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.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/editor_file_unsorted.js b/_server/editor_file_unsorted.js index 92ba8c81..72e204ae 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)) { @@ -31,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,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..8ea8c365 100644 --- a/_server/refactoring.md +++ b/_server/refactoring.md @@ -1,18 +1,27 @@ # 重构 +总体思路 + 按功能拆分文件 + 左侧页面模块化, 方便添加 + 不同的模式的文件操作尽可能模块化 +目前主要在重构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整理清晰 ## 文件结构 + [ ] 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 移除 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