fix: 实现按键时的id判断

This commit is contained in:
unanmed 2023-11-20 21:32:35 +08:00
parent a2639e63db
commit d10022c9e8
2 changed files with 4 additions and 2 deletions

View File

@ -81,7 +81,7 @@ dam4.png ---- 存档 59
[] 优化插件加载系统 [] 优化插件加载系统
[] 优化 Scroll 组件 [] 优化 Scroll 组件
[] 重写技能控制系统 [] 重写技能控制系统
[] 自定义快捷键 [x] 自定义快捷键
[x] 优化 ui 控制系统 [x] 优化 ui 控制系统
[] 优化游戏进程与渲染进程间的通讯 [] 优化游戏进程与渲染进程间的通讯
[] 优化资源分离,音乐放到 bgm 目录下 [] 优化资源分离,音乐放到 bgm 目录下

View File

@ -99,7 +99,9 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
*/ */
realize(id: string, func: HotkeyFunc) { realize(id: string, func: HotkeyFunc) {
const toSet = Object.values(this.data).filter(v => { const toSet = Object.values(this.data).filter(v => {
return v.id === id || v.id.split('_').slice(0, -1).join('_') === id; const split = v.id.split('_');
const last = !isNaN(Number(split.at(-1)));
return v.id === id || (last && split.slice(0, -1).join('_') === id);
}); });
if (toSet.length === 0) { if (toSet.length === 0) {
throw new Error(`Realize nonexistent key '${id}'.`); throw new Error(`Realize nonexistent key '${id}'.`);