From c73d16c1b986b4500c427933b4d5de4bfcc0e83d Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Sun, 21 Apr 2019 17:59:50 -0400 Subject: [PATCH 1/4] update --- _server/editor_file.js | 95 +++++++++------------------------------ _server/editor_game.js | 100 ++++++++++++++++++++++++----------------- _server/refactoring.md | 8 +++- editor-mobile.html | 2 +- editor.html | 2 +- 5 files changed, 89 insertions(+), 118 deletions(-) diff --git a/_server/editor_file.js b/_server/editor_file.js index 1a8a9fa0..f0387da8 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -32,11 +32,7 @@ editor_file = function (editor, callback) { editor_file.getFloorFileList = function (callback) { - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); /* var fs = editor.fs; fs.readdir('project/floors',function(err, data){ callback([data,err]); @@ -46,22 +42,14 @@ editor_file = function (editor, callback) { //callback([Array,err:String]) editor_file.loadFloorFile = function (filename, callback) { //filename不含'/'不含'.js' - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); editor.currentFloorId = editor.core.status.floorId; editor.currentFloorData = editor.core.floors[editor.currentFloorId]; } //callback(err:String) editor_file.saveFloorFile = function (callback) { - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); /* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) { callback('未选中文件或无数据'); } */ @@ -113,10 +101,7 @@ editor_file = function (editor, callback) { //callback(err:String) editor_file.saveNewFile = function (saveFilename, callback) { //saveAsFilename不含'/'不含'.js' - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - }; + checkCallback(callback); var currData=editor.currentFloorData; var saveStatus = document.getElementById('newMapStatus').checked; @@ -163,10 +148,7 @@ editor_file = function (editor, callback) { editor_file.saveFloorFile(callback); } editor_file.saveNewFiles = function (floorIdList, from, to, callback) { - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - }; + checkCallback(callback); var currData=editor.currentFloorData; var saveStatus = document.getElementById('newMapsStatus').checked; @@ -349,11 +331,7 @@ editor_file = function (editor, callback) { } editor_file.changeIdAndIdnum = function (id, idnum, info, callback) { - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); //检查maps中是否有重复的idnum或id var change = -1; for (var ii in editor.core.maps.blocksInfo) { @@ -428,11 +406,7 @@ editor_file = function (editor, callback) { ] 为[]时只查询不修改 */ - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); if (isset(actionList) && actionList.length > 0) { actionList.forEach(function (value) { var tempindex = value[1].indexOf(']') + 1; @@ -475,11 +449,7 @@ editor_file = function (editor, callback) { ] 为[]时只查询不修改 */ - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); if (isset(actionList) && actionList.length > 0) { actionList.forEach(function (value) { value[1] = "['" + id + "']" + value[1]; @@ -512,11 +482,7 @@ editor_file = function (editor, callback) { ] 为[]时只查询不修改 */ - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); if (isset(actionList) && actionList.length > 0) { var tempmap=[]; for(var ii=0;ii 0) { actionList.forEach(function (value) { value[1] = value[1] + "['" + x + "," + y + "']"; @@ -600,11 +562,7 @@ editor_file = function (editor, callback) { ] 为[]时只查询不修改 */ - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); if (isset(actionList) && actionList.length > 0) { saveSetting('floors', actionList, function (err) { callback([err]); @@ -643,11 +601,7 @@ editor_file = function (editor, callback) { 为[]时只查询不修改 */ var data_obj = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d; - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); if (isset(actionList) && actionList.length > 0) { saveSetting('data', actionList, function (err) { callback([err]); @@ -698,11 +652,7 @@ editor_file = function (editor, callback) { ] 为[]时只查询不修改 */ - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); if (isset(actionList) && actionList.length > 0) { saveSetting('functions', actionList, function (err) { callback([err]); @@ -729,11 +679,7 @@ editor_file = function (editor, callback) { 为[]时只查询不修改 */ var data_obj = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent; - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); if (isset(actionList) && actionList.length > 0) { actionList.forEach(function (value) { value[1] = "['commonEvent']" + value[1]; @@ -780,11 +726,7 @@ editor_file = function (editor, callback) { ] 为[]时只查询不修改 */ - if (!isset(callback)) { - printe('未设置callback'); - throw('未设置callback') - } - ; + checkCallback(callback); if (isset(actionList) && actionList.length > 0) { saveSetting('plugins', actionList, function (err) { callback([err]); @@ -811,6 +753,13 @@ editor_file = function (editor, callback) { return true } + var checkCallback=function(callback){ + if (!isset(callback)) { + printe('未设置callback'); + throw('未设置callback') + } + } + var formatMap = function (mapArr,trySimplify) { if(!mapArr || JSON.stringify(mapArr)==JSON.stringify([]))return ''; if(trySimplify){ diff --git a/_server/editor_game.js b/_server/editor_game.js index efd447bf..efe59fec 100644 --- a/_server/editor_game.js +++ b/_server/editor_game.js @@ -1,37 +1,56 @@ editor_game_wrapper = function (editor, main, core) { editor_game = function () { + this.replacerRecord = {} + } + // 三个 replacer 和 replacerRecord 暂时放在此处 + editor_game.prototype.replacerForLoading = function (_key, value) { + var rmap = editor.game.replacerRecord; + if (value instanceof Function) { + var guid_ = editor.util.guid() + rmap[guid_] = value.toString() + return guid_ + } else if (value === null) { + // 为了包含functions的新建, 不使用'null'是否有问题待测 + var guid_ = editor.util.guid() + rmap[guid_] = null + return guid_ + } + return value + } + + editor_game.prototype.replacerForSaving = function (_key, value) { + var rmap = editor.game.replacerRecord; + if (rmap.hasOwnProperty(value)) { + return rmap[value] + } + return value + } + + editor_game.prototype.replacerWithoutRecord = function (_key, value) { + if (value instanceof Function) { + return value.toString() + } else return value } editor_game.prototype.fixFunctionInGameData = function () { - core.floors = JSON.parse(JSON.stringify(core.floors, function (_k, v) { - if (v instanceof Function) { - return v.toString() - } else return v - })); - core.data = JSON.parse(JSON.stringify(core.data, function (_k, v) { - if (v instanceof Function) { - return v.toString() - } else return v - })); - data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = JSON.parse(JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, function (_k, v) { - if (v instanceof Function) { - return v.toString() - } else return v - })); + var rf = editor.game.replacerWithoutRecord + core.floors = JSON.parse(JSON.stringify(core.floors, rf)); + core.data = JSON.parse(JSON.stringify(core.data, rf)); + 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 = []; var MAX_NUM = 0; - var keys=Object.keys(maps_90f36752_8815_4be8_b32b_d7fad1d0542e); - for(var ii=0;iiMAX_NUM && v MAX_NUM && v < core.icons.tilesetStartOffset) MAX_NUM = v; } - editor.MAX_NUM=MAX_NUM; + editor.MAX_NUM = MAX_NUM; var getInfoById = function (id) { var block = maps.initBlock(0, 0, id); if (Object.prototype.hasOwnProperty.call(block, 'event')) { @@ -46,15 +65,15 @@ editor_game_wrapper = function (editor, main, core) { var id = indexBlock.event.id; var indexId = indexBlock.id; var allCls = Object.keys(icons); - if(i==17){ - editor.ids.push({'idnum': 17, 'id': id, 'images': 'terrains'}); + if (i == 17) { + editor.ids.push({ 'idnum': 17, 'id': id, 'images': 'terrains' }); point++; editor.indexs[i].push(point); continue; } for (var j = 0; j < allCls.length; j++) { if (id in icons[allCls[j]]) { - editor.ids.push({'idnum': indexId, 'id': id, 'images': allCls[j], 'y': icons[allCls[j]][id]}); + editor.ids.push({ 'idnum': indexId, 'id': id, 'images': allCls[j], 'y': icons[allCls[j]][id] }); point++; editor.indexs[i].push(point); } @@ -62,36 +81,36 @@ editor_game_wrapper = function (editor, main, core) { } } editor.indexs[0] = [0]; - + var startOffset = core.icons.tilesetStartOffset; for (var i in core.tilesets) { var imgName = core.tilesets[i]; var img = core.material.images.tilesets[imgName]; - var width = Math.floor(img.width/32), height = Math.floor(img.height/32); - if(img.width%32 || img.height%32){ - alert(imgName+'的长或宽不是32的整数倍, 请修改后刷新页面'); + var width = Math.floor(img.width / 32), height = Math.floor(img.height / 32); + if (img.width % 32 || img.height % 32) { + alert(imgName + '的长或宽不是32的整数倍, 请修改后刷新页面'); } - if(img.width*img.height > 32*32*3000){ - alert(imgName+'上的图块数量超过了3000,请修改后刷新页面'); + if (img.width * img.height > 32 * 32 * 3000) { + alert(imgName + '上的图块数量超过了3000,请修改后刷新页面'); } - for (var id=startOffset; id, 准备改为和core一致只储存数字 ++ editor.widthX特别不直观 + ## 功能改进 + [ ] 大地图 @@ -103,6 +105,8 @@ editor: { + [ ] `显示文章`以及`选项`等方块, 把`标题`和`图像`从字符串提取出填回相应的空 ++ [ ] blockly中某些需要选点的填空, 增加按钮, 点击后从缩略图中点击位置 + ## 左侧页面模式 标题? 保存按钮? 添加按钮? 删除按钮? diff --git a/editor-mobile.html b/editor-mobile.html index b60e2836..cb43de52 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -523,8 +523,8 @@ - + diff --git a/editor.html b/editor.html index 7953d7ba..c7c02094 100644 --- a/editor.html +++ b/editor.html @@ -506,8 +506,8 @@ - + From 3bae60a545d5010517b2e81d7543e8ec9c51cbab Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Sun, 21 Apr 2019 18:14:48 -0400 Subject: [PATCH 2/4] update --- _server/editor_file.js | 2 +- _server/editor_game.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/_server/editor_file.js b/_server/editor_file.js index f0387da8..dce01c80 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -706,7 +706,7 @@ editor_file = function (editor, callback) { return id_; } else if(v===null){ var id_ = editor.util.guid(); - plmap[id_] = 'null'; + plmap[id_] = null; return id_; } return v }, 4); diff --git a/_server/editor_game.js b/_server/editor_game.js index efe59fec..71667b59 100644 --- a/_server/editor_game.js +++ b/_server/editor_game.js @@ -1,4 +1,5 @@ editor_game_wrapper = function (editor, main, core) { + // 原则上重构后只有此文件允许`\b(main|core)`形式的调用, 以及其初始化 editor_game_wrapper(editor, main, core) editor_game = function () { this.replacerRecord = {} @@ -12,7 +13,7 @@ editor_game_wrapper = function (editor, main, core) { rmap[guid_] = value.toString() return guid_ } else if (value === null) { - // 为了包含functions的新建, 不使用'null'是否有问题待测 + // 为了包含plugins的新建 var guid_ = editor.util.guid() rmap[guid_] = null return guid_ From 3360d151e731df7701d8e618452794144e69d462 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Sun, 21 Apr 2019 18:16:15 -0400 Subject: [PATCH 3/4] fix comment --- _server/editor_game.js | 2 +- _server/refactoring.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_server/editor_game.js b/_server/editor_game.js index 71667b59..46639469 100644 --- a/_server/editor_game.js +++ b/_server/editor_game.js @@ -1,5 +1,5 @@ editor_game_wrapper = function (editor, main, core) { - // 原则上重构后只有此文件允许`\b(main|core)`形式的调用, 以及其初始化 editor_game_wrapper(editor, main, core) + // 原则上重构后只有此文件允许`\s(main|core)`形式的调用, 以及其初始化 editor_game_wrapper(editor, main, core) editor_game = function () { this.replacerRecord = {} diff --git a/_server/refactoring.md b/_server/refactoring.md index d867c2ff..ff45ab82 100644 --- a/_server/refactoring.md +++ b/_server/refactoring.md @@ -11,7 +11,7 @@ + [ ] editor_multi 多行文本编辑器 + [x] editor_table 处理表格的生成, 及其响应的事件, 从原editor\_mode中分离 + [ ] editor_file 调用fs.js编辑文件, 把原editor\_file模块化 -+ [ ] editor_game 处理来自core的数据, 导入为editor的数据, 从原editor中分离. **只有此文件允许`\b(main|core)`形式的调用**(以及其初始化`editor_game_wrapper(editor, main, core);`) ++ [ ] editor_game 处理来自core的数据, 导入为editor的数据, 从原editor中分离. **只有此文件允许`\s(main|core)`形式的调用**(以及其初始化`editor_game_wrapper(editor, main, core);`) + [x] editor_util 生成guid等函数, 从editor分离 + [ ] editor 执行初始化流程加组合各组件 + [ ] 原editor_mode 移除 From b41feefa0749c832cdcc3f93381bf090a570e1b0 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Sun, 21 Apr 2019 18:33:20 -0400 Subject: [PATCH 4/4] add /* html */ to get tpl highlighted by plugin https://marketplace.visualstudio.com/items?itemName=bierner.comment-tagged-templates --- _server/editor_blockly.js | 21 +++++++++++++-------- _server/editor_table.js | 16 ++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 02453bab..44b03be5 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -2,7 +2,11 @@ editor_blockly = function () { var editor_blockly = {}; - initscript = String.raw` +/////////////////initscript start///////////////////////////// +// do not use String.raw because of highlighting +// Comment tagged templates +// https://marketplace.visualstudio.com/items?itemName=bierner.comment-tagged-templates + initscript = /* js */` (function(){ var getCategory = function(name,custom){ for(var node of document.getElementById('toolbox').children) { @@ -30,7 +34,7 @@ editor_blockly = function () { "textInList": "1F金币商店", "use": "money", "need": "20+10*times*(times+1)", - "text": "勇敢的武士啊,给我\${need}金币就可以:", + "text": "勇敢的武士啊,给我\\\${need}金币就可以:", "choices": [ {"text": "生命+800", "effect": "status:hp+=800"}, {"text": "攻击+4", "effect": "status:atk+=4"}, @@ -188,27 +192,27 @@ editor_blockly = function () { '', MotaActionFunctions.actionParser.parseList({"type": "if", "condition": "!core.musicStatus.bgmStatus", "true": [ - "\t[系统提示]你当前音乐处于关闭状态,本塔开音乐游戏效果更佳" + "\\t[系统提示]你当前音乐处于关闭状态,本塔开音乐游戏效果更佳" ], "false": [] }), '', MotaActionFunctions.actionParser.parse([ - {"type": "choices", "text": "\t[老人,man]少年,你需要钥匙吗?\n我这里有大把的!", + {"type": "choices", "text": "\\t[老人,man]少年,你需要钥匙吗?\\n我这里有大把的!", "choices": [ - {"text": "黄钥匙(\${9+flag:shop_times}金币)", "color": [255,255,0,1], "action": [ + {"text": "黄钥匙(\\\${9+flag:shop_times}金币)", "color": [255,255,0,1], "action": [ {"type": "if", "condition": "status:money>=9+flag:shop_times", "true": [ {"type": "addValue", "name": "status:money", "value": "-(9+flag:shop_times)"}, {"type": "addValue", "name": "item:yellowKey", "value": "1"}, ], "false": [ - "\t[老人,man]你的金钱不足!", + "\\t[老人,man]你的金钱不足!", {"type": "revisit"} ] } ]}, - {"text": "蓝钥匙(\${18+2*flag:shop_times}金币)", "color": [0,0,255,1], "action": [ + {"text": "蓝钥匙(\\\${18+2*flag:shop_times}金币)", "color": [0,0,255,1], "action": [ ]}, {"text": "离开", "action": [ {"type": "exit"} @@ -361,7 +365,7 @@ function omitedcheckUpdateFunction(event) { } } try { - var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\i/g, '\\\\i'); + var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\\\i/g, '\\\\\\\\i'); codeAreaHL.setValue(code); } catch (error) { codeAreaHL.setValue(String(error)); @@ -433,6 +437,7 @@ function omitedcheckUpdateFunction(event) { } })(); `; +/////////////////initscript end ///////////////////////////// var input_ = ''; editor_blockly.runOne = function () { diff --git a/_server/editor_table.js b/_server/editor_table.js index a3b742cd..e141e5ff 100644 --- a/_server/editor_table.js +++ b/_server/editor_table.js @@ -12,31 +12,31 @@ editor_table_wrapper = function (editor) { values.map(function (v) { return editor.table.option(v) }).join('') - return `\n` + return /* html */`\n` } editor_table.prototype.option = function (value) { - return `\n` + return /* html */`\n` } editor_table.prototype.text = function (value) { - return `\n` + return /* html */`\n` } editor_table.prototype.checkbox = function (value) { - return `\n` + return /* html */`\n` } editor_table.prototype.textarea = function (value, indent) { - return `\n` + return /* html */`\n` } editor_table.prototype.title = function () { - return `\n条目注释值\n` + return /* html */`\n条目注释值\n` } editor_table.prototype.gap = function (field) { - return `--------${field}\n` + return /* html */`--------${field}\n` } editor_table.prototype.tr = function (guid, field, shortField, commentHTMLescape, cobjstr, shortCommentHTMLescape, tdstr) { - return ` + return /* html */` ${shortField} ${shortCommentHTMLescape}
${tdstr}