mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-31 23:29:27 +08:00
新的设置控制器
This commit is contained in:
parent
7ce6acb664
commit
a457438e97
1
idea.md
1
idea.md
@ -78,3 +78,4 @@ dam4.png ---- 存档 59
|
||||
[x] 优化插件加载系统
|
||||
[] 优化 Scroll 组件
|
||||
[] 重写技能控制系统
|
||||
[] 自定义快捷键
|
||||
|
153
src/core/main/setting.ts
Normal file
153
src/core/main/setting.ts
Normal file
@ -0,0 +1,153 @@
|
||||
type MotaSettingType = boolean | number | MotaSetting;
|
||||
|
||||
interface MotaSettingItem<T extends MotaSettingType = MotaSettingType> {
|
||||
name: string;
|
||||
value: T;
|
||||
defaults?: boolean | number;
|
||||
step?: number;
|
||||
display?: (value: T) => string;
|
||||
}
|
||||
|
||||
class MotaSetting {
|
||||
private list: Record<string, MotaSettingItem> = {};
|
||||
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<MotaSettingItem | null> {
|
||||
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)
|
||||
);
|
@ -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']
|
||||
]
|
||||
);
|
||||
|
@ -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(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user