From 4fa318a6b4dc350aa8bec2e65ebff2e59bb7d168 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 19 Mar 2019 22:19:41 -0400 Subject: [PATCH 1/5] step1:buttons --- _server/vm.js | 189 ++++++++++++++++++++------------------------- editor-mobile.html | 8 +- editor.html | 8 +- 3 files changed, 91 insertions(+), 114 deletions(-) diff --git a/_server/vm.js b/_server/vm.js index 6707dea0..8fe05935 100644 --- a/_server/vm.js +++ b/_server/vm.js @@ -1,46 +1,39 @@ -// vue 相关处理 -var exportMap = new Vue({ - el: '#exportMap', - data: { - isExport: false, - }, - methods: { - exportMap: function () { - editor.updateMap(); - var sx=editor.map.length-1,sy=editor.map[0].length-1; +var exportMap = document.getElementById('exportMap') +exportMap.isExport=false +exportMap.onclick=function(){ + editor.updateMap(); + var sx=editor.map.length-1,sy=editor.map[0].length-1; - var filestr = ''; - for (var yy = 0; yy <= sy; yy++) { - filestr += '[' - for (var xx = 0; xx <= sx; xx++) { - var mapxy = editor.map[yy][xx]; - if (typeof(mapxy) == typeof({})) { - if ('idnum' in mapxy) mapxy = mapxy.idnum; - else { - // mapxy='!!?'; - tip.whichShow = 3; - return; - } - } else if (typeof(mapxy) == 'undefined') { - tip.whichShow = 3; - return; - } - mapxy = String(mapxy); - mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy; - filestr += mapxy + (xx == sx ? '' : ',') + var filestr = ''; + for (var yy = 0; yy <= sy; yy++) { + filestr += '[' + for (var xx = 0; xx <= sx; xx++) { + var mapxy = editor.map[yy][xx]; + if (typeof(mapxy) == typeof({})) { + if ('idnum' in mapxy) mapxy = mapxy.idnum; + else { + // mapxy='!!?'; + tip.whichShow = 3; + return; } - - filestr += ']' + (yy == sy ? '' : ',\n'); + } else if (typeof(mapxy) == 'undefined') { + tip.whichShow = 3; + return; } - pout.value = filestr; - editArea.mapArr = filestr; - this.isExport = true; - editArea.error = 0; - tip.whichShow = 2; + mapxy = String(mapxy); + mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy; + filestr += mapxy + (xx == sx ? '' : ',') } + + filestr += ']' + (yy == sy ? '' : ',\n'); } -}) + pout.value = filestr; + editArea.mapArr = filestr; + exportMap.isExport = true; + editArea.error = 0; + tip.whichShow = 2; +} var editArea = new Vue({ el: '#editArea', data: { @@ -133,80 +126,64 @@ var editArea = new Vue({ } } }); -var copyMap = new Vue({ - el: '#copyMap', - data: { - err: '' - }, - methods: { - copyMap: function () { - - tip.whichShow = 0; - if (pout.value.trim() != '') { - if (editArea.error) { - this.err = editArea.errors[editArea.error - 1]; - tip.whichShow = 5 - return; - } - try { - pout.focus(); - pout.setSelectionRange(0, pout.value.length); - document.execCommand("Copy"); - tip.whichShow = 6; - } catch (e) { - this.err = e; - tip.whichShow = 5; - } - } else { - tip.whichShow = 7; - } +var copyMap=document.getElementById('copyMap') +copyMap.err='' +copyMap.onclick=function(){ + tip.whichShow = 0; + if (pout.value.trim() != '') { + if (editArea.error) { + copyMap.err = editArea.errors[editArea.error - 1]; + tip.whichShow = 5 + return; } - }, -}) -var clearMap = new Vue({ - el: '#clearMap', - - methods: { - clearMap: function () { - editor.mapInit(); - editor_mode.onmode(''); - editor.file.saveFloorFile(function (err) { - if (err) { - printe(err); - throw(err) - } - ;printf('地图清除成功'); - }); - editor.updateMap(); - clearTimeout(editArea.formatTimer); - clearTimeout(tip.timer); - pout.value = ''; - editArea.mapArr = ''; - tip.whichShow = 4; - editArea.error = 0; + try { + pout.focus(); + pout.setSelectionRange(0, pout.value.length); + document.execCommand("Copy"); + tip.whichShow = 6; + } catch (e) { + copyMap.err = e; + tip.whichShow = 5; } + } else { + tip.whichShow = 7; } -}) -var deleteMap = new Vue({ - el: '#deleteMap', - methods: { - deleteMap: function () { - editor_mode.onmode(''); - var index = core.floorIds.indexOf(editor.currentFloorId); - if (index>=0) { - core.floorIds.splice(index,1); - 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('删除成功,请F5刷新编辑器生效'); - }); - } - else printe('删除成功,请F5刷新编辑器生效'); +} +var clearMapButton=document.getElementById('clearMapButton') +clearMapButton.onclick=function () { + editor.mapInit(); + editor_mode.onmode(''); + editor.file.saveFloorFile(function (err) { + if (err) { + printe(err); + throw(err) } + ;printf('地图清除成功'); + }); + editor.updateMap(); + clearTimeout(editArea.formatTimer); + clearTimeout(tip.timer); + pout.value = ''; + editArea.mapArr = ''; + tip.whichShow = 4; + editArea.error = 0; +} +var deleteMap=document.getElementById('deleteMap') +deleteMap.onclick=function () { + editor_mode.onmode(''); + var index = core.floorIds.indexOf(editor.currentFloorId); + if (index>=0) { + core.floorIds.splice(index,1); + 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('删除成功,请F5刷新编辑器生效'); + }); } -}) + else printe('删除成功,请F5刷新编辑器生效'); +} printf = function (str_, type) { selectBox.isSelected = false; if (!type) { diff --git a/editor-mobile.html b/editor-mobile.html index 4a14c201..e90fe59a 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -34,10 +34,10 @@
- - - - + + + +
- - - - + + + +
diff --git a/editor.html b/editor.html index cc870582..0fe2bc80 100644 --- a/editor.html +++ b/editor.html @@ -325,7 +325,7 @@
-
+
From a1e144f2da72a4f342d9ba57ae8f81d0826c4c9d Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 19 Mar 2019 22:36:13 -0400 Subject: [PATCH 3/5] editArea-1 --- _server/css/editor.css | 4 +-- _server/css/editor_mobile.css | 4 +-- _server/vm.js | 54 ++++++++++++++++------------------- editor-mobile.html | 6 ++-- editor.html | 6 ++-- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/_server/css/editor.css b/_server/css/editor.css index b37149bb..dd9c0e18 100644 --- a/_server/css/editor.css +++ b/_server/css/editor.css @@ -54,7 +54,7 @@ body { height: 630px; } -#editArea { +#mapEditArea { position: absolute; width: 100%; height: 400px; @@ -107,7 +107,7 @@ body { top: 530px; } -#editArea p { +#mapEditArea p { margin: 10px; display: block; width: 70%; diff --git a/_server/css/editor_mobile.css b/_server/css/editor_mobile.css index 7bdf8953..1120c9fd 100644 --- a/_server/css/editor_mobile.css +++ b/_server/css/editor_mobile.css @@ -37,7 +37,7 @@ body { position: absolute; } -#editArea { +#mapEditArea { position: absolute; width: 100%; height: 70%; @@ -64,7 +64,7 @@ body { overflow: auto; } -#editArea p { +#mapEditArea p { margin: 10px; display: block; width: 70%; diff --git a/_server/vm.js b/_server/vm.js index 5e4fbe21..1b40bf3a 100644 --- a/_server/vm.js +++ b/_server/vm.js @@ -29,13 +29,13 @@ exportMap.onclick=function(){ filestr += ']' + (yy == sy ? '' : ',\n'); } pout.value = filestr; - editArea.mapArr = filestr; + mapEditArea.mapArr = filestr; exportMap.isExport = true; - editArea.error = 0; + mapEditArea.error = 0; tip.whichShow = 2; } -var editArea = new Vue({ - el: '#editArea', +var mapEditArea = new Vue({ + el: '#mapEditArea', data: { mapArr: '', errors: [ // 编号1,2,3,4 @@ -49,39 +49,36 @@ var editArea = new Vue({ }, watch: { mapArr: function (val, oldval) { - var that = this; if (val == '') return; if (exportMap.isExport) { exportMap.isExport = false; return; } - if (that.formatArr()) { - that.error = 0; + if (mapEditArea.formatArr()) { + mapEditArea.error = 0; setTimeout(function () { - that.mapArr = that.formatArr(); - that.drawMap(); + mapEditArea.mapArr = mapEditArea.formatArr(); + mapEditArea.drawMap(); tip.whichShow = 8 }, 1000); - that.formatTimer = setTimeout(function () { - pout.value = that.formatArr(); + mapEditArea.formatTimer = setTimeout(function () { + pout.value = mapEditArea.formatArr(); }, 5000); //5s后再格式化,不然光标跳到最后很烦 } else { - that.error = 1; + mapEditArea.error = 1; } }, error: function () { - // console.log(editArea.mapArr); - if (this.error>0) - printe(this.errors[this.error-1]) + // console.log(mapEditArea.mapArr); + if (mapEditArea.error>0) + printe(mapEditArea.errors[mapEditArea.error-1]) } }, methods: { drawMap: function () { - var that = this; - - // var mapArray = that.mapArr.split(/\D+/).join(' ').trim().split(' '); - var mapArray = JSON.parse('[' + that.mapArr + ']'); + // var mapArray = mapEditArea.mapArr.split(/\D+/).join(' ').trim().split(' '); + var mapArray = JSON.parse('[' + mapEditArea.mapArr + ']'); var sy=editor.map.length,sx=editor.map[0].length; for (var y = 0; y < sy; y++) for (var x = 0; x < sx; x++) { @@ -89,7 +86,7 @@ var editArea = new Vue({ if (num == 0) editor.map[y][x] = 0; else if (typeof(editor.indexs[num][0]) == 'undefined') { - that.error = 2; + mapEditArea.error = 2; editor.map[y][x] = undefined; } else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]]; } @@ -99,11 +96,10 @@ var editArea = new Vue({ }, formatArr: function () { var formatArrStr = ''; - var that = this; - clearTimeout(that.formatTimer); + clearTimeout(mapEditArea.formatTimer); var si=editor.map.length,sk=editor.map[0].length; - if (this.mapArr.split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false; - var arr = this.mapArr.replace(/\s+/g, '').split('],['); + if (mapEditArea.mapArr.split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false; + var arr = mapEditArea.mapArr.replace(/\s+/g, '').split('],['); if (arr.length != si) return; for (var i = 0; i < si; i++) { @@ -131,8 +127,8 @@ copyMap.err='' copyMap.onclick=function(){ tip.whichShow = 0; if (pout.value.trim() != '') { - if (editArea.error) { - copyMap.err = editArea.errors[editArea.error - 1]; + if (mapEditArea.error) { + copyMap.err = mapEditArea.errors[mapEditArea.error - 1]; tip.whichShow = 5 return; } @@ -161,12 +157,12 @@ clearMapButton.onclick=function () { ;printf('地图清除成功'); }); editor.updateMap(); - clearTimeout(editArea.formatTimer); + clearTimeout(mapEditArea.formatTimer); clearTimeout(tip.timer); pout.value = ''; - editArea.mapArr = ''; + mapEditArea.mapArr = ''; tip.whichShow = 4; - editArea.error = 0; + mapEditArea.error = 0; } var deleteMap=document.getElementById('deleteMap') deleteMap.onclick=function () { diff --git a/editor-mobile.html b/editor-mobile.html index 66d38e6f..34d7c12d 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -18,7 +18,7 @@
-
+
@@ -522,8 +522,8 @@ if (location.protocol.indexOf("http")!=0) {