From eaad1f0a5ac1b8105b29f3405805d356f7397e23 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 19 Nov 2023 19:36:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8C=89=E9=94=AE=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E6=80=AA=E7=89=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/main/init/fixed.ts | 2 +- src/core/main/init/hotkey.ts | 40 ++++++++++++++++++++++++++++-------- src/plugin/mark.ts | 4 ++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/core/main/init/fixed.ts b/src/core/main/init/fixed.ts index b60f17a..e3d275b 100644 --- a/src/core/main/init/fixed.ts +++ b/src/core/main/init/fixed.ts @@ -34,7 +34,7 @@ const closeFixed = () => { }); }; -let hovered: Block | null; +export let hovered: Block | null; gameListener.on('hoverBlock', block => { closeFixed(); diff --git a/src/core/main/init/hotkey.ts b/src/core/main/init/hotkey.ts index 5268476..c66d30e 100644 --- a/src/core/main/init/hotkey.ts +++ b/src/core/main/init/hotkey.ts @@ -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', () => { diff --git a/src/plugin/mark.ts b/src/plugin/mark.ts index 1ca8cbd..821ce65 100644 --- a/src/plugin/mark.ts +++ b/src/plugin/mark.ts @@ -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); }