From 46d4d77bde27463188ce2fd22e978c101772ac6d Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Sat, 10 Mar 2018 19:36:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug=20=E4=BB=A5=E5=8F=8A=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E8=BF=BD=E5=8A=A0=E7=B4=A0=E6=9D=90=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/README.md | 64 ++++++++++++++++++++++++++++++++----- _server/css/editor_mode.css | 6 ++++ _server/editor_file.js | 48 ++++++++++++++-------------- _server/editor_mode.js | 1 - _server/editor_multi.js | 4 +-- editor.html | 8 ++--- project/comment.js | 1 + 7 files changed, 93 insertions(+), 39 deletions(-) diff --git a/_server/README.md b/_server/README.md index e75cf35d..d074b9d5 100644 --- a/_server/README.md +++ b/_server/README.md @@ -2,15 +2,20 @@ 本目录下所有文件,以及`../editor.html`和`../启动服务.exe`([源码](http://github.com/ckcz123/mota-js-server/))是地图编辑器的所有组件. -`editor.js`,`editor_file.js`和`editor_mode.js`耦合较强,`editor_blockly.js`和`fs.js`基本可以独立使用. +`editor.js`,`editor_file.js`和`editor_mode.js`耦合较强,`editor_blockly.js`和`editor_multi.js`和`fs.js`基本可以独立使用. ## 各组件功能 ### editor.js -暂略 +``` js +editor.mapInit();//清空地图 +editor.changeFloor('MT2')//切换地图 +editor.guid()//产生一个可以作为id的长随机字符串 +``` ### editor_file.js + 提供了以下函数进行楼层`map`数组相关的操作 ```javascript editor.file.getFloorFileList @@ -18,6 +23,7 @@ editor.file.loadFloorFile editor.file.saveFloorFile editor.file.saveFloorFileAs ``` + 编辑模式有关的查询 ```javascript editor.file.editItem('redJewel',[],function(a){console.log(a)}); @@ -27,6 +33,7 @@ editor.file.editFloor([],function(a){console.log(a)}); editor.file.editTower([],function(a){console.log(a)}); editor.file.editFunctions([],function(a){console.log(a)}); ``` + 编辑模式有关的编辑 ```javascript editor.info={images: "terrains", y: 9}; @@ -40,7 +47,7 @@ editor.file.editFunctions(["change","['events']['afterChangeLight']","function(x ``` ### editor_mode.js -5个生成表格并绑定事件的函数 +生成表格并绑定事件的函数 ```javascript editor.mode.loc(); editor.mode.emenyitem(); @@ -48,6 +55,7 @@ editor.mode.floor(); editor.mode.tower(); editor.mode.functions(); ``` + 切换模式 ```javascript editor.mode.onmode('');//清空 @@ -72,24 +80,64 @@ while (!editor_mode._ids.hasOwnProperty(node.getAttribute('id'))) { } editor_mode.onmode(editor_mode._ids[node.getAttribute('id')]); ``` + +`editor.mode.listen`中提供了追加素材的支持. + ### editor_blockly.js + 把选定`id_`的事件用blockly编辑 ``` js editor_blockly.import(id_); ``` + 把文本区域的代码转换成图块 ``` js editor_blockly.parse(); ``` -把当前图块对应的事件返回给调用blockly的`id_` + +### editor_multi.js + +用[CodeMirror](https://github.com/codemirror/CodeMirror) 实现有高亮的多行文本编辑 + +编辑选定`id_`的文本域 ``` js -editor_blockly.confirm(); +editor_multi.import(id_) ``` -### 待调整 +编辑blockly方块的特定域 +``` js +editor_multi.multiLineEdit(value,b,f,callback) +``` -+ [x] 多行文本编辑器独立作为组件 -+ [x] editor_multi.js +### fs.js + +模仿node的fs模块提供如下api,与`启动服务.exe`配合为js提供文件读写功能 +``` js +fs.readFile('file.in','utf-8',callback) +//读文本文件 +//callback:function(err, data) +//data:字符串 +fs.readFile('file.in','base64',callback) +//读二进制文件 +//callback:function(err, data) +//data:base64字符串 + +fs.writeFile('file.out', data ,'utf-8', callback) +//写文本文件 +//callback:function(err) +//data:字符串 +fs.writeFile('file.out', data ,'base64', callback) +//写二进制文件 +//callback:function(err) +//data:base64字符串 + +fs.readdir(path, callback) +//callback:function(err, data) +//path:支持"/"做分隔符 +//data:[filename1,filename2,..] filename是字符串,只包含文件不包含目录 + +//所有参数不允许缺省 +``` ## z-index diff --git a/_server/css/editor_mode.css b/_server/css/editor_mode.css index e260377c..9dc1d587 100644 --- a/_server/css/editor_mode.css +++ b/_server/css/editor_mode.css @@ -19,6 +19,11 @@ width: 435px; } +#appendPicSelection span { + font-size:11px; + -webkit-text-stroke: 1px black; +} + #left6 { left: 5px; /* top: 1930px; */ @@ -87,6 +92,7 @@ background-color: #f6f8fa; } /* copy end --------------------------------------------- */ + .etable tr {width:100%} .etable tr > :nth-child(1) {width:20%} .etable tr > :nth-child(2) {width:20%} diff --git a/_server/editor_file.js b/_server/editor_file.js index 966b3b00..b5a853b4 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -175,11 +175,11 @@ editor_file = function(editor, callback){ saveSetting('items',actionList,function (err) { callback([ {'items':(function(){ - var locObj={}; + var locObj=Object.assign({},editor.core.items.items[id]); Object.keys(editor_file.comment.items.items).forEach(function(v){ - if (isset(editor.core.items.items[id][v])) - locObj[v]=editor.core.items.items[id][v]; - else + if (!isset(editor.core.items.items[id][v])) + /* locObj[v]=editor.core.items.items[id][v]; + else */ locObj[v]=null; }); return locObj; @@ -191,11 +191,11 @@ editor_file = function(editor, callback){ } else { callback([ {'items':(function(){ - var locObj={}; + var locObj=Object.assign({},editor.core.items.items[id]); Object.keys(editor_file.comment.items.items).forEach(function(v){ - if (isset(editor.core.items.items[id][v])) - locObj[v]=editor.core.items.items[id][v]; - else + if (!isset(editor.core.items.items[id][v])) + /* locObj[v]=editor.core.items.items[id][v]; + else */ locObj[v]=null; }); return locObj; @@ -223,11 +223,11 @@ editor_file = function(editor, callback){ saveSetting('enemys',actionList,function (err) { callback([ (function(){ - var locObj={}; + var locObj=Object.assign({},editor.core.enemys.enemys[id]); Object.keys(editor_file.comment.enemys).forEach(function(v){ - if (isset(editor.core.enemys.enemys[id][v])) - locObj[v]=editor.core.enemys.enemys[id][v]; - else + if (!isset(editor.core.enemys.enemys[id][v])) + /* locObj[v]=editor.core.enemys.enemys[id][v]; + else */ locObj[v]=null; }); return locObj; @@ -238,11 +238,11 @@ editor_file = function(editor, callback){ } else { callback([ (function(){ - var locObj={}; + var locObj=Object.assign({},editor.core.enemys.enemys[id]); Object.keys(editor_file.comment.enemys).forEach(function(v){ - if (isset(editor.core.enemys.enemys[id][v])) - locObj[v]=editor.core.enemys.enemys[id][v]; - else + if (!isset(editor.core.enemys.enemys[id][v])) + /* locObj[v]=editor.core.enemys.enemys[id][v]; + else */ locObj[v]=null; }); return locObj; @@ -315,11 +315,11 @@ editor_file = function(editor, callback){ saveSetting('floors',actionList,function (err) { callback([ (function(){ - var locObj={}; + var locObj=Object.assign({},editor.currentFloorData); Object.keys(editor_file.comment.floors.floor).forEach(function(v){ - if (isset(editor.currentFloorData[v])) - locObj[v]=editor.currentFloorData[v]; - else + if (!isset(editor.currentFloorData[v])) + /* locObj[v]=editor.currentFloorData[v]; + else */ locObj[v]=null; }); return locObj; @@ -330,11 +330,11 @@ editor_file = function(editor, callback){ } else { callback([ (function(){ - var locObj={}; + var locObj=Object.assign({},editor.currentFloorData); Object.keys(editor_file.comment.floors.floor).forEach(function(v){ - if (isset(editor.currentFloorData[v])) - locObj[v]=editor.currentFloorData[v]; - else + if (!isset(editor.currentFloorData[v])) + /* locObj[v]=editor.currentFloorData[v]; + else */ locObj[v]=null; }); return locObj; diff --git a/_server/editor_mode.js b/_server/editor_mode.js index 83c51823..d48e222e 100644 --- a/_server/editor_mode.js +++ b/_server/editor_mode.js @@ -371,7 +371,6 @@ editor_mode.prototype.listen = function(callback){ selectAppend.onchange(); var selectFileBtn = document.getElementById('selectFileBtn'); - var selectFileStr = document.getElementById('selectFileStr'); selectFileBtn.onclick = function(){ var loadImage = function (content, callback) { var image = new Image(); diff --git a/_server/editor_multi.js b/_server/editor_multi.js index 556096f7..e536d17e 100644 --- a/_server/editor_multi.js +++ b/_server/editor_multi.js @@ -29,7 +29,7 @@ editor_multi.import = function(id_){ editor_multi.isString=true; codeEditor.setValue(JSON.parse(input.value)||''); } else { - eval('var tobj='+input.value); + eval('var tobj='+(input.value||'null')); var tmap={}; var tstr = JSON.stringify(tobj,function(k,v){if(typeof(v)===typeof('') && v.slice(0,8)==='function'){var id_ = editor.guid();tmap[id_]=v.toString();return id_;}else return v},4); for(var id_ in tmap){ @@ -64,7 +64,7 @@ editor_multi.confirm = function (){ if(editor_multi.isString){ input.value = JSON.stringify(value); } else { - eval('var tobj='+value); + eval('var tobj='+(value||'null')); var tmap={}; var tstr = JSON.stringify(tobj,function(k,v){if(v instanceof Function){var id_ = editor.guid();tmap[id_]=v.toString();return id_;}else return v},4); for(var id_ in tmap){ diff --git a/editor.html b/editor.html index 494ac186..243bb2e8 100644 --- a/editor.html +++ b/editor.html @@ -49,10 +49,10 @@
-
1
-
  2
-
    3
-
      4
+
1
+
  2
+
    3
+
      4
diff --git a/project/comment.js b/project/comment.js index dfd1aed8..5ca2803e 100644 --- a/project/comment.js +++ b/project/comment.js @@ -25,6 +25,7 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = 'bomb':' 加入 "bomb": false 代表该怪物不可被炸弹或圣锤炸掉\n$select({\"values\":[true,false]})$end', 'point': 'point可以在打败怪物后进行加点,详见文档说明\n$range((thiseval==~~thiseval && thiseval>0)||thiseval==null)$end', 'n': '多连击需要在后面指定n代表是几连击\n$range((thiseval==~~thiseval && thiseval>0)||thiseval==null)$end', + 'add': '代表吸血后是否加到自身\n$select({\"values\":[true,false]})$end', 'atkValue':'退化时勇士下降的攻击力点数\n$range(thiseval==~~thiseval||thiseval==null)$end', 'defValue':'退化时勇士下降的防御力点数\n$range(thiseval==~~thiseval||thiseval==null)$end', 'damage':'战前扣血的点数\n$range(thiseval==~~thiseval||thiseval==null)$end'