Merge pull request #358 from zhaouv/refactoring-editor

refactoring-update
This commit is contained in:
Zhang Chen 2019-04-22 11:39:35 +08:00 committed by GitHub
commit 354f2d192f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 112 additions and 135 deletions

View File

@ -2,7 +2,11 @@ editor_blockly = function () {
var editor_blockly = {}; 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(){ (function(){
var getCategory = function(name,custom){ var getCategory = function(name,custom){
for(var node of document.getElementById('toolbox').children) { for(var node of document.getElementById('toolbox').children) {
@ -30,7 +34,7 @@ editor_blockly = function () {
"textInList": "1F金币商店", "textInList": "1F金币商店",
"use": "money", "use": "money",
"need": "20+10*times*(times+1)", "need": "20+10*times*(times+1)",
"text": "勇敢的武士啊,给我\${need}金币就可以:", "text": "勇敢的武士啊,给我\\\${need}金币就可以:",
"choices": [ "choices": [
{"text": "生命+800", "effect": "status:hp+=800"}, {"text": "生命+800", "effect": "status:hp+=800"},
{"text": "攻击+4", "effect": "status:atk+=4"}, {"text": "攻击+4", "effect": "status:atk+=4"},
@ -188,27 +192,27 @@ editor_blockly = function () {
'<label text="检测音乐如果没有开启则系统提示开启"></label>', '<label text="检测音乐如果没有开启则系统提示开启"></label>',
MotaActionFunctions.actionParser.parseList({"type": "if", "condition": "!core.musicStatus.bgmStatus", MotaActionFunctions.actionParser.parseList({"type": "if", "condition": "!core.musicStatus.bgmStatus",
"true": [ "true": [
"\t[系统提示]你当前音乐处于关闭状态,本塔开音乐游戏效果更佳" "\\t[系统提示]你当前音乐处于关闭状态,本塔开音乐游戏效果更佳"
], ],
"false": [] "false": []
}), }),
'<label text="商店购买属性/钥匙"></label>', '<label text="商店购买属性/钥匙"></label>',
MotaActionFunctions.actionParser.parse([ MotaActionFunctions.actionParser.parse([
{"type": "choices", "text": "\t[老人,man]少年,你需要钥匙吗?\n我这里有大把的", {"type": "choices", "text": "\\t[老人,man]少年,你需要钥匙吗?\\n我这里有大把的",
"choices": [ "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", {"type": "if", "condition": "status:money>=9+flag:shop_times",
"true": [ "true": [
{"type": "addValue", "name": "status:money", "value": "-(9+flag:shop_times)"}, {"type": "addValue", "name": "status:money", "value": "-(9+flag:shop_times)"},
{"type": "addValue", "name": "item:yellowKey", "value": "1"}, {"type": "addValue", "name": "item:yellowKey", "value": "1"},
], ],
"false": [ "false": [
"\t[老人,man]你的金钱不足!", "\\t[老人,man]你的金钱不足!",
{"type": "revisit"} {"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": [ {"text": "离开", "action": [
{"type": "exit"} {"type": "exit"}
@ -361,7 +365,7 @@ function omitedcheckUpdateFunction(event) {
} }
} }
try { try {
var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\i/g, '\\\\i'); var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\\\i/g, '\\\\\\\\i');
codeAreaHL.setValue(code); codeAreaHL.setValue(code);
} catch (error) { } catch (error) {
codeAreaHL.setValue(String(error)); codeAreaHL.setValue(String(error));
@ -433,6 +437,7 @@ function omitedcheckUpdateFunction(event) {
} }
})(); })();
`; `;
/////////////////initscript end /////////////////////////////
var input_ = ''; var input_ = '';
editor_blockly.runOne = function () { editor_blockly.runOne = function () {

View File

@ -32,11 +32,7 @@ editor_file = function (editor, callback) {
editor_file.getFloorFileList = function (callback) { editor_file.getFloorFileList = function (callback) {
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
/* var fs = editor.fs; /* var fs = editor.fs;
fs.readdir('project/floors',function(err, data){ fs.readdir('project/floors',function(err, data){
callback([data,err]); callback([data,err]);
@ -46,22 +42,14 @@ editor_file = function (editor, callback) {
//callback([Array<String>,err:String]) //callback([Array<String>,err:String])
editor_file.loadFloorFile = function (filename, callback) { editor_file.loadFloorFile = function (filename, callback) {
//filename不含'/'不含'.js' //filename不含'/'不含'.js'
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
editor.currentFloorId = editor.core.status.floorId; editor.currentFloorId = editor.core.status.floorId;
editor.currentFloorData = editor.core.floors[editor.currentFloorId]; editor.currentFloorData = editor.core.floors[editor.currentFloorId];
} }
//callback(err:String) //callback(err:String)
editor_file.saveFloorFile = function (callback) { editor_file.saveFloorFile = function (callback) {
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
/* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) { /* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) {
callback('未选中文件或无数据'); callback('未选中文件或无数据');
} */ } */
@ -113,10 +101,7 @@ editor_file = function (editor, callback) {
//callback(err:String) //callback(err:String)
editor_file.saveNewFile = function (saveFilename, callback) { editor_file.saveNewFile = function (saveFilename, callback) {
//saveAsFilename不含'/'不含'.js' //saveAsFilename不含'/'不含'.js'
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
};
var currData=editor.currentFloorData; var currData=editor.currentFloorData;
var saveStatus = document.getElementById('newMapStatus').checked; var saveStatus = document.getElementById('newMapStatus').checked;
@ -163,10 +148,7 @@ editor_file = function (editor, callback) {
editor_file.saveFloorFile(callback); editor_file.saveFloorFile(callback);
} }
editor_file.saveNewFiles = function (floorIdList, from, to, callback) { editor_file.saveNewFiles = function (floorIdList, from, to, callback) {
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
};
var currData=editor.currentFloorData; var currData=editor.currentFloorData;
var saveStatus = document.getElementById('newMapsStatus').checked; var saveStatus = document.getElementById('newMapsStatus').checked;
@ -349,11 +331,7 @@ editor_file = function (editor, callback) {
} }
editor_file.changeIdAndIdnum = function (id, idnum, info, callback) { editor_file.changeIdAndIdnum = function (id, idnum, info, callback) {
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
//检查maps中是否有重复的idnum或id //检查maps中是否有重复的idnum或id
var change = -1; var change = -1;
for (var ii in editor.core.maps.blocksInfo) { for (var ii in editor.core.maps.blocksInfo) {
@ -428,11 +406,7 @@ editor_file = function (editor, callback) {
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) { actionList.forEach(function (value) {
var tempindex = value[1].indexOf(']') + 1; var tempindex = value[1].indexOf(']') + 1;
@ -475,11 +449,7 @@ editor_file = function (editor, callback) {
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) { actionList.forEach(function (value) {
value[1] = "['" + id + "']" + value[1]; value[1] = "['" + id + "']" + value[1];
@ -512,11 +482,7 @@ editor_file = function (editor, callback) {
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
var tempmap=[]; var tempmap=[];
for(var ii=0;ii<actionList.length;ii++){ for(var ii=0;ii<actionList.length;ii++){
@ -560,11 +526,7 @@ editor_file = function (editor, callback) {
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) { actionList.forEach(function (value) {
value[1] = value[1] + "['" + x + "," + y + "']"; value[1] = value[1] + "['" + x + "," + y + "']";
@ -600,11 +562,7 @@ editor_file = function (editor, callback) {
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
saveSetting('floors', actionList, function (err) { saveSetting('floors', actionList, function (err) {
callback([err]); callback([err]);
@ -643,11 +601,7 @@ editor_file = function (editor, callback) {
[]时只查询不修改 []时只查询不修改
*/ */
var data_obj = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d; var data_obj = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d;
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
saveSetting('data', actionList, function (err) { saveSetting('data', actionList, function (err) {
callback([err]); callback([err]);
@ -698,11 +652,7 @@ editor_file = function (editor, callback) {
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
saveSetting('functions', actionList, function (err) { saveSetting('functions', actionList, function (err) {
callback([err]); callback([err]);
@ -729,11 +679,7 @@ editor_file = function (editor, callback) {
[]时只查询不修改 []时只查询不修改
*/ */
var data_obj = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent; var data_obj = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent;
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) { actionList.forEach(function (value) {
value[1] = "['commonEvent']" + value[1]; value[1] = "['commonEvent']" + value[1];
@ -760,7 +706,7 @@ editor_file = function (editor, callback) {
return id_; return id_;
} else if(v===null){ } else if(v===null){
var id_ = editor.util.guid(); var id_ = editor.util.guid();
plmap[id_] = 'null'; plmap[id_] = null;
return id_; return id_;
} return v } return v
}, 4); }, 4);
@ -780,11 +726,7 @@ editor_file = function (editor, callback) {
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) { checkCallback(callback);
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) { if (isset(actionList) && actionList.length > 0) {
saveSetting('plugins', actionList, function (err) { saveSetting('plugins', actionList, function (err) {
callback([err]); callback([err]);
@ -811,6 +753,13 @@ editor_file = function (editor, callback) {
return true return true
} }
var checkCallback=function(callback){
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
}
var formatMap = function (mapArr,trySimplify) { var formatMap = function (mapArr,trySimplify) {
if(!mapArr || JSON.stringify(mapArr)==JSON.stringify([]))return ''; if(!mapArr || JSON.stringify(mapArr)==JSON.stringify([]))return '';
if(trySimplify){ if(trySimplify){

View File

@ -1,25 +1,45 @@
editor_game_wrapper = function (editor, main, core) { editor_game_wrapper = function (editor, main, core) {
// 原则上重构后只有此文件允许`\s(main|core)`形式的调用, 以及其初始化 editor_game_wrapper(editor, main, core)
editor_game = function () { 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) {
// 为了包含plugins的新建
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 () { editor_game.prototype.fixFunctionInGameData = function () {
core.floors = JSON.parse(JSON.stringify(core.floors, function (_k, v) { var rf = editor.game.replacerWithoutRecord
if (v instanceof Function) { core.floors = JSON.parse(JSON.stringify(core.floors, rf));
return v.toString() core.data = JSON.parse(JSON.stringify(core.data, rf));
} else return v data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = JSON.parse(JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, rf));
}));
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
}));
} }
editor_game.prototype.idsInit = function (maps, icons) { editor_game.prototype.idsInit = function (maps, icons) {
@ -118,7 +138,6 @@ editor_game_wrapper = function (editor, main, core) {
} }
} }
editor.constructor.prototype.game = new editor_game(); editor.constructor.prototype.game = new editor_game();
} }
//editor_game_wrapper(editor); //editor_game_wrapper(editor);

View File

@ -12,31 +12,31 @@ editor_table_wrapper = function (editor) {
values.map(function (v) { values.map(function (v) {
return editor.table.option(v) return editor.table.option(v)
}).join('') }).join('')
return `<select>\n${content}</select>\n` return /* html */`<select>\n${content}</select>\n`
} }
editor_table.prototype.option = function (value) { editor_table.prototype.option = function (value) {
return `<option value='${JSON.stringify(value)}'>${JSON.stringify(value)}</option>\n` return /* html */`<option value='${JSON.stringify(value)}'>${JSON.stringify(value)}</option>\n`
} }
editor_table.prototype.text = function (value) { editor_table.prototype.text = function (value) {
return `<input type='text' spellcheck='false' value='${JSON.stringify(value)}'/>\n` return /* html */`<input type='text' spellcheck='false' value='${JSON.stringify(value)}'/>\n`
} }
editor_table.prototype.checkbox = function (value) { editor_table.prototype.checkbox = function (value) {
return `<input type='checkbox' ${(value ? 'checked ' : '')}/>\n` return /* html */`<input type='checkbox' ${(value ? 'checked ' : '')}/>\n`
} }
editor_table.prototype.textarea = function (value, indent) { editor_table.prototype.textarea = function (value, indent) {
return `<textarea spellcheck='false'>${JSON.stringify(value, null, indent || 0)}</textarea>\n` return /* html */`<textarea spellcheck='false'>${JSON.stringify(value, null, indent || 0)}</textarea>\n`
} }
editor_table.prototype.title = function () { editor_table.prototype.title = function () {
return `\n<tr><td>条目</td><td>注释</td><td>值</td></tr>\n` return /* html */`\n<tr><td>条目</td><td>注释</td><td>值</td></tr>\n`
} }
editor_table.prototype.gap = function (field) { editor_table.prototype.gap = function (field) {
return `<tr><td>----</td><td>----</td><td>${field}</td></tr>\n` return /* html */`<tr><td>----</td><td>----</td><td>${field}</td></tr>\n`
} }
editor_table.prototype.tr = function (guid, field, shortField, commentHTMLescape, cobjstr, shortCommentHTMLescape, tdstr) { editor_table.prototype.tr = function (guid, field, shortField, commentHTMLescape, cobjstr, shortCommentHTMLescape, tdstr) {
return `<tr id="${guid}"> return /* html */`<tr id="${guid}">
<td title="${field}">${shortField}</td> <td title="${field}">${shortField}</td>
<td title="${commentHTMLescape}" cobj="${cobjstr}">${shortCommentHTMLescape}</td> <td title="${commentHTMLescape}" cobj="${cobjstr}">${shortCommentHTMLescape}</td>
<td><div class="etableInputDiv">${tdstr}</div></td> <td><div class="etableInputDiv">${tdstr}</div></td>

View File

@ -11,7 +11,7 @@
+ [ ] editor_multi 多行文本编辑器 + [ ] editor_multi 多行文本编辑器
+ [x] editor_table 处理表格的生成, 及其响应的事件, 从原editor\_mode中分离 + [x] editor_table 处理表格的生成, 及其响应的事件, 从原editor\_mode中分离
+ [ ] editor_file 调用fs.js编辑文件, 把原editor\_file模块化 + [ ] editor_file 调用fs.js编辑文件, 把原editor\_file模块化
+ [ ] editor_game 处理来自core的数据, 导入为editor的数据, 从原editor中分离 + [ ] editor_game 处理来自core的数据, 导入为editor的数据, 从原editor中分离. **只有此文件允许`\s(main|core)`形式的调用**(以及其初始化`editor_game_wrapper(editor, main, core);`)
+ [x] editor_util 生成guid等函数, 从editor分离 + [x] editor_util 生成guid等函数, 从editor分离
+ [ ] editor 执行初始化流程加组合各组件 + [ ] editor 执行初始化流程加组合各组件
+ [ ] 原editor_mode 移除 + [ ] 原editor_mode 移除
@ -51,7 +51,7 @@ editor: {
+ 地图的编辑与其他(如全塔属性和楼层属性), 现在的文件操作的模式是完全不同的 + 地图的编辑与其他(如全塔属性和楼层属性), 现在的文件操作的模式是完全不同的
楼层文件的储存与其他不同 楼层文件的储存与其他不同
+ editor.file在修改时不再返回obj和commentobj,只在查询时返回 + [x] editor.file在修改时不再返回obj和commentobj,只在查询时返回
+ editor.file中的各个条目, 非常相似, 但是细节的不同处理非常麻烦. 是类似的代码复制后修改一部分, 尝试模块化(或者重写) + editor.file中的各个条目, 非常相似, 但是细节的不同处理非常麻烦. 是类似的代码复制后修改一部分, 尝试模块化(或者重写)
@ -61,6 +61,8 @@ editor: {
+ 目前editor.map中储存的是info\<object\>, 准备改为和core一致只储存数字 + 目前editor.map中储存的是info\<object\>, 准备改为和core一致只储存数字
+ editor.widthX特别不直观
## 功能改进 ## 功能改进
+ [ ] 大地图 + [ ] 大地图
@ -103,6 +105,8 @@ editor: {
+ [ ] `显示文章`以及`选项`等方块, 把`标题`和`图像`从字符串提取出填回相应的空 + [ ] `显示文章`以及`选项`等方块, 把`标题`和`图像`从字符串提取出填回相应的空
+ [ ] blockly中某些需要选点的填空, 增加按钮, 点击后从缩略图中点击位置
## 左侧页面模式 ## 左侧页面模式
标题? 保存按钮? 添加按钮? 删除按钮? 标题? 保存按钮? 添加按钮? 删除按钮?

View File

@ -523,8 +523,8 @@
<!-- <script src='_server/vendor/polyfill.min.js'></script> --> <!-- <script src='_server/vendor/polyfill.min.js'></script> -->
<script src='_server/fs.js'></script> <script src='_server/fs.js'></script>
<script src='_server/editor_util.js'></script> <script src='_server/editor_util.js'></script>
<script src='_server/editor_file.js'></script>
<script src='_server/editor_game.js'></script> <script src='_server/editor_game.js'></script>
<script src='_server/editor_file.js'></script>
<script src='_server/editor_table.js'></script> <script src='_server/editor_table.js'></script>
<script src='_server/editor_mode.js'></script> <script src='_server/editor_mode.js'></script>
<script src='_server/editor_unsorted_1.js'></script> <script src='_server/editor_unsorted_1.js'></script>

View File

@ -506,8 +506,8 @@
<!-- <script src='_server/vendor/polyfill.min.js'></script> --> <!-- <script src='_server/vendor/polyfill.min.js'></script> -->
<script src='_server/fs.js'></script> <script src='_server/fs.js'></script>
<script src='_server/editor_util.js'></script> <script src='_server/editor_util.js'></script>
<script src='_server/editor_file.js'></script>
<script src='_server/editor_game.js'></script> <script src='_server/editor_game.js'></script>
<script src='_server/editor_file.js'></script>
<script src='_server/editor_table.js'></script> <script src='_server/editor_table.js'></script>
<script src='_server/editor_mode.js'></script> <script src='_server/editor_mode.js'></script>
<script src='_server/editor_unsorted_1.js'></script> <script src='_server/editor_unsorted_1.js'></script>