mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-03-02 02:27:07 +08:00
refactor: 按键标记怪物
This commit is contained in:
parent
337aaade8c
commit
eaad1f0a5a
@ -34,7 +34,7 @@ const closeFixed = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let hovered: Block | null;
|
export let hovered: Block | null;
|
||||||
|
|
||||||
gameListener.on('hoverBlock', block => {
|
gameListener.on('hoverBlock', block => {
|
||||||
closeFixed();
|
closeFixed();
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { KeyCode } from '@/plugin/keyCodes';
|
import { KeyCode } from '@/plugin/keyCodes';
|
||||||
import { Hotkey } from '../custom/hotkey';
|
import { Hotkey } from '../custom/hotkey';
|
||||||
import { generateBinary, keycode } from '@/plugin/utils';
|
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 mainScope = Symbol.for('@key_main');
|
||||||
export const gameKey = new Hotkey('gameKey', '游戏按键');
|
export const gameKey = new Hotkey('gameKey', '游戏按键');
|
||||||
@ -82,25 +84,40 @@ gameKey
|
|||||||
// --------------------
|
// --------------------
|
||||||
.group('function', '功能按键')
|
.group('function', '功能按键')
|
||||||
.register({
|
.register({
|
||||||
id: 'undo',
|
id: 'undo_1',
|
||||||
name: '回退',
|
name: '回退_1',
|
||||||
defaults: KeyCode.KeyA
|
defaults: KeyCode.KeyA
|
||||||
})
|
})
|
||||||
.register({
|
.register({
|
||||||
id: 'redo',
|
id: 'undo_2',
|
||||||
name: '恢复',
|
name: '回退_2',
|
||||||
|
defaults: KeyCode.Digit5
|
||||||
|
})
|
||||||
|
.register({
|
||||||
|
id: 'redo_1',
|
||||||
|
name: '恢复_1',
|
||||||
defaults: KeyCode.KeyW
|
defaults: KeyCode.KeyW
|
||||||
})
|
})
|
||||||
|
.register({
|
||||||
|
id: 'redo_2',
|
||||||
|
name: '恢复_2',
|
||||||
|
defaults: KeyCode.Digit6
|
||||||
|
})
|
||||||
.register({
|
.register({
|
||||||
id: 'turn',
|
id: 'turn',
|
||||||
name: '勇士转向',
|
name: '勇士转向',
|
||||||
defaults: KeyCode.KeyZ
|
defaults: KeyCode.KeyZ
|
||||||
})
|
})
|
||||||
.register({
|
.register({
|
||||||
id: 'getNext',
|
id: 'getNext_1',
|
||||||
name: '轻按',
|
name: '轻按_1',
|
||||||
defaults: KeyCode.Space
|
defaults: KeyCode.Space
|
||||||
})
|
})
|
||||||
|
.register({
|
||||||
|
id: 'getNext_2',
|
||||||
|
name: '轻按_2',
|
||||||
|
defaults: KeyCode.Digit7
|
||||||
|
})
|
||||||
.register({
|
.register({
|
||||||
id: 'mark',
|
id: 'mark',
|
||||||
name: '标记怪物',
|
name: '标记怪物',
|
||||||
@ -328,7 +345,7 @@ gameKey.use(mainScope);
|
|||||||
// ----- Realization
|
// ----- Realization
|
||||||
|
|
||||||
gameKey
|
gameKey
|
||||||
.when(() => !core.status.lockControl)
|
.when(() => !core.status.lockControl && !core.isMoving())
|
||||||
.realize('book', () => {
|
.realize('book', () => {
|
||||||
core.openBook(true);
|
core.openBook(true);
|
||||||
})
|
})
|
||||||
@ -380,7 +397,14 @@ gameKey
|
|||||||
.realize('getNext', () => {
|
.realize('getNext', () => {
|
||||||
core.getNextItem();
|
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('special', () => {})
|
||||||
.realize('critical', () => {})
|
.realize('critical', () => {})
|
||||||
.realize('restart', () => {
|
.realize('restart', () => {
|
||||||
|
@ -52,12 +52,16 @@ export function markEnemy(id: EnemyIds) {
|
|||||||
marked.push(info);
|
marked.push(info);
|
||||||
|
|
||||||
uiMap.set(id, fixedUi.open('markedEnemy', { enemy: info }));
|
uiMap.set(id, fixedUi.open('markedEnemy', { enemy: info }));
|
||||||
|
|
||||||
|
tip('success', `已标记 ${enemy.enemy.name}!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unmarkEnemy(id: EnemyIds) {
|
export function unmarkEnemy(id: EnemyIds) {
|
||||||
fixedUi.close(uiMap.get(id) ?? -1);
|
fixedUi.close(uiMap.get(id) ?? -1);
|
||||||
uiMap.delete(id);
|
uiMap.delete(id);
|
||||||
const index = marked.findIndex(v => v.id === id);
|
const index = marked.findIndex(v => v.id === id);
|
||||||
|
if (index === -1) return;
|
||||||
|
tip('success', `已取消标记 ${marked[index].enemy.enemy.name}!`);
|
||||||
marked.splice(index, 1);
|
marked.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user