From 4e102eba6c2e01dbaa9fe8dfaa70831721600c61 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 23 Apr 2019 14:39:19 -0400 Subject: [PATCH 1/5] editor_file --- _server/README.md | 2 -- _server/editor.js | 1 + _server/editor_file_unsorted.js | 17 ----------------- _server/editor_game.js | 25 +++++++++++++++++++++---- _server/editor_unsorted_2.js | 2 +- _server/editor_util.js | 11 +++++++++++ _server/refactoring.md | 6 +++--- 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/_server/README.md b/_server/README.md index d23bfb43..e6a12c67 100644 --- a/_server/README.md +++ b/_server/README.md @@ -42,8 +42,6 @@ editor.util.guid()//产生一个可以作为id的长随机字符串 提供了以下函数进行楼层`map`数组相关的操作 ```javascript -editor.file.getFloorFileList -editor.file.loadFloorFile editor.file.saveFloorFile editor.file.saveFloorFileAs ``` diff --git a/_server/editor.js b/_server/editor.js index 1e277681..aa5a21ec 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -53,6 +53,7 @@ editor.prototype.init = function (callback) { editor_file_wrapper(editor); editor_table_wrapper(editor); editor_unsorted_1_wrapper(editor); + editor.printe=printe; afterMainInit(); }); diff --git a/_server/editor_file_unsorted.js b/_server/editor_file_unsorted.js index 92ba8c81..27d4e7aa 100644 --- a/_server/editor_file_unsorted.js +++ b/_server/editor_file_unsorted.js @@ -7,23 +7,6 @@ editor_file = function (editor, callback) { /////////////////////////////////////////////////////////////////////////// - editor.file.getFloorFileList = function (callback) { - checkCallback(callback); - /* var fs = editor.fs; - fs.readdir('project/floors',function(err, data){ - callback([data,err]); - }); */ - callback([editor.core.floorIds, null]); - } - //callback([Array,err:String]) - editor.file.loadFloorFile = function (filename, callback) { - //filename不含'/'不含'.js' - checkCallback(callback); - - editor.currentFloorId = editor.core.status.floorId; - editor.currentFloorData = editor.core.floors[editor.currentFloorId]; - } - //callback(err:String) editor.file.saveFloorFile = function (callback) { checkCallback(callback); /* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) { diff --git a/_server/editor_game.js b/_server/editor_game.js index 13b4d402..278dd67e 100644 --- a/_server/editor_game.js +++ b/_server/editor_game.js @@ -5,7 +5,10 @@ editor_game_wrapper = function (editor, main, core) { this.replacerRecord = {} } + + //////////////////// 修改数据相关 //////////////////// // 三个 replacer 和 replacerRecord 暂时放在此处 + editor_game.prototype.replacerForLoading = function (_key, value) { var rmap = editor.game.replacerRecord; if (value instanceof Function) { @@ -29,7 +32,7 @@ editor_game_wrapper = function (editor, main, core) { return value } - editor_game.prototype.getValue = function(field){ + editor_game.prototype.getValue = function (field) { var rmap = editor.game.replacerRecord; var value = eval(field) if (rmap.hasOwnProperty(oldval)) { @@ -39,13 +42,13 @@ editor_game_wrapper = function (editor, main, core) { } } - editor_game.prototype.setValue = function(field,value){ + editor_game.prototype.setValue = function (field, value) { var rmap = editor.game.replacerRecord; var oldval = eval(field) if (rmap.hasOwnProperty(oldval)) { - rmap[value]=eval(value) + rmap[value] = eval(value) } else { - eval(field+'='+value) + eval(field + '=' + value) } } @@ -62,6 +65,9 @@ editor_game_wrapper = function (editor, main, core) { data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = JSON.parse(JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, rf)); } + //////////////////// 加载游戏数据相关 //////////////////// + + // 初始化数字与地图图块的对应 editor_game.prototype.idsInit = function (maps, icons) { editor.ids = [0]; editor.indexs = []; @@ -125,6 +131,7 @@ editor_game_wrapper = function (editor, main, core) { } } + // 获取当前地图 editor_game.prototype.fetchMapFromCore = function () { var mapArray = core.maps.saveMap(core.status.floorId); editor.map = mapArray.map(function (v) { @@ -158,6 +165,16 @@ editor_game_wrapper = function (editor, main, core) { } } + // 获取地图列表 + editor_game.prototype.getFloorFileList = function (callback) { + // callback([Array,err:String]) + editor.util.checkCallback(callback); + /* editor.fs.readdir('project/floors',function(err, data){ + callback([data,err]); + }); */ + callback([editor.core.floorIds, null]); + } + editor.constructor.prototype.game = new editor_game(); } //editor_game_wrapper(editor); \ No newline at end of file diff --git a/_server/editor_unsorted_2.js b/_server/editor_unsorted_2.js index 82dfd7b8..fe7ecf58 100644 --- a/_server/editor_unsorted_2.js +++ b/_server/editor_unsorted_2.js @@ -37,7 +37,7 @@ editor_unsorted_2_wrapper=function(editor_mode){ } var selectFloor = document.getElementById('selectFloor'); - editor.file.getFloorFileList(function (floors) { + editor.game.getFloorFileList(function (floors) { var outstr = []; floors[0].forEach(function (floor) { outstr.push(["\n'].join('')); diff --git a/_server/editor_util.js b/_server/editor_util.js index 83b745a5..6f81a8c1 100644 --- a/_server/editor_util.js +++ b/_server/editor_util.js @@ -157,6 +157,17 @@ editor_util_wrapper = function (editor) { }).join('')) } + editor_util.prototype.isset = function (val) { + return val != null && !(typeof val == 'number' && isNaN(val)); + } + + editor_util.prototype.checkCallback=function(callback){ + if (!editor.util.isset(callback)) { + editor.printe('未设置callback'); + throw('未设置callback') + } + } + editor.constructor.prototype.util = new editor_util(); } //editor_util_wrapper(editor); \ No newline at end of file diff --git a/_server/refactoring.md b/_server/refactoring.md index ff45ab82..7c3380c2 100644 --- a/_server/refactoring.md +++ b/_server/refactoring.md @@ -10,9 +10,9 @@ + [ ] editor_blockly 图块化事件编辑器 + [ ] editor_multi 多行文本编辑器 + [x] editor_table 处理表格的生成, 及其响应的事件, 从原editor\_mode中分离 -+ [ ] editor_file 调用fs.js编辑文件, 把原editor\_file模块化 -+ [ ] editor_game 处理来自core的数据, 导入为editor的数据, 从原editor中分离. **只有此文件允许`\s(main|core)`形式的调用**(以及其初始化`editor_game_wrapper(editor, main, core);`) -+ [x] editor_util 生成guid等函数, 从editor分离 ++ [ ] editor_file 调用fs.js编辑文件, 把原editor\_file模块化, 并且只负责文件写入 ++ [ ] editor_game 处理游戏数据, 导入为editor的数据, 编辑数据, 从原editor和editor_file中抽离. **只有此文件允许`\s(main|core)`形式的调用**(以及其初始化`editor_game_wrapper(editor, main, core);`) ++ [x] editor_util 生成guid/处理颜色 等函数, 从editor分离 + [ ] editor 执行初始化流程加组合各组件 + [ ] 原editor_mode 移除 + [x] 原vm 移除 From 057861d82644cf65cdad6e187d11906de044cc13 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 23 Apr 2019 14:58:15 -0400 Subject: [PATCH 2/5] floors_template --- _server/editor_file_unsorted.js | 34 ++++++------------------------ _server/table/comment.js | 37 +++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/_server/editor_file_unsorted.js b/_server/editor_file_unsorted.js index 27d4e7aa..80c34c3a 100644 --- a/_server/editor_file_unsorted.js +++ b/_server/editor_file_unsorted.js @@ -70,7 +70,8 @@ editor_file = function (editor, callback) { name = saveFilename.substring(2); title = "主塔 "+name+" 层"; } - editor.currentFloorData = { + // editor.file.comment._data.floors_template + editor.currentFloorData = Object.assign(JSON.parse(JSON.stringify(editor.file.comment._data.floors_template)), { floorId: saveFilename, title: title, name: name, @@ -80,24 +81,13 @@ editor_file = function (editor, callback) { canUseQuickShop: saveStatus?currData.canUseQuickShop:true, cannotViewMap: saveStatus?currData.cannotViewMap:false, cannotMoveDirectly: saveStatus?currData.cannotMoveDirectly:false, - images: [], item_ratio: saveStatus?currData.item_ratio:1, defaultGround: saveStatus?currData.defaultGround:"ground", bgm: saveStatus?currData.bgm:null, - upFloor: null, - downFloor: null, color: saveStatus?currData.color:null, weather: saveStatus?currData.weather:null, - firstArrive: [], - eachArrive: [], - parallelDo: "", - events: {}, - changeFloor: {}, - afterBattle: {}, - afterGetItem: {}, - afterOpenDoor: {}, - cannotMove: {} - }; + }); + Object.keys(editor.currentFloorData).forEach(function (t) { if (editor.currentFloorData[t] == null) delete editor.currentFloorData[t]; @@ -128,7 +118,7 @@ editor_file = function (editor, callback) { var datas = []; for (var i=from;i<=to;i++) { var datastr = ['main.floors.', floorIdList[i-from], '=\n{']; - var data = { + var data = Object.assign(JSON.parse(JSON.stringify(editor.file.comment._data.floors_template)), { floorId: floorIdList[i-from], title: calValue(document.getElementById('newFloorTitles').value, i), name: calValue(document.getElementById('newFloorNames').value, i), @@ -139,24 +129,12 @@ editor_file = function (editor, callback) { canUseQuickShop: saveStatus?currData.canUseQuickShop:true, cannotViewMap: saveStatus?currData.cannotViewMap:false, cannotMoveDirectly: saveStatus?currData.cannotMoveDirectly:false, - images: [], item_ratio: saveStatus?currData.item_ratio:1, defaultGround: saveStatus?currData.defaultGround:"ground", bgm: saveStatus?currData.bgm:null, - upFloor: null, - downFloor: null, color: saveStatus?currData.color:null, weather: saveStatus?currData.weather:null, - firstArrive: [], - eachArrive: [], - parallelDo: "", - events: {}, - changeFloor: {}, - afterBattle: {}, - afterGetItem: {}, - afterOpenDoor: {}, - cannotMove: {} - }; + }); Object.keys(data).forEach(function (t) { if (data[t] == null) delete data[t]; diff --git a/_server/table/comment.js b/_server/table/comment.js index ff09aa48..d5d72cf8 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -230,7 +230,7 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_type": "select", "_select": { "values": [ - null, + "null", "openDoor", "passNet", "changeLight", @@ -245,9 +245,9 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_type": "select", "_select": { "values": [ - null, - true, - false + "null", + "true", + "false" ] }, "_data": "该图块是否不可通行;true代表不可通行,false代表可通行,null代表使用系统缺省值" @@ -462,6 +462,35 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { } } } + }, + + "floors_template": { + "floorId": "to be covered", + "title": "new floor", + "name": "new floor", + "width": 13, + "height": 13, + "canFlyTo": true, + "canUseQuickShop": true, + "cannotViewMap": false, + "cannotMoveDirectly": false, + "images": [], + "item_ratio": 1, + "defaultGround": "ground", + "bgm": null, + "upFloor": null, + "downFloor": null, + "color": null, + "weather": null, + "firstArrive": [], + "eachArrive": [], + "parallelDo": "", + "events": {}, + "changeFloor": {}, + "afterBattle": {}, + "afterGetItem": {}, + "afterOpenDoor": {}, + "cannotMove": {} } } } \ No newline at end of file From 59b1bee743aa212d8531861ca5f0a350f967f339 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 23 Apr 2019 16:46:03 -0400 Subject: [PATCH 3/5] editor_file floors_template --- _server/editor_file_unsorted.js | 42 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/_server/editor_file_unsorted.js b/_server/editor_file_unsorted.js index 80c34c3a..471adb69 100644 --- a/_server/editor_file_unsorted.js +++ b/_server/editor_file_unsorted.js @@ -77,16 +77,17 @@ editor_file = function (editor, callback) { name: name, width: parseInt(document.getElementById('newMapWidth').value), height: parseInt(document.getElementById('newMapHeight').value), - canFlyTo: saveStatus?currData.canFlyTo:true, - canUseQuickShop: saveStatus?currData.canUseQuickShop:true, - cannotViewMap: saveStatus?currData.cannotViewMap:false, - cannotMoveDirectly: saveStatus?currData.cannotMoveDirectly:false, - item_ratio: saveStatus?currData.item_ratio:1, - defaultGround: saveStatus?currData.defaultGround:"ground", - bgm: saveStatus?currData.bgm:null, - color: saveStatus?currData.color:null, - weather: saveStatus?currData.weather:null, - }); + },saveStatus?{ + canFlyTo: currData.canFlyTo, + canUseQuickShop: currData.canUseQuickShop, + cannotViewMap: currData.cannotViewMap, + cannotMoveDirectly: currData.cannotMoveDirectly, + item_ratio: currData.item_ratio, + defaultGround: currData.defaultGround, + bgm: currData.bgm, + color: currData.color, + weather: currData.weather, + }:{}); Object.keys(editor.currentFloorData).forEach(function (t) { if (editor.currentFloorData[t] == null) @@ -125,16 +126,17 @@ editor_file = function (editor, callback) { width: width, height: height, map: map, - canFlyTo: saveStatus?currData.canFlyTo:true, - canUseQuickShop: saveStatus?currData.canUseQuickShop:true, - cannotViewMap: saveStatus?currData.cannotViewMap:false, - cannotMoveDirectly: saveStatus?currData.cannotMoveDirectly:false, - item_ratio: saveStatus?currData.item_ratio:1, - defaultGround: saveStatus?currData.defaultGround:"ground", - bgm: saveStatus?currData.bgm:null, - color: saveStatus?currData.color:null, - weather: saveStatus?currData.weather:null, - }); + },saveStatus?{ + canFlyTo: currData.canFlyTo, + canUseQuickShop: currData.canUseQuickShop, + cannotViewMap: currData.cannotViewMap, + cannotMoveDirectly: currData.cannotMoveDirectly, + item_ratio: currData.item_ratio, + defaultGround: currData.defaultGround, + bgm: currData.bgm, + color: currData.color, + weather: currData.weather, + }:{}); Object.keys(data).forEach(function (t) { if (data[t] == null) delete data[t]; From b49fbc6c22c692091a176236aa519e42d3e7f9f8 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 23 Apr 2019 17:08:31 -0400 Subject: [PATCH 4/5] editor_file --- _server/editor_file_unsorted.js | 42 +++++++++++++-------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/_server/editor_file_unsorted.js b/_server/editor_file_unsorted.js index 471adb69..72e204ae 100644 --- a/_server/editor_file_unsorted.js +++ b/_server/editor_file_unsorted.js @@ -14,31 +14,16 @@ editor_file = function (editor, callback) { } */ var filename = 'project/floors/' + editor.currentFloorId + '.js'; var datastr = ['main.floors.', editor.currentFloorId, '=\n']; - if (editor.currentFloorData.map == 'new') { - /* - editor.currentFloorData.map = editor.map.map(function (v) { - return v.map(function () { - return 0 + + 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 }) }); - */ - var width = parseInt(document.getElementById('newMapWidth').value); - var height = parseInt(document.getElementById('newMapHeight').value); - var row = []; - for (var i=0;i Date: Tue, 23 Apr 2019 17:49:49 -0400 Subject: [PATCH 5/5] =?UTF-8?q?update=20refactoring.md=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E9=87=8D=E6=9E=84=E6=80=9D=E8=B7=AF,?= =?UTF-8?q?=E5=85=B3=E4=BA=8Eedtior=5Ffile=E7=9A=84=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=80=9D=E8=80=83=E7=9A=84(=E5=8F=AF=E8=83=BD)=E6=AF=94?= =?UTF-8?q?=E8=BE=83=E6=B8=85=E6=99=B0=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/editor_file.js | 1 + _server/refactoring.md | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/_server/editor_file.js b/_server/editor_file.js index 84c6595f..9b9f0418 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -3,6 +3,7 @@ editor_file_wrapper = function (editor) { } + // 这个函数之后挪到editor.table? editor_file_proto.prototype.loadCommentjs=function(callback){ var commentjs = { 'comment': 'comment', diff --git a/_server/refactoring.md b/_server/refactoring.md index 7c3380c2..8ea8c365 100644 --- a/_server/refactoring.md +++ b/_server/refactoring.md @@ -1,9 +1,18 @@ # 重构 +总体思路 + 按功能拆分文件 + 左侧页面模块化, 方便添加 + 不同的模式的文件操作尽可能模块化 +目前主要在重构editor_file, 思路是editor.file负责把editor.game内的游戏数据格式化成字符串以及写入到文件, 由editor.game来修改数据 ++ editor.file维护一些标记, 描述哪些数据需要格式化并写入, 在save时写入文件(自动保存的话就是每次修改数据都触发save) ++ editor.game修改数据, 并修改editor.file中的标记 ++ 此思路下editor.file的大部分内容会挪到editor.game, editor.game和editor.table可能会再进一步合并拆分 + +editor_file之后是更改editor.map的储存方式, 现有的存对象的模式要在对象和数字间来回转换, 非常繁琐和奇怪 + +再之后是把editor_unsorted_*.js整理清晰 ## 文件结构