From b7f0d6f4d817176a2a0af859de40055ef2e67eb9 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 2 Aug 2023 23:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=BE=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/main/setting.ts | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 085f658..6705d98 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -8,6 +8,7 @@ interface MotaSettingItem { defaults?: boolean | number; step?: number; display?: (value: T) => string; + special?: string; } interface SettingEvent extends EmitableEvent { @@ -20,14 +21,13 @@ interface SettingEvent extends EmitableEvent { class MotaSetting extends EventEmitter { private list: Record = {}; - special?: string; /** * 标记为特殊的设置项 */ - markAsSpecial(sp: string) { - this.special = sp; - this.register('@special', '', false); + markSpecial(key: string, sp: string) { + const setting = this.getSettingBy(key.split('.')); + setting.special = sp; return this; } @@ -83,7 +83,7 @@ class MotaSetting extends EventEmitter { } const old = setting.value as boolean | number; setting.value = value; - this.emit('valueChange', this.formatKey(key), old, value); + this.emit('valueChange', key, old, value); } /** @@ -101,7 +101,7 @@ class MotaSetting extends EventEmitter { } const old = setting.value as boolean | number; setting.value += value; - this.emit('valueChange', this.formatKey(key), old, value); + this.emit('valueChange', key, old, value); } /** @@ -130,10 +130,6 @@ class MotaSetting extends EventEmitter { return now.list[list.at(-1)!] ?? null; } - - private formatKey(key: string) { - return key.replace('.@special', ''); - } } export const mainSetting = new MotaSetting(); @@ -159,11 +155,8 @@ mainSetting new MotaSetting() .register('autoSkill', '自动切换技能', true) .register('fixed', '定点查看', true) - .register( - 'hotkey', - '快捷键', - new MotaSetting().markAsSpecial('hotkey') - ) + .register('hotkey', '快捷键', false) + .markSpecial('hotkey', 'hotkey') ) .register( 'utils',