From e11085f26f5e12fc454361f86cf536e08cac2444 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 31 Jul 2020 16:03:48 +0800 Subject: [PATCH] Fix tiny bugs --- _docs/api.md | 15 +++++++++++++++ _server/CodeMirror/defs.js | 20 ++++++++++++++++++++ extensions/dynamicMapEditor.js | 2 ++ libs/control.js | 32 ++++++++++++++++++++++++++++++-- libs/maps.js | 2 +- runtime.d.ts | 15 +++++++++++++++ 6 files changed, 83 insertions(+), 3 deletions(-) diff --git a/_docs/api.md b/_docs/api.md index 5f4c0ec2..c0f59e31 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -261,6 +261,9 @@ addStatus: fn(name: string, value: number) name: 属性的英文名 value: 属性的增量 +addSwitch: fn(x: number, y: number, floorId?: string, name: string, value: number) +增加某个独立开关的值 + autosave: fn(removeLast?: bool) 自动存档 @@ -379,6 +382,9 @@ getStatusLabel: fn(name: string) -> string getStatusOrDefault: fn(status?: ?, name?: string) 从status中获得属性,如果不存在则从勇士属性中获取 +getSwitch: fn(x: number, y: number, floorId?: string, name: string, defaultValue?: ?) +获得某个独立开关的值 + hasFlag: fn(name: string) -> bool 判定一个flag变量是否存在且不为false、0、''、null、undefined和NaN 例如:core.hasFlag('poison'); // 判断主角当前是否中毒 @@ -388,6 +394,9 @@ name: 变量名,支持中文 hasSave: fn(index?: number) -> bool 判断某个存档位是否存在存档 +hasSwitch: fn(x: number, y: number, floorId?: string, name: string) -> bool +判定某个独立开关的值 + hideStartAnimate: fn(callback?: fn()) 淡出标题画面 例如:core.hideStartAnimate(core.startGame); // 淡出标题画面并开始新游戏,跳过难度选择 @@ -490,6 +499,9 @@ removeFlag: fn(name: string) removeSave: fn(index?: number, callback?: fn()) 删除某个存档 +removeSwitch: fn(x: number, y: number, floorId?: string, name: string) +删除某个独立开关 + replay: fn() 回放下一个操作 @@ -579,6 +591,9 @@ setStatus: fn(name: string, value: number) name: 属性的英文名,其中'x'、'y'和'direction'会被特殊处理为 core.setHeroLoc(name, value),其他的会直接对 core.status.hero[name] 赋值 value: 属性的新值 +setSwitch: fn(x: number, y: number, floorId?: string, name: string, value?: ?) +设置某个独立开关的值 + setToolbarButton: fn(useButton?: bool) 改变工具栏为按钮1-8 diff --git a/_server/CodeMirror/defs.js b/_server/CodeMirror/defs.js index 9a1954e1..84897a22 100644 --- a/_server/CodeMirror/defs.js +++ b/_server/CodeMirror/defs.js @@ -2571,6 +2571,26 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [ "checkRouteFolding": { "!doc": "检查录像折叠信息", "!type": "fn()" + }, + "setSwitch": { + "!doc": "设置某个独立开关", + "!type": "fn(x: number, y: number, floorId?: string, name: string, value: ?)" + }, + "getSwitch": { + "!doc": "获得某个独立开关", + "!type": "fn(x: number, y: number, floorId?: string, name: string, defaultValue?: ?)" + }, + "addSwitch": { + "!doc": "增加某个独立开关", + "!type": "fn(x: number, y: number, floorId?: string, name: string, value: number)" + }, + "removeSwitch": { + "!doc": "删除某个独立开关", + "!type": "fn(x: number, y: number, floorId?: string, name: string)" + }, + "removeSwitch": { + "!doc": "判定某个独立开关", + "!type": "fn(x: number, y: number, floorId?: string, name: string) -> bool" } }, "icons": { diff --git a/extensions/dynamicMapEditor.js b/extensions/dynamicMapEditor.js index b4327a88..21489faa 100644 --- a/extensions/dynamicMapEditor.js +++ b/extensions/dynamicMapEditor.js @@ -108,6 +108,8 @@ dynamicMapEditor.prototype.onKeyUp = function(e) { dynamicMapEditor.prototype.onMapClick = function(x, y) { if (!this.isValid()) return false; if (!this.isUsingTool || !this.selectedItem) return false; + x += parseInt(core.bigmap.offsetX / 32); + y += parseInt(core.bigmap.offsetY / 32); var number = this.selectedItem.number; this.addOperation('put', number, x, y, core.status.floorId); return true; diff --git a/libs/control.js b/libs/control.js index 3a8da3c3..02027175 100644 --- a/libs/control.js +++ b/libs/control.js @@ -2251,8 +2251,6 @@ control.prototype.getHeroLoc = function (name) { return core.status.hero.loc[name]; } - - ////// 获得某个等级的名称 ////// control.prototype.getLvName = function (lv) { if (!core.status.hero) return null; @@ -2291,6 +2289,36 @@ control.prototype.removeFlag = function(name) { delete core.status.hero.flags[name]; } +////// 获得某个点的独立开关 ////// +control.prototype.getSwitch = function (x, y, floorId, name, defaultValue) { + var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@"); + return this.getFlag(prefix + "@" + name, defaultValue); +} + +////// 设置某个点的独立开关 ////// +control.prototype.setSwitch = function (x, y, floorId, name, value) { + var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@"); + return this.setFlag(prefix + "@" + name, value); +} + +////// 增加某个点的独立开关 ////// +control.prototype.addSwitch = function (x, y, floorId, name, value) { + var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@"); + return this.addFlag(prefix + "@" + name, value); +} + +////// 判定某个点的独立开关 ////// +control.prototype.hasSwitch = function (x, y, floorId, name) { + var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@"); + return this.hasFlag(prefix + "@" + name); +} + +////// 删除某个点的独立开关 ////// +control.prototype.removeSwitch = function (x, y, floorId, name) { + var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@"); + return this.removeFlag(prefix + "@" + name); +} + ////// 锁定状态栏,常常用于事件处理 ////// control.prototype.lockControl = function () { core.status.lockControl = true; diff --git a/libs/maps.js b/libs/maps.js index b0a98ac3..3a2a69b3 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -113,7 +113,7 @@ maps.prototype.extractBlocksForUI = function (map, flags) { for (var j = 0; j < mw; j++) { var number = (decompressed[i] || [])[j] || 0; if (!number || number == 17 || this.isMapBlockDisabled(floorId, j, i, flags)) continue; - map.blocks.push(this.initBlock(j, i, number)); + map.blocks.push(Object.assign({}, this.getBlockByNumber(number), {x: j, y: i})); } } } diff --git a/runtime.d.ts b/runtime.d.ts index 0bd3b4a5..c5a6c735 100644 --- a/runtime.d.ts +++ b/runtime.d.ts @@ -277,6 +277,21 @@ declare class control { /** 删除某个flag/变量 */ removeFlag(name: string): void + /** 设置某个独立开关 */ + setSwitch(x: number, y: number, floorId?: string, name: string, value: any): void + + /** 获得某个独立开关 */ + getSwitch(x: number, y: number, floorId?: string, name: string, defaultValue: any): any + + /** 增加某个独立开关 */ + addSwitch(x: number, y: number, floorId?: string, name: string, value: any): void + + /** 判定某个独立开关 */ + hasSwitch(x: number, y: number, floorId?: string, name: string): boolean + + /** 删除独立开关 */ + removeSwitch(x: number, y: number, floorId?: string, name: string): boolean + /** 设置大地图的偏移量 */ setGameCanvasTranslate(canvasId: string, x: number, y: number): void