Skip to content

Commit 918140f

Browse files
committed
config.json
1 parent 4e648a0 commit 918140f

10 files changed

+72
-29
lines changed

_server/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"lastUsed":[],"foldPerCol":50,"folded":false}

_server/editor.js

+21-17
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,20 @@ editor.prototype.init = function (callback) {
151151
editor.airwallImg.src = './project/images/airwall.png';
152152

153153
main.init('editor', function () {
154-
editor_util_wrapper(editor);
155-
editor_game_wrapper(editor, main, core);
156-
editor_file_wrapper(editor);
157-
editor_table_wrapper(editor);
158-
editor_ui_wrapper(editor);
159-
editor_mappanel_wrapper(editor);
160-
editor_datapanel_wrapper(editor);
161-
editor_materialpanel_wrapper(editor);
162-
editor_listen_wrapper(editor);
163-
editor.printe=printe;
164-
afterMainInit();
154+
editor.config = new editor_config();
155+
editor.config.load(function() {
156+
editor_util_wrapper(editor);
157+
editor_game_wrapper(editor, main, core);
158+
editor_file_wrapper(editor);
159+
editor_table_wrapper(editor);
160+
editor_ui_wrapper(editor);
161+
editor_mappanel_wrapper(editor);
162+
editor_datapanel_wrapper(editor);
163+
editor_materialpanel_wrapper(editor);
164+
editor_listen_wrapper(editor);
165+
editor.printe=printe;
166+
afterMainInit();
167+
})
165168
});
166169

167170
var afterMainInit = function () {
@@ -174,7 +177,7 @@ editor.prototype.init = function (callback) {
174177
editor_mode = editor_mode(editor);
175178
editor.mode = editor_mode;
176179
core.resetGame(core.firstData.hero, null, core.firstData.floorId, core.clone(core.initStatus.maps));
177-
var lastFloorId = core.getLocalStorage('editorLastFloorId', core.status.floorId);
180+
var lastFloorId = editor.config.get('editorLastFloorId', core.status.floorId);
178181
if (core.floorIds.indexOf(lastFloorId) < 0) lastFloorId = core.status.floorId;
179182
core.changeFloor(lastFloorId, null, core.firstData.hero.loc, null, function () {
180183
afterCoreReset();
@@ -274,8 +277,9 @@ editor.prototype.changeFloor = function (floorId, callback) {
274277
var loc = editor.viewportLoc[floorId] || [], x = loc[0] || 0, y = loc[1] || 0;
275278
editor.setViewport(x, y);
276279

277-
core.setLocalStorage('editorLastFloorId', floorId);
278-
if (callback) callback();
280+
editor.config.set('editorLastFloorId', floorId, function() {
281+
if (callback) callback();
282+
});
279283
});
280284
}
281285

@@ -448,11 +452,11 @@ editor.prototype.drawInitData = function (icons) {
448452
var maxHeight = 700;
449453
var sumWidth = 0;
450454
editor.widthsX = {};
451-
editor.uivalues.folded = core.getLocalStorage('folded', false);
455+
editor.uivalues.folded = editor.config.get('folded', false);
452456
// editor.uivalues.folded = true;
453-
editor.uivalues.foldPerCol = core.getLocalStorage('foldPerCol', 50);
457+
editor.uivalues.foldPerCol = editor.config.get('foldPerCol', 50);
454458
// var imgNames = Object.keys(images); //还是固定顺序吧;
455-
editor.uivalues.lastUsed = core.getLocalStorage("lastUsed", []);
459+
editor.uivalues.lastUsed = editor.config.get("lastUsed", []);
456460
var imgNames = ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48", "autotile"];
457461

458462
for (var ii = 0; ii < imgNames.length; ii++) {

_server/editor_blockly.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,13 @@ function omitedcheckUpdateFunction(event) {
492492
`;
493493
/////////////////initscript end /////////////////////////////
494494

495-
editor.uivalues.disableBlocklyReplace = core.getLocalStorage("disableBlocklyReplace", false);
495+
editor.uivalues.disableBlocklyReplace = editor.config.get("disableBlocklyReplace", false);
496496
var replaceCheckbox = document.getElementById('blocklyReplace');
497497
replaceCheckbox.checked = !editor.uivalues.disableBlocklyReplace;
498498

499499
editor_blockly.triggerReplace = function () {
500500
editor.uivalues.disableBlocklyReplace = !replaceCheckbox.checked;
501-
core.setLocalStorage("disableBlocklyReplace", !replaceCheckbox.checked);
501+
editor.config.set("disableBlocklyReplace", !replaceCheckbox.checked);
502502
if (MotaActionFunctions) MotaActionFunctions.disableReplace = !replaceCheckbox.checked;
503503
alert("已" + (replaceCheckbox.checked ? "开启" : "关闭") + "中文变量名替换!\n关闭并重开事件编辑器以生效。");
504504
}

_server/editor_config.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function editor_config() {
2+
this.address = "_server/config.json";
3+
}
4+
5+
editor_config.prototype.load = function(callback) {
6+
var _this = this;
7+
fs.readFile(this.address, "utf-8", function(e, d) {
8+
if (e) {
9+
console.warn("无法读取配置文件, 已重新生成");
10+
_this.config = {};
11+
_this.save(callback);
12+
} else {
13+
_this.config = JSON.parse(d);
14+
if (callback) callback();
15+
}
16+
});
17+
}
18+
19+
editor_config.prototype.get = function(key, defaultValue) {
20+
value = this.config[key];
21+
return value != null ? value : defaultValue;
22+
}
23+
24+
editor_config.prototype.set = function(key, value, callback) {
25+
this.config[key] = value;
26+
if (callback !== false) this.save(callback);
27+
}
28+
29+
editor_config.prototype.save = function(callback) {
30+
fs.writeFile(this.address, JSON.stringify(this.config) ,'utf-8', function(e) {
31+
if (e) alert("写入配置文件失败");
32+
if (callback instanceof Function) callback();
33+
})
34+
}

_server/editor_listen.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ editor_listen_wrapper = function (editor) {
1515

1616
editor.dom.mid.onmousewheel = editor.uifunctions.map_mousewheel
1717

18-
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 });
18+
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 });
1919
editor.dom.body.onkeydown = editor.uifunctions.body_shortcut
2020

2121
editor.uivalues.scrollBarHeight = editor.uifunctions.getScrollBarHeight();

_server/editor_mappanel.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ editor_mappanel_wrapper = function (editor) {
253253
// console.log(editor.map);
254254
if (editor.info.y != null) {
255255
editor.uivalues.lastUsed = [editor.info].concat(editor.uivalues.lastUsed.filter(function (e) { return e.id != editor.info.id}));
256-
core.setLocalStorage("lastUsed", editor.uivalues.lastUsed);
256+
editor.config.set("lastUsed", editor.uivalues.lastUsed);
257257
}
258258
editor.updateMap();
259259
editor.uivalues.holdingPath = 0;
@@ -601,9 +601,9 @@ editor_mappanel_wrapper = function (editor) {
601601
* 切换画笔模式
602602
*/
603603
editor.uifunctions.brushMod3_onchange = function () {
604-
if (!core.getLocalStorage('alertTileMode') &&
604+
if (!editor.config.get('alertTileMode') &&
605605
!confirm("从V2.6.6开始,tileset贴图模式已被废弃。\n请右键额外素材,并输入所需要绘制的宽高,然后单击地图以绘制一个区域。\n\n点取消将不再显示此提示。")) {
606-
core.setLocalStorage('alertTileMode', true);
606+
editor.config.set('alertTileMode', true);
607607
}
608608
// tip.showHelp(5)
609609
tip.isSelectedBlock(false)

_server/editor_materialpanel.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ editor_materialpanel_wrapper = function (editor) {
3131
editor.uifunctions.fold_material_click = function () {
3232
if (editor.uivalues.folded) {
3333
if (confirm("你想要展开素材吗?\n展开模式下将显示全素材内容。")) {
34-
core.setLocalStorage('folded', false);
35-
window.location.reload();
34+
editor.config.set('folded', false, function() {
35+
window.location.reload();
36+
});
3637
}
3738
} else {
3839
var perCol = parseInt(prompt("请输入折叠素材模式下每列的个数:", "50")) || 0;
3940
if (perCol > 0) {
40-
core.setLocalStorage('foldPerCol', perCol);
41-
core.setLocalStorage('folded', true);
42-
window.location.reload();
41+
editor.config.set('foldPerCol', perCol, false);
42+
editor.config.set('folded', false, function() {
43+
window.location.reload();
44+
});
4345
}
4446
}
4547
}

_server/editor_ui.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ editor_ui_wrapper = function (editor) {
219219
if (infoToSave == JSON.stringify({})) return;
220220
editor.uivalues.shortcut[e.keyCode] = JSON.parse(infoToSave);
221221
printf('已保存该快捷图块, 数字键 ' + (e.keyCode - 48) + ' 使用.')
222-
core.setLocalStorage('shortcut', editor.uivalues.shortcut);
222+
editor.config.set('shortcut', editor.uivalues.shortcut);
223223
return;
224224
}
225225
//ctrl + 0~9 切换到快捷图块

editor-mobile.html

+1
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ <h3 class="leftTabHeader">插件编写&nbsp;&nbsp;<button onclick="editor.mode.o
584584
<!-- <script src="https://cdn.bootcss.com/vue/2.5.13/vue.js"></script> -->
585585
<!-- <script src='_server/vendor/polyfill.min.js'></script> -->
586586
<script src='_server/fs.js'></script>
587+
<script src='_server/editor_config.js'></script>
587588
<script src='_server/editor_util.js'></script>
588589
<script src='_server/editor_game.js'></script>
589590
<script src='_server/editor_file.js'></script>

editor.html

+1
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ <h3 class="leftTabHeader">插件编写&nbsp;&nbsp;<button onclick="editor.mode.o
568568
<!-- <script src="https://cdn.bootcss.com/vue/2.5.13/vue.js"></script> -->
569569
<!-- <script src='_server/vendor/polyfill.min.js'></script> -->
570570
<script src='_server/fs.js'></script>
571+
<script src='_server/editor_config.js'></script>
571572
<script src='_server/editor_util.js'></script>
572573
<script src='_server/editor_game.js'></script>
573574
<script src='_server/editor_file.js'></script>

0 commit comments

Comments
 (0)