editor: fgmap bgmap data-support

This commit is contained in:
YouWei Zhao 2018-09-13 19:31:10 +08:00
parent 095aedf1e1
commit 2c3fba90e1
5 changed files with 49 additions and 24 deletions

View File

@ -12,14 +12,7 @@ editor.prototype.init = function (callback) {
editor.reset(function () { editor.reset(function () {
editor.drawMapBg(); editor.drawMapBg();
var mapArray = core.maps.save(core.status.maps, core.status.floorId); editor.fetchMapFromCore();
editor.map = mapArray.map(function (v) {
return v.map(function (v) {
return editor.ids[[editor.indexs[parseInt(v)][0]]]
})
});
editor.currentFloorId = core.status.floorId;
editor.currentFloorData = core.floors[core.status.floorId];
editor.updateMap(); editor.updateMap();
editor.buildMark(); editor.buildMark();
editor.drawEventBlock(); editor.drawEventBlock();
@ -170,7 +163,11 @@ editor.prototype.mapInit = function () {
editor.map[y][x] = 0; editor.map[y][x] = 0;
} }
} }
editor.fgmap=JSON.parse(JSON.stringify(editor.map));
editor.bgmap=JSON.parse(JSON.stringify(editor.map));
editor.currentFloorData.map = editor.map; editor.currentFloorData.map = editor.map;
editor.currentFloorData.fgmap = editor.fgmap;
editor.currentFloorData.bgmap = editor.bgmap;
editor.currentFloorData.firstArrive = []; editor.currentFloorData.firstArrive = [];
editor.currentFloorData.events = {}; editor.currentFloorData.events = {};
editor.currentFloorData.changeFloor = {}; editor.currentFloorData.changeFloor = {};
@ -326,26 +323,45 @@ editor.prototype.buildMark = function(){
} }
} }
editor.prototype.changeFloor = function (floorId, callback) { editor.prototype.fetchMapFromCore = function(){
editor.currentFloorData.map = editor.map.map(function (v) { var mapArray = core.maps.save(core.status.maps, core.status.floorId);
editor.map = mapArray.map(function (v) {
return v.map(function (v) { return v.map(function (v) {
return v.idnum || v || 0 return editor.ids[[editor.indexs[parseInt(v)][0]]]
}) })
}); });
editor.currentFloorId = core.status.floorId;
editor.currentFloorData = core.floors[core.status.floorId];
for(var ii=0,name;name=['bgmap','fgmap'][ii];ii++){
var mapArray = editor.currentFloorData[name];
if(!mapArray || JSON.stringify(mapArray)==JSON.stringify([])){//未设置或空数组
//与editor.map同形的全0
mapArray=eval('['+Array(editor.map.length+1).join('['+Array(editor.map[0].length+1).join('0,')+'],')+']');
}
editor[name]=mapArray.map(function (v) {
return v.map(function (v) {
return editor.ids[[editor.indexs[parseInt(v)][0]]]
})
});
}
}
editor.prototype.changeFloor = function (floorId, callback) {
for(var ii=0,name;name=['map','bgmap','fgmap'][ii];ii++){
var mapArray=editor[name].map(function (v) {
return v.map(function (v) {
return v.idnum || v || 0
})
});
editor.currentFloorData[name]=mapArray;
}
core.changeFloor(floorId, null, {"x": 0, "y": 0, "direction": "up"}, null, function () { core.changeFloor(floorId, null, {"x": 0, "y": 0, "direction": "up"}, null, function () {
core.bigmap.offsetX=0; core.bigmap.offsetX=0;
core.bigmap.offsetY=0; core.bigmap.offsetY=0;
editor.moveViewport(0,0); editor.moveViewport(0,0);
editor.drawMapBg(); editor.drawMapBg();
var mapArray = core.maps.save(core.status.maps, core.status.floorId); editor.fetchMapFromCore();
editor.map = mapArray.map(function (v) {
return v.map(function (v) {
return editor.ids[[editor.indexs[parseInt(v)][0]]]
})
});
editor.currentFloorId = core.status.floorId;
editor.currentFloorData = core.floors[core.status.floorId];
editor.updateMap(); editor.updateMap();
editor_mode.floor(); editor_mode.floor();
editor.drawEventBlock(); editor.drawEventBlock();

View File

@ -106,8 +106,8 @@ editor_file = function (editor, callback) {
}); });
for (var ii in editor.currentFloorData) for (var ii in editor.currentFloorData)
if (editor.currentFloorData.hasOwnProperty(ii)) { if (editor.currentFloorData.hasOwnProperty(ii)) {
if (ii == 'map') if (['map','bgmap','fgmap'].indexOf(ii)!==-1)
datastr = datastr.concat(['\n"', ii, '": [\n', formatMap(editor.currentFloorData[ii]), '\n],']); datastr = datastr.concat(['\n"', ii, '": [\n', formatMap(editor.currentFloorData[ii],ii!='map'), '\n],']);
else else
datastr = datastr.concat(['\n"', ii, '": ', JSON.stringify(editor.currentFloorData[ii], null, 4), ',']); datastr = datastr.concat(['\n"', ii, '": ', JSON.stringify(editor.currentFloorData[ii], null, 4), ',']);
} }
@ -704,7 +704,13 @@ editor_file = function (editor, callback) {
return true return true
} }
var formatMap = function (mapArr) { var formatMap = function (mapArr,trySimplify) {
if(!mapArr || JSON.stringify(mapArr)==JSON.stringify([]))return '';
if(trySimplify){
//检查是否是全0二维数组
var jsoncheck=JSON.stringify(mapArr).replace(/\D/g,'');
if(jsoncheck==Array(jsoncheck.length+1).join('0'))return '';
}
//把二维数组格式化 //把二维数组格式化
var formatArrStr = ''; var formatArrStr = '';
var arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],['); var arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],[');

View File

@ -211,6 +211,7 @@
<canvas class='gameCanvas' id='bg' width='416' height='416'></canvas> <canvas class='gameCanvas' id='bg' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='event' width='416' height='416'></canvas> <canvas class='gameCanvas' id='event' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='event2' width='416' height='416'></canvas> <canvas class='gameCanvas' id='event2' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='fg' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='efg' width='416' height='416'></canvas> <canvas class='gameCanvas' id='efg' width='416' height='416'></canvas>
<canvas class='egameCanvas' id='eui' width='416' height='416' style='z-index:100'></canvas> <canvas class='egameCanvas' id='eui' width='416' height='416' style='z-index:100'></canvas>
</div> </div>
@ -406,7 +407,7 @@
<!-- <canvas class='gameCanvas' id='event' width='416' height='416'></canvas> --> <!-- <canvas class='gameCanvas' id='event' width='416' height='416'></canvas> -->
<canvas class='gameCanvas' id='hero' width='416' height='416'></canvas> <canvas class='gameCanvas' id='hero' width='416' height='416'></canvas>
<!-- <canvas class='gameCanvas' id='event2' width='416' height='416'></canvas> --> <!-- <canvas class='gameCanvas' id='event2' width='416' height='416'></canvas> -->
<canvas class='gameCanvas' id='fg' width='416' height='416'></canvas> <!-- <canvas class='gameCanvas' id='fg' width='416' height='416'></canvas> -->
<canvas class='gameCanvas' id='damage' width='416' height='416'></canvas> <canvas class='gameCanvas' id='damage' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='animate' width='416' height='416'></canvas> <canvas class='gameCanvas' id='animate' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='weather' width='416' height='416'></canvas> <canvas class='gameCanvas' id='weather' width='416' height='416'></canvas>

View File

@ -210,6 +210,7 @@
<canvas class='gameCanvas' id='bg' width='416' height='416'></canvas> <canvas class='gameCanvas' id='bg' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='event' width='416' height='416'></canvas> <canvas class='gameCanvas' id='event' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='event2' width='416' height='416'></canvas> <canvas class='gameCanvas' id='event2' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='fg' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='efg' width='416' height='416'></canvas> <canvas class='gameCanvas' id='efg' width='416' height='416'></canvas>
<canvas class='egameCanvas' id='eui' width='416' height='416' style='z-index:100'></canvas> <canvas class='egameCanvas' id='eui' width='416' height='416' style='z-index:100'></canvas>
</div> </div>
@ -391,7 +392,7 @@
<!-- <canvas class='gameCanvas' id='event' width='416' height='416'></canvas> --> <!-- <canvas class='gameCanvas' id='event' width='416' height='416'></canvas> -->
<canvas class='gameCanvas' id='hero' width='416' height='416'></canvas> <canvas class='gameCanvas' id='hero' width='416' height='416'></canvas>
<!-- <canvas class='gameCanvas' id='event2' width='416' height='416'></canvas> --> <!-- <canvas class='gameCanvas' id='event2' width='416' height='416'></canvas> -->
<canvas class='gameCanvas' id='fg' width='416' height='416'></canvas> <!-- <canvas class='gameCanvas' id='fg' width='416' height='416'></canvas> -->
<canvas class='gameCanvas' id='damage' width='416' height='416'></canvas> <canvas class='gameCanvas' id='damage' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='animate' width='416' height='416'></canvas> <canvas class='gameCanvas' id='animate' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='weather' width='416' height='416'></canvas> <canvas class='gameCanvas' id='weather' width='416' height='416'></canvas>

View File

@ -433,6 +433,7 @@ maps.prototype.drawMap = function (mapName, callback) {
if (main.mode=='editor'){ if (main.mode=='editor'){
main.editor.drawMapBg = function(){ main.editor.drawMapBg = function(){
core.clearMap('bg'); core.clearMap('bg');
core.clearMap('fg');
drawBg(); drawBg();
} }
} else { } else {