refactor: 按键标记怪物

This commit is contained in:
unanmed 2023-11-19 19:36:45 +08:00
parent 337aaade8c
commit eaad1f0a5a
3 changed files with 37 additions and 9 deletions

View File

@ -34,7 +34,7 @@ const closeFixed = () => {
});
};
let hovered: Block | null;
export let hovered: Block | null;
gameListener.on('hoverBlock', block => {
closeFixed();

View File

@ -1,6 +1,8 @@
import { KeyCode } from '@/plugin/keyCodes';
import { Hotkey } from '../custom/hotkey';
import { generateBinary, keycode } from '@/plugin/utils';
import { hovered } from './fixed';
import { hasMarkedEnemy, markEnemy, unmarkEnemy } from '@/plugin/mark';
export const mainScope = Symbol.for('@key_main');
export const gameKey = new Hotkey('gameKey', '游戏按键');
@ -82,25 +84,40 @@ gameKey
// --------------------
.group('function', '功能按键')
.register({
id: 'undo',
name: '回退',
id: 'undo_1',
name: '回退_1',
defaults: KeyCode.KeyA
})
.register({
id: 'redo',
name: '恢复',
id: 'undo_2',
name: '回退_2',
defaults: KeyCode.Digit5
})
.register({
id: 'redo_1',
name: '恢复_1',
defaults: KeyCode.KeyW
})
.register({
id: 'redo_2',
name: '恢复_2',
defaults: KeyCode.Digit6
})
.register({
id: 'turn',
name: '勇士转向',
defaults: KeyCode.KeyZ
})
.register({
id: 'getNext',
name: '轻按',
id: 'getNext_1',
name: '轻按_1',
defaults: KeyCode.Space
})
.register({
id: 'getNext_2',
name: '轻按_2',
defaults: KeyCode.Digit7
})
.register({
id: 'mark',
name: '标记怪物',
@ -328,7 +345,7 @@ gameKey.use(mainScope);
// ----- Realization
gameKey
.when(() => !core.status.lockControl)
.when(() => !core.status.lockControl && !core.isMoving())
.realize('book', () => {
core.openBook(true);
})
@ -380,7 +397,14 @@ gameKey
.realize('getNext', () => {
core.getNextItem();
})
.realize('mark', () => {})
.realize('mark', () => {
const cls = hovered?.event.cls;
if (cls === 'enemys' || cls === 'enemy48') {
const id = hovered!.event.id as EnemyIds;
if (hasMarkedEnemy(id)) unmarkEnemy(id);
else markEnemy(id);
}
})
.realize('special', () => {})
.realize('critical', () => {})
.realize('restart', () => {

View File

@ -52,12 +52,16 @@ export function markEnemy(id: EnemyIds) {
marked.push(info);
uiMap.set(id, fixedUi.open('markedEnemy', { enemy: info }));
tip('success', `已标记 ${enemy.enemy.name}`);
}
export function unmarkEnemy(id: EnemyIds) {
fixedUi.close(uiMap.get(id) ?? -1);
uiMap.delete(id);
const index = marked.findIndex(v => v.id === id);
if (index === -1) return;
tip('success', `已取消标记 ${marked[index].enemy.enemy.name}`);
marked.splice(index, 1);
}