From 2c3fba90e1b90465c162663bdb549424aa0541ec Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Thu, 13 Sep 2018 19:31:10 +0800 Subject: [PATCH 1/3] editor: fgmap bgmap data-support --- _server/editor.js | 54 +++++++++++++++++++++++++++--------------- _server/editor_file.js | 12 +++++++--- editor-mobile.html | 3 ++- editor.html | 3 ++- libs/maps.js | 1 + 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/_server/editor.js b/_server/editor.js index 9c9603cc..0fb176e8 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -12,14 +12,7 @@ editor.prototype.init = function (callback) { editor.reset(function () { editor.drawMapBg(); - var mapArray = core.maps.save(core.status.maps, core.status.floorId); - 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.fetchMapFromCore(); editor.updateMap(); editor.buildMark(); editor.drawEventBlock(); @@ -170,7 +163,11 @@ editor.prototype.mapInit = function () { 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.fgmap = editor.fgmap; + editor.currentFloorData.bgmap = editor.bgmap; editor.currentFloorData.firstArrive = []; editor.currentFloorData.events = {}; editor.currentFloorData.changeFloor = {}; @@ -326,26 +323,45 @@ editor.prototype.buildMark = function(){ } } -editor.prototype.changeFloor = function (floorId, callback) { - editor.currentFloorData.map = editor.map.map(function (v) { +editor.prototype.fetchMapFromCore = function(){ + var mapArray = core.maps.save(core.status.maps, core.status.floorId); + editor.map = mapArray.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.bigmap.offsetX=0; core.bigmap.offsetY=0; editor.moveViewport(0,0); editor.drawMapBg(); - var mapArray = core.maps.save(core.status.maps, core.status.floorId); - 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.fetchMapFromCore(); editor.updateMap(); editor_mode.floor(); editor.drawEventBlock(); diff --git a/_server/editor_file.js b/_server/editor_file.js index 4f534d2a..e4c46b1c 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -106,8 +106,8 @@ editor_file = function (editor, callback) { }); for (var ii in editor.currentFloorData) if (editor.currentFloorData.hasOwnProperty(ii)) { - if (ii == 'map') - datastr = datastr.concat(['\n"', ii, '": [\n', formatMap(editor.currentFloorData[ii]), '\n],']); + if (['map','bgmap','fgmap'].indexOf(ii)!==-1) + datastr = datastr.concat(['\n"', ii, '": [\n', formatMap(editor.currentFloorData[ii],ii!='map'), '\n],']); else datastr = datastr.concat(['\n"', ii, '": ', JSON.stringify(editor.currentFloorData[ii], null, 4), ',']); } @@ -704,7 +704,13 @@ editor_file = function (editor, callback) { 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 arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],['); diff --git a/editor-mobile.html b/editor-mobile.html index ad395cc3..641e5763 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -211,6 +211,7 @@ + @@ -406,7 +407,7 @@ - + diff --git a/editor.html b/editor.html index 446aaaaf..28ddbce2 100644 --- a/editor.html +++ b/editor.html @@ -210,6 +210,7 @@ + @@ -391,7 +392,7 @@ - + diff --git a/libs/maps.js b/libs/maps.js index 4ec056a9..89ae1ff1 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -433,6 +433,7 @@ maps.prototype.drawMap = function (mapName, callback) { if (main.mode=='editor'){ main.editor.drawMapBg = function(){ core.clearMap('bg'); + core.clearMap('fg'); drawBg(); } } else { From f0d5c04db51f6537b74a40194e64ddd63ee60323 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Sat, 15 Sep 2018 23:54:39 +0800 Subject: [PATCH 2/3] editor: fgmap bgmap draw-support --- _server/editor.js | 33 +++++++++++++++++++++++++++++---- _server/editor_file.js | 16 ++++++++++------ _server/vm.js | 2 +- editor-mobile.html | 19 ++++++++++++------- editor.html | 6 ++++++ libs/maps.js | 2 ++ 6 files changed, 60 insertions(+), 18 deletions(-) diff --git a/_server/editor.js b/_server/editor.js index 0fb176e8..56b3f292 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -2,6 +2,7 @@ function editor() { this.version = "2.0"; this.material = {}; this.brushMod = "line";//["line","rectangle"] + this.layerMod = "map";//["fgmap","map","bgmap"] } editor.prototype.init = function (callback) { @@ -177,6 +178,7 @@ editor.prototype.mapInit = function () { editor.currentFloorData.cannotMove = {}; } editor.prototype.drawMapBg = function (img) { + return var bgc = bg.getContext('2d'); if (!core.isset(editor.bgY) || editor.bgY == 0) { editor.main.editor.drawMapBg(); @@ -253,6 +255,8 @@ editor.prototype.updateMap = function () { } // 绘制地图 start var eventCtx = document.getElementById('event').getContext("2d"); + var fgCtx = document.getElementById('fg').getContext("2d"); + var bgCtx = document.getElementById('bg').getContext("2d"); for (var y = 0; y < editor.map.length; y++) for (var x = 0; x < editor.map[0].length; x++) { var tileInfo = editor.map[y][x]; @@ -260,6 +264,10 @@ editor.prototype.updateMap = function () { addIndexToAutotileInfo(x, y); drawAutotile(eventCtx, x, y, tileInfo); } else drawTile(eventCtx, x, y, tileInfo); + tileInfo = editor.fgmap[y][x]; + drawTile(fgCtx, x, y, tileInfo); + tileInfo = editor.bgmap[y][x]; + drawTile(bgCtx, x, y, tileInfo); } // 绘制地图 end @@ -502,7 +510,7 @@ editor.prototype.listen = function () { holdingPath = 0; e.stopPropagation(); if (stepPostfix && stepPostfix.length) { - preMapData = JSON.parse(JSON.stringify(editor.map)); + preMapData = JSON.parse(JSON.stringify({map:editor.map,fgmap:editor.fgmap,bgmap:editor.bgmap})); if(editor.brushMod==='rectangle'){ var x0=stepPostfix[0].x; var y0=stepPostfix[0].y; @@ -522,7 +530,7 @@ editor.prototype.listen = function () { reDo = null; // console.log(stepPostfix); for (var ii = 0; ii < stepPostfix.length; ii++) - editor.map[stepPostfix[ii].y][stepPostfix[ii].x] = editor.info; + editor[editor.layerMod][stepPostfix[ii].y][stepPostfix[ii].x] = editor.info; // console.log(editor.map); editor.updateMap(); holdingPath = 0; @@ -590,7 +598,9 @@ editor.prototype.listen = function () { e.preventDefault(); //Ctrl+z 撤销上一步undo if (e.keyCode == 90 && e.ctrlKey && preMapData && currDrawData.pos.length && selectBox.isSelected) { - editor.map = JSON.parse(JSON.stringify(preMapData)); + editor.map = JSON.parse(JSON.stringify(preMapData.map)); + editor.fgmap = JSON.parse(JSON.stringify(preMapData.fgmap)); + editor.bgmap = JSON.parse(JSON.stringify(preMapData.bgmap)); editor.updateMap(); reDo = JSON.parse(JSON.stringify(currDrawData)); currDrawData = {pos: [], info: {}}; @@ -598,7 +608,7 @@ editor.prototype.listen = function () { } //Ctrl+y 重做一步redo if (e.keyCode == 89 && e.ctrlKey && reDo && reDo.pos.length && selectBox.isSelected) { - preMapData = JSON.parse(JSON.stringify(editor.map)); + preMapData = JSON.parse(JSON.stringify({map:editor.map,fgmap:editor.fgmap,bgmap:editor.bgmap})); for (var j = 0; j < reDo.pos.length; j++) editor.map[reDo.pos[j].y][reDo.pos[j].x] = JSON.parse(JSON.stringify(reDo.info)); @@ -881,6 +891,21 @@ editor.prototype.listen = function () { editor.brushMod=brushMod2.value; } + var layerMod=document.getElementById('layerMod'); + layerMod.onchange=function(){ + editor.layerMod=layerMod.value; + } + + var layerMod2=document.getElementById('layerMod2'); + if(layerMod2)layerMod2.onchange=function(){ + editor.layerMod=layerMod2.value; + } + + var layerMod3=document.getElementById('layerMod3'); + if(layerMod3)layerMod3.onchange=function(){ + editor.layerMod=layerMod3.value; + } + editor.moveViewport=function(x,y){ core.bigmap.offsetX = core.clamp(core.bigmap.offsetX+32*x, 0, 32*core.bigmap.width-416); diff --git a/_server/editor_file.js b/_server/editor_file.js index e4c46b1c..8e340f4b 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -98,12 +98,16 @@ editor_file = function (editor, callback) { editor.currentFloorData.map = []; for (var i=0;i脚本编辑 - -
- - - - + +
+ + + +
- + + + 图层: + 前景 + 事件 + 背景 +
diff --git a/libs/maps.js b/libs/maps.js index 89ae1ff1..da8c8fc7 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -351,11 +351,13 @@ maps.prototype.drawBgFgMap = function (floorId, canvas, name) { var getMapArray = function (name) { var arr = core.clone(core.floors[floorId][name+"map"] || []); + if(main.mode=='editor')arr = core.clone(editor[name+"map"])||arr; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { arr[y] = arr[y] || []; if (core.hasFlag(name + "_" + floorId + "_" + x + "_" + y)) arr[y][x] = 0; else arr[y][x] = core.getFlag(name + "v_" + floorId + "_" + x + "_" + y, arr[y][x] || 0); + if(main.mode=='editor')arr[y][x]= arr[y][x].idnum || arr[y][x] || 0; } } return arr; From d1fdc2825ddd7dbc55d4526eb67016fdedbbb04a Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Sun, 16 Sep 2018 00:08:29 +0800 Subject: [PATCH 3/3] editor: ban 48*32 blocks in fgmap/bgmap --- _server/editor.js | 14 ++++++++++---- libs/maps.js | 13 ++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/_server/editor.js b/_server/editor.js index 56b3f292..07741e42 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -178,13 +178,15 @@ editor.prototype.mapInit = function () { editor.currentFloorData.cannotMove = {}; } editor.prototype.drawMapBg = function (img) { - return - var bgc = bg.getContext('2d'); + return; + + //legacy if (!core.isset(editor.bgY) || editor.bgY == 0) { editor.main.editor.drawMapBg(); return; } + var bgc = bg.getContext('2d'); for (var ii = 0; ii < 13; ii++) for (var jj = 0; jj < 13; jj++) { bgc.clearRect(ii * 32, jj * 32, 32, 32); @@ -529,8 +531,12 @@ editor.prototype.listen = function () { currDrawData.info = JSON.parse(JSON.stringify(editor.info)); reDo = null; // console.log(stepPostfix); - for (var ii = 0; ii < stepPostfix.length; ii++) - editor[editor.layerMod][stepPostfix[ii].y][stepPostfix[ii].x] = editor.info; + if (editor.layerMod!='map' && editor.info.images && editor.info.images.indexOf('48')!==-1){ + printe('前景/背景不支持48的图块'); + } else { + for (var ii = 0; ii < stepPostfix.length; ii++) + editor[editor.layerMod][stepPostfix[ii].y][stepPostfix[ii].x] = editor.info; + } // console.log(editor.map); editor.updateMap(); holdingPath = 0; diff --git a/libs/maps.js b/libs/maps.js index da8c8fc7..6ad50ff5 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -433,11 +433,14 @@ maps.prototype.drawMap = function (mapName, callback) { } if (main.mode=='editor'){ - main.editor.drawMapBg = function(){ - core.clearMap('bg'); - core.clearMap('fg'); - drawBg(); - } + // just do not run drawBg + + // //---move to main.editor.updateMap + // main.editor.drawMapBg = function(){ + // core.clearMap('bg'); + // core.clearMap('fg'); + // drawBg(); + // } } else { drawBg(); }