diff --git a/_server/editor_file.js b/_server/editor_file.js index 89b7f6c5..e074a1d5 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -941,11 +941,7 @@ editor_file = function (editor, callback) { return formatArrStr; } - var encode = function (str) { - return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { - return String.fromCharCode(parseInt(p1, 16)) - })) - } + var encode = editor.util.encode64 var alertWhenCompress = function(){ if(editor.useCompress===true){ diff --git a/_server/editor_multi.js b/_server/editor_multi.js index 9ccd00c9..e68cf56a 100644 --- a/_server/editor_multi.js +++ b/_server/editor_multi.js @@ -11,14 +11,14 @@ editor_multi = function () { tabSize: 4, indentWithTabs: true, smartIndent: true, - mode: {name: "javascript", globalVars: true, localVars: true}, + mode: { name: "javascript", globalVars: true, localVars: true }, lineWrapping: true, continueComments: "Enter", gutters: ["CodeMirror-lint-markers"], lint: true, autocomplete: true, autoCloseBrackets: true, - highlightSelectionMatches: {showToken: /\w/, annotateScrollbar: true} + highlightSelectionMatches: { showToken: /\w/, annotateScrollbar: true } }); editor_multi.codeEditor = codeEditor; @@ -26,9 +26,9 @@ editor_multi = function () { codeEditor.on("keyup", function (cm, event) { if (codeEditor.getOption("autocomplete") && !event.ctrlKey && ( (event.keyCode >= 65 && event.keyCode <= 90) || - (!event.shiftKey && event.keyCode == 190) || (event.shiftKey && event.keyCode == 189))){ + (!event.shiftKey && event.keyCode == 190) || (event.shiftKey && event.keyCode == 189))) { try { - CodeMirror.commands.autocomplete(cm, null, {completeSingle: false}); + CodeMirror.commands.autocomplete(cm, null, { completeSingle: false }); } catch (e) { } } @@ -39,7 +39,7 @@ editor_multi = function () { editor_multi.lintAutocomplete = false; editor_multi.show = function () { - if (typeof(selectBox) !== typeof(undefined)) selectBox.isSelected(false); + if (typeof (selectBox) !== typeof (undefined)) selectBox.isSelected(false); var valueNow = codeEditor.getValue(); //try{eval('function _asdygakufyg_() { return '+valueNow+'\n}');editor_multi.lintAutocomplete=true;}catch(ee){} if (valueNow.slice(0, 8) === 'function') editor_multi.lintAutocomplete = true; @@ -60,7 +60,7 @@ editor_multi = function () { } editor_multi.indent = function (field) { - if (typeof(editor) !== typeof(undefined) && editor && editor.mode && editor.mode.indent) return editor.mode.indent(field); + if (typeof (editor) !== typeof (undefined) && editor && editor.mode && editor.mode.indent) return editor.mode.indent(field); return '\t'; } @@ -102,7 +102,7 @@ editor_multi = function () { eval('var tobj=' + (input.value || 'null')); var tmap = {}; var tstr = JSON.stringify(tobj, function (k, v) { - if (typeof(v) === typeof('') && v.slice(0, 8) === 'function') { + if (typeof (v) === typeof ('') && v.slice(0, 8) === 'function') { var id_ = editor.util.guid(); tmap[id_] = v.toString(); return id_; @@ -128,13 +128,21 @@ editor_multi = function () { editor_multi.id = ''; return; } - // ----- 自动格式化 - _format(); + if (editor_multi.id === 'callFromBlockly') { + // ----- 自动格式化 + _format(); editor_multi.id = ''; editor_multi.multiLineDone(); return; } + + if (editor_multi.id === 'importFile') { + editor_multi.id = ''; + editor_multi.writeFileDone(); + return; + } + var setvalue = function (value) { var thisTr = document.getElementById(editor_multi.id); editor_multi.id = ''; @@ -159,6 +167,8 @@ editor_multi = function () { editor_multi.hide(); input.onchange(); } + // ----- 自动格式化 + _format(); setvalue(codeEditor.getValue() || ''); } @@ -179,6 +189,46 @@ editor_multi = function () { multiLineArgs[2](newvalue, multiLineArgs[0], multiLineArgs[1]) } + var _fileValues = [''] + editor_multi.importFile = function (filename) { + editor_multi.id = 'importFile' + _fileValues[0] = filename + codeEditor.setValue('loading') + editor_multi.show(); + fs.readFile(filename, 'base64', function (e, d) { + if (e) { + codeEditor.setValue('加载文件失败:\n' + e) + editor_multi.id = '' + return; + } + var str = editor.util.decode64(d) + codeEditor.setValue(str) + _fileValues[1] = str + }) + } + + editor_multi.writeFileDone = function () { + fs.writeFile(_fileValues[0], editor.util.encode64(codeEditor.getValue() || ''), 'base64', function (err, data) { + if (err) printe('文件写入失败,请手动粘贴至' + _fileValues[0] + '\n' + err); + else editor_multi.hide(); + }); + } + + editor_multi.editCommentJs = function (mod) { + var dict = { + loc: '_server/comment.js', + enemyitem: '_server/comment.js', + floor: '_server/comment.js', + tower: '_server/data.comment.js', + functions: '_server/functions.comment.js', + commonevent: '_server/events.comment.js', + plugins: '_server/plugins.comment.js', + } + editor_multi.lintAutocomplete = true + editor_multi.setLint() + editor_multi.importFile(dict[mod]) + } + return editor_multi; } //editor_multi=editor_multi(); \ No newline at end of file diff --git a/_server/editor_util.js b/_server/editor_util.js index bab29837..83b745a5 100644 --- a/_server/editor_util.js +++ b/_server/editor_util.js @@ -59,7 +59,7 @@ editor_util_wrapper = function (editor) { // SOFTWARE. //-------------------------------------------- // https://github.com/carloscabo/colz/blob/master/public/js/colz.class.js - var round=Math.round; + var round = Math.round; var rgbToHsl = function (rgba) { var arg, r, g, b, h, s, l, d, max, min; @@ -141,9 +141,21 @@ editor_util_wrapper = function (editor) { } return [round(r * 255), round(g * 255), round(b * 255)]; } - editor_util.prototype.rgbToHsl=rgbToHsl - editor_util.prototype.hue2rgb=hue2rgb - editor_util.prototype.hslToRgb=hslToRgb + editor_util.prototype.rgbToHsl = rgbToHsl + editor_util.prototype.hue2rgb = hue2rgb + editor_util.prototype.hslToRgb = hslToRgb + + editor_util.prototype.encode64 = function (str) { + return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { + return String.fromCharCode(parseInt(p1, 16)) + })) + } + + editor_util.prototype.decode64 = function (str) { + return decodeURIComponent(atob(str.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, '')).split('').map(function (c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2) + }).join('')) + } editor.constructor.prototype.util = new editor_util(); } diff --git a/_server/refactoring.md b/_server/refactoring.md index 55b02bfe..c75dc64b 100644 --- a/_server/refactoring.md +++ b/_server/refactoring.md @@ -85,7 +85,7 @@ editor: { + [ ] 画地图也自动保存 -+ [ ] 修改系统的触发器(下拉菜单增加新项) ++ [x] 修改系统的触发器(下拉菜单增加新项) 在编辑器修改`comment.js`:现场发readFile请求读文件,然后开脚本编辑器进行编辑 + [ ] ? 删除注册项/修改图块ID diff --git a/editor-mobile.html b/editor-mobile.html index ebcc334c..e77a286f 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -97,7 +97,7 @@
-

地图选点   +

地图选点    

0,0

@@ -115,7 +115,7 @@
-

图块属性       +

图块属性        

@@ -141,7 +141,7 @@
-

楼层属性       +

楼层属性        

@@ -158,7 +158,7 @@
-

全塔属性     +

全塔属性      

@@ -226,7 +226,7 @@
-

脚本编辑   +

脚本编辑    

@@ -243,7 +243,7 @@
-

公共事件       +

公共事件        

@@ -260,7 +260,7 @@
-

插件编写       +

插件编写        

diff --git a/editor.html b/editor.html index 0b5c4187..58ea0a1c 100644 --- a/editor.html +++ b/editor.html @@ -93,7 +93,7 @@
-

地图选点   +

地图选点    

0,0

@@ -111,7 +111,7 @@
-

图块属性       +

图块属性        

@@ -137,7 +137,7 @@
-

楼层属性       +

楼层属性        

@@ -154,7 +154,7 @@
-

全塔属性     +

全塔属性      

@@ -222,7 +222,7 @@
-

脚本编辑   +

脚本编辑    

@@ -239,7 +239,7 @@
-

公共事件       +

公共事件        

@@ -256,7 +256,7 @@
-

插件编写       +

插件编写