diff --git a/_server/config.json b/_server/config.json new file mode 100644 index 00000000..8ef9802a --- /dev/null +++ b/_server/config.json @@ -0,0 +1 @@ +{"lastUsed":[],"foldPerCol":50,"folded":false} \ No newline at end of file diff --git a/_server/editor.js b/_server/editor.js index 8cec0a7d..7ddc0f60 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -151,17 +151,20 @@ editor.prototype.init = function (callback) { editor.airwallImg.src = './project/images/airwall.png'; main.init('editor', function () { - editor_util_wrapper(editor); - editor_game_wrapper(editor, main, core); - editor_file_wrapper(editor); - editor_table_wrapper(editor); - editor_ui_wrapper(editor); - editor_mappanel_wrapper(editor); - editor_datapanel_wrapper(editor); - editor_materialpanel_wrapper(editor); - editor_listen_wrapper(editor); - editor.printe=printe; - afterMainInit(); + editor.config = new editor_config(); + editor.config.load(function() { + editor_util_wrapper(editor); + editor_game_wrapper(editor, main, core); + editor_file_wrapper(editor); + editor_table_wrapper(editor); + editor_ui_wrapper(editor); + editor_mappanel_wrapper(editor); + editor_datapanel_wrapper(editor); + editor_materialpanel_wrapper(editor); + editor_listen_wrapper(editor); + editor.printe=printe; + afterMainInit(); + }) }); var afterMainInit = function () { @@ -174,7 +177,7 @@ editor.prototype.init = function (callback) { editor_mode = editor_mode(editor); editor.mode = editor_mode; core.resetGame(core.firstData.hero, null, core.firstData.floorId, core.clone(core.initStatus.maps)); - var lastFloorId = core.getLocalStorage('editorLastFloorId', core.status.floorId); + var lastFloorId = editor.config.get('editorLastFloorId', core.status.floorId); if (core.floorIds.indexOf(lastFloorId) < 0) lastFloorId = core.status.floorId; core.changeFloor(lastFloorId, null, core.firstData.hero.loc, null, function () { afterCoreReset(); @@ -274,8 +277,9 @@ editor.prototype.changeFloor = function (floorId, callback) { var loc = editor.viewportLoc[floorId] || [], x = loc[0] || 0, y = loc[1] || 0; editor.setViewport(x, y); - core.setLocalStorage('editorLastFloorId', floorId); - if (callback) callback(); + editor.config.set('editorLastFloorId', floorId, function() { + if (callback) callback(); + }); }); } @@ -448,11 +452,11 @@ editor.prototype.drawInitData = function (icons) { var maxHeight = 700; var sumWidth = 0; editor.widthsX = {}; - editor.uivalues.folded = core.getLocalStorage('folded', false); + editor.uivalues.folded = editor.config.get('folded', false); // editor.uivalues.folded = true; - editor.uivalues.foldPerCol = core.getLocalStorage('foldPerCol', 50); + editor.uivalues.foldPerCol = editor.config.get('foldPerCol', 50); // var imgNames = Object.keys(images); //还是固定顺序吧; - editor.uivalues.lastUsed = core.getLocalStorage("lastUsed", []); + editor.uivalues.lastUsed = editor.config.get("lastUsed", []); var imgNames = ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48", "autotile"]; for (var ii = 0; ii < imgNames.length; ii++) { diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 090ba314..aa221608 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -492,13 +492,13 @@ function omitedcheckUpdateFunction(event) { `; /////////////////initscript end ///////////////////////////// - editor.uivalues.disableBlocklyReplace = core.getLocalStorage("disableBlocklyReplace", false); + editor.uivalues.disableBlocklyReplace = editor.config.get("disableBlocklyReplace", false); var replaceCheckbox = document.getElementById('blocklyReplace'); replaceCheckbox.checked = !editor.uivalues.disableBlocklyReplace; editor_blockly.triggerReplace = function () { editor.uivalues.disableBlocklyReplace = !replaceCheckbox.checked; - core.setLocalStorage("disableBlocklyReplace", !replaceCheckbox.checked); + editor.config.set("disableBlocklyReplace", !replaceCheckbox.checked); if (MotaActionFunctions) MotaActionFunctions.disableReplace = !replaceCheckbox.checked; alert("已" + (replaceCheckbox.checked ? "开启" : "关闭") + "中文变量名替换!\n关闭并重开事件编辑器以生效。"); } diff --git a/_server/editor_config.js b/_server/editor_config.js new file mode 100644 index 00000000..016b316c --- /dev/null +++ b/_server/editor_config.js @@ -0,0 +1,34 @@ +function editor_config() { + this.address = "_server/config.json"; +} + +editor_config.prototype.load = function(callback) { + var _this = this; + fs.readFile(this.address, "utf-8", function(e, d) { + if (e) { + console.warn("无法读取配置文件, 已重新生成"); + _this.config = {}; + _this.save(callback); + } else { + _this.config = JSON.parse(d); + if (callback) callback(); + } + }); +} + +editor_config.prototype.get = function(key, defaultValue) { + value = this.config[key]; + return value != null ? value : defaultValue; +} + +editor_config.prototype.set = function(key, value, callback) { + this.config[key] = value; + if (callback !== false) this.save(callback); +} + +editor_config.prototype.save = function(callback) { + fs.writeFile(this.address, JSON.stringify(this.config) ,'utf-8', function(e) { + if (e) alert("写入配置文件失败"); + if (callback instanceof Function) callback(); + }) +} diff --git a/_server/editor_listen.js b/_server/editor_listen.js index 970111b7..31825aa5 100644 --- a/_server/editor_listen.js +++ b/_server/editor_listen.js @@ -15,7 +15,7 @@ editor_listen_wrapper = function (editor) { editor.dom.mid.onmousewheel = editor.uifunctions.map_mousewheel - editor.uivalues.shortcut = core.getLocalStorage('shortcut', { 48: 0, 49: 0, 50: 0, 51: 0, 52: 0, 53: 0, 54: 0, 55: 0, 56: 0, 57: 0 }); + editor.uivalues.shortcut = editor.config.get('shortcut', { 48: 0, 49: 0, 50: 0, 51: 0, 52: 0, 53: 0, 54: 0, 55: 0, 56: 0, 57: 0 }); editor.dom.body.onkeydown = editor.uifunctions.body_shortcut editor.uivalues.scrollBarHeight = editor.uifunctions.getScrollBarHeight(); diff --git a/_server/editor_mappanel.js b/_server/editor_mappanel.js index d4546c44..9068eff9 100644 --- a/_server/editor_mappanel.js +++ b/_server/editor_mappanel.js @@ -253,7 +253,7 @@ editor_mappanel_wrapper = function (editor) { // console.log(editor.map); if (editor.info.y != null) { editor.uivalues.lastUsed = [editor.info].concat(editor.uivalues.lastUsed.filter(function (e) { return e.id != editor.info.id})); - core.setLocalStorage("lastUsed", editor.uivalues.lastUsed); + editor.config.set("lastUsed", editor.uivalues.lastUsed); } editor.updateMap(); editor.uivalues.holdingPath = 0; @@ -601,9 +601,9 @@ editor_mappanel_wrapper = function (editor) { * 切换画笔模式 */ editor.uifunctions.brushMod3_onchange = function () { - if (!core.getLocalStorage('alertTileMode') && + if (!editor.config.get('alertTileMode') && !confirm("从V2.6.6开始,tileset贴图模式已被废弃。\n请右键额外素材,并输入所需要绘制的宽高,然后单击地图以绘制一个区域。\n\n点取消将不再显示此提示。")) { - core.setLocalStorage('alertTileMode', true); + editor.config.set('alertTileMode', true); } // tip.showHelp(5) tip.isSelectedBlock(false) diff --git a/_server/editor_materialpanel.js b/_server/editor_materialpanel.js index 6b81cf1e..ea7dcced 100644 --- a/_server/editor_materialpanel.js +++ b/_server/editor_materialpanel.js @@ -31,15 +31,17 @@ editor_materialpanel_wrapper = function (editor) { editor.uifunctions.fold_material_click = function () { if (editor.uivalues.folded) { if (confirm("你想要展开素材吗?\n展开模式下将显示全素材内容。")) { - core.setLocalStorage('folded', false); - window.location.reload(); + editor.config.set('folded', false, function() { + window.location.reload(); + }); } } else { var perCol = parseInt(prompt("请输入折叠素材模式下每列的个数:", "50")) || 0; if (perCol > 0) { - core.setLocalStorage('foldPerCol', perCol); - core.setLocalStorage('folded', true); - window.location.reload(); + editor.config.set('foldPerCol', perCol, false); + editor.config.set('folded', false, function() { + window.location.reload(); + }); } } } diff --git a/_server/editor_ui.js b/_server/editor_ui.js index cadd3b2f..4a5e4386 100644 --- a/_server/editor_ui.js +++ b/_server/editor_ui.js @@ -219,7 +219,7 @@ editor_ui_wrapper = function (editor) { if (infoToSave == JSON.stringify({})) return; editor.uivalues.shortcut[e.keyCode] = JSON.parse(infoToSave); printf('已保存该快捷图块, 数字键 ' + (e.keyCode - 48) + ' 使用.') - core.setLocalStorage('shortcut', editor.uivalues.shortcut); + editor.config.set('shortcut', editor.uivalues.shortcut); return; } //ctrl + 0~9 切换到快捷图块 diff --git a/editor-mobile.html b/editor-mobile.html index 6946dedf..45fe1dce 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -584,6 +584,7 @@ + diff --git a/editor.html b/editor.html index 95ab78f7..0e26d46f 100644 --- a/editor.html +++ b/editor.html @@ -568,6 +568,7 @@ +