From 20bedabd05cb8800ce5e8187daced8e8794889cc Mon Sep 17 00:00:00 2001 From: oc Date: Tue, 1 Jan 2019 23:14:12 +0800 Subject: [PATCH] create multiple floors --- _server/css/editor.css | 27 +++++++++++-- _server/css/editor_mobile.css | 30 ++++++++++++++ _server/editor_file.js | 76 +++++++++++++++++++++++++++++++++++ _server/editor_mode.js | 65 ++++++++++++++++++++++++++++++ editor-mobile.html | 42 +++++++++++++------ editor.html | 31 ++++++++++---- project/floors/sample0.js | 2 +- 7 files changed, 248 insertions(+), 25 deletions(-) diff --git a/_server/css/editor.css b/_server/css/editor.css index f64b6b69..77c0b298 100644 --- a/_server/css/editor.css +++ b/_server/css/editor.css @@ -58,7 +58,7 @@ body { #editArea { position: absolute; width: 100%; - height: 70%; + height: 400px; left: 0; top: 0; /* padding: 10px 5px; */ @@ -68,7 +68,7 @@ body { #pout { display: block; width: 410px; - height: 100%; + height: 380px; box-sizing: border-box; margin-left: 22px; margin-top: 23px; @@ -84,9 +84,28 @@ body { #editTip { position: absolute; width: 100%; - margin-bottom: 120px; - bottom: 0; left: 10px; + top: 430px; +} + +#editBtns { + position: absolute; + width: 100%; + left: 10px; + top: 465px; +} + +#newMaps { + position: absolute; + left: 10px; + top: 505px; +} + +#newFloors { + position: absolute; + width: 100%; + left: 10px; + top: 530px; } #editArea p { diff --git a/_server/css/editor_mobile.css b/_server/css/editor_mobile.css index 6d024248..8da52de2 100644 --- a/_server/css/editor_mobile.css +++ b/_server/css/editor_mobile.css @@ -45,6 +45,7 @@ body { top: 0; /* padding: 10px 5px; */ box-sizing: border-box; + display: none; } #pout { @@ -72,12 +73,39 @@ body { font-size: 14px; } +#editTip { + position: absolute; + width: 95vw; + left: 4vw; + top: 4vw; +} + #editTip .btn { float: right; margin-right: 20px; margin-top: 5px; } +#editBtns { + position: absolute; + width: 95vw; + left: 4vw; + top: 20vw; +} + +#newMaps { + position: absolute; + left: 4vw; + top: 35vw; +} + +#newFloors { + position: absolute; + width: 95vw; + left: 4vw; + top: 43vw; +} + #mid { position: absolute; } @@ -279,6 +307,7 @@ div.col .coltd { width: 95vw; height: 16px; font-size: 13px; + display: none; } #mapColMark { @@ -334,6 +363,7 @@ div.row .rowtd .rowtext{ width: 4vw; height: 62vw; font-size: 12px; + display: none; } #mapRowMark { diff --git a/_server/editor_file.js b/_server/editor_file.js index 3d2b80ca..0304d2f1 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -174,6 +174,82 @@ editor_file = function (editor, callback) { editor.currentFloorId = saveFilename; editor_file.saveFloorFile(callback); } + editor_file.saveNewFiles = function (floorIdList, from, to, callback) { + if (!isset(callback)) { + printe('未设置callback'); + throw('未设置callback') + }; + var currData=editor.currentFloorData; + var saveStatus = document.getElementById('newMapsStatus').checked; + + var calValue = function (text, i) { + return text.replace(/\${(.*?)}/g, function (word, value) { + return eval(value); + }); + } + + var width = parseInt(document.getElementById('newMapsWidth').value); + var height = parseInt(document.getElementById('newMapsHeight').value); + + var row = [], map = []; + for (var i=0;ito || from<0 || to<0) { + printe("请输入有效的起始和终止楼层"); + return; + } + if (to-from >= 100) { + printe("一次最多创建99个楼层"); + return; + } + var floorIdList = []; + for (var i = from; i<=to; i++) { + var floorId = floorIds.replace(/\${(.*?)}/g, function (word, value) { + return eval(value); + }); + if (core.floorIds.indexOf(floorId)>=0) { + printe("要创建的楼层 "+floorId+" 已存在!"); + return; + } + if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(floorId)) { + printe("楼层名 "+floorId+" 不合法!请使用字母、数字、下划线,且不能以数字开头!"); + return; + } + if (floorIdList.indexOf(floorId)>=0) { + printe("尝试重复创建楼层 "+floorId+" !"); + return; + } + floorIdList.push(floorId); + } + + var width = parseInt(document.getElementById('newMapsWidth').value); + var height = parseInt(document.getElementById('newMapsHeight').value); + if (!core.isset(width) || !core.isset(height) || width<13 || height<13 || width*height>1000) { + printe("新建地图的宽高都不得小于13,且宽高之积不能超过1000"); + return; + } + editor_mode.onmode(''); + + editor.file.saveNewFiles(floorIdList, from, to, function (err) { + if (err) { + printe(err); + throw(err) + } + core.floorIds = core.floorIds.concat(floorIdList); + editor.file.editTower([['change', "['main']['floorIds']", core.floorIds]], function (objs_) {//console.log(objs_); + if (objs_.slice(-1)[0] != null) { + printe(objs_.slice(-1)[0]); + throw(objs_.slice(-1)[0]) + } + ;printe('批量创建 '+floorIdList[0]+'~'+floorIdList[floorIdList.length-1]+' 成功,请F5刷新编辑器生效'); + }); + }); + } + var ratio = 1; var appendPicCanvas = document.getElementById('appendPicCanvas'); var bg = appendPicCanvas.children[0]; diff --git a/editor-mobile.html b/editor-mobile.html index ad6e5b64..7dbf1883 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -22,30 +22,48 @@ -
- - +
+ - 保留属性 + 保留楼层属性 +
+
-
+
+ +
-
- -
-
- -
-

追加素材

diff --git a/editor.html b/editor.html index 352e951a..0c79d30c 100644 --- a/editor.html +++ b/editor.html @@ -31,20 +31,35 @@ 保留楼层属性
-
+
+ +
-
- -
-
- -
-

追加素材

diff --git a/project/floors/sample0.js b/project/floors/sample0.js index c08187bb..8ed705e3 100644 --- a/project/floors/sample0.js +++ b/project/floors/sample0.js @@ -8,7 +8,7 @@ main.floors.sample0= "defaultGround": "ground", "images": [], "bgm": "bgm.mp3", -"item_ratio": 2, +"item_ratio": 1, "map": [ [ 0, 0,220, 0, 0, 20, 87, 3, 65, 64, 44, 43, 42], [ 0,246, 0,246, 0, 20, 0, 3, 58, 59, 60, 61, 41],