From 4e102eba6c2e01dbaa9fe8dfaa70831721600c61 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 23 Apr 2019 14:39:19 -0400 Subject: [PATCH] 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 移除