From a457438e975509ccd6591aa34a223269b806035e Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 2 Aug 2023 23:17:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=9A=84=E8=AE=BE=E7=BD=AE=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- idea.md | 1 + src/core/main/setting.ts | 153 +++++++++++++++++++++++++++++++++++++++ src/ui/fixed.vue | 2 +- src/ui/fly.vue | 2 +- 4 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 src/core/main/setting.ts diff --git a/idea.md b/idea.md index 73f8e19..1c94de2 100644 --- a/idea.md +++ b/idea.md @@ -78,3 +78,4 @@ dam4.png ---- 存档 59 [x] 优化插件加载系统 [] 优化 Scroll 组件 [] 重写技能控制系统 +[] 自定义快捷键 diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts new file mode 100644 index 0000000..2ef3b7e --- /dev/null +++ b/src/core/main/setting.ts @@ -0,0 +1,153 @@ +type MotaSettingType = boolean | number | MotaSetting; + +interface MotaSettingItem { + name: string; + value: T; + defaults?: boolean | number; + step?: number; + display?: (value: T) => string; +} + +class MotaSetting { + private list: Record = {}; + special?: string; + + /** + * 标记为特殊的设置项 + */ + markAsSpecial(sp: string) { + this.special = sp; + return this; + } + + /** + * 注册一个数字型设置 + * @param key 设置的键名 + * @param value 设置的值 + */ + register(key: string, name: string, value: number, step?: number): this; + /** + * 注册一个非数字型设置 + * @param key 设置的键名 + * @param value 设置的值 + */ + register(key: string, name: string, value: boolean | MotaSetting): this; + register( + key: string, + name: string, + value: MotaSettingType, + step: number = 1 + ) { + const setting: MotaSettingItem = { + name, + value + }; + if (!(value instanceof MotaSetting)) setting.defaults = value; + if (typeof value === 'number') setting.step = step; + this.list[key] = setting; + return this; + } + + /** + * 获取一个设置信息 + * @param key 要获取的设置的键 + */ + getSetting(key: string): Readonly { + const list = key.split('.'); + return this.getSettingBy(list); + } + + /** + * 设置一个设置的值 + * @param key 要设置的设置的键 + * @param value 要设置的值 + */ + setValue(key: string, value: boolean | number) { + const setting = this.getSettingBy(key.split('.')); + if (typeof setting.value !== typeof value) { + throw new Error( + `Setting type mismatch on setting '${key}'.` + + `Expected: ${typeof setting.value}. Recieve: ${typeof value}` + ); + } + setting.value = value; + } + + /** + * 增加一个设置的值 + * @param key 要改变的设置的值 + * @param value 值的增量 + */ + addValue(key: string, value: number) { + const setting = this.getSettingBy(key.split('.')); + if (typeof setting.value !== 'number') { + throw new Error( + `Cannot execute addValue method on a non-number setting.` + + `Type expected: number. See: ${typeof setting.value}` + ); + } + setting.value += value; + } + + /** + * 设置一个设置的值显示函数 + * @param key 要设置的设置的键 + * @param func 显示函数 + */ + setDisplayFunc(key: string, func: (value: MotaSettingType) => string) { + const setting = this.getSettingBy(key.split('.')); + setting.display = func; + } + + private getSettingBy(list: string[]) { + let now: MotaSetting = this; + + for (let i = 0; i < list.length - 1; i++) { + const item = now.list[list[i]]; + if (!(item instanceof MotaSetting)) { + throw new Error( + `Cannot get setting. The parent isn't a MotaSetting instance.` + + `Key: '${list.join('.')}'. Reading: '${list[i]}'` + ); + } + now = item; + } + + return now.list[list.at(-1)!] ?? null; + } +} + +export const mainSetting = new MotaSetting(); + +// ----- 游戏的所有设置项 +mainSetting + .register( + 'screen', + '显示设置', + new MotaSetting() + .register('fullscreen', '全屏游戏', false) + .register('halo', '光环显示', true) + .register('frag', '打怪特效', true) + .register('itemDetail', '宝石血瓶显伤', true) + .register('transition', '界面动画', false) + .register('antiAlias', '抗锯齿', false) + .register('autoScale', '自动放缩', true) + .register('fontSize', '字体大小', 16, 1) + ) + .register( + 'action', + '操作设置', + new MotaSetting() + .register('autoSkill', '自动切换技能', true) + .register('fixed', '定点查看', true) + .register( + 'hotkey', + '快捷键', + new MotaSetting().markAsSpecial('hotkey') + ) + ) + .register( + 'utils', + '功能设置', + new MotaSetting().register('betterLoad', '优化加载', true) + ); diff --git a/src/ui/fixed.vue b/src/ui/fixed.vue index 399caaa..755b7a2 100644 --- a/src/ui/fixed.vue +++ b/src/ui/fixed.vue @@ -54,7 +54,7 @@ const toShowAttrs: ComputedRef<[number | string, string, string][]> = computed( [enemy.value.enemy.enemy.money, '金币', 'lightyellow'], [enemy.value.enemy.enemy.exp, '经验', 'lawgreen'], [enemy.value.critical, '临界', 'lightsalmon'], - [enemy.value.criticalDam, '减伤', 'lightpink'], + [enemy.value.criticalDam, '临界减伤', 'lightpink'], [enemy.value.defDam, `${core.status.thisMap?.ratio ?? 1}防`, 'cyan'] ] ); diff --git a/src/ui/fly.vue b/src/ui/fly.vue index 3ae7059..4756038 100644 --- a/src/ui/fly.vue +++ b/src/ui/fly.vue @@ -615,7 +615,7 @@ onMounted(async () => { document.addEventListener('keyup', keyup); map.addEventListener('touchstart', touchdown); map.addEventListener('touchend', touchup); - map.addEventListener('touchend', touchmove); + map.addEventListener('touchmove', touchmove); }); onUnmounted(() => {