From e5afdb73fdb6b034e56e21f594c57c464d5d215b Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Mon, 26 Aug 2024 21:55:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E6=89=8B=E6=84=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/main/custom/hotkey.ts | 8 ++-- src/core/render/preset/floor.ts | 4 ++ src/plugin/game/fallback.ts | 75 +++++++++++++++++---------------- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/core/main/custom/hotkey.ts b/src/core/main/custom/hotkey.ts index f0417ac..899fe03 100644 --- a/src/core/main/custom/hotkey.ts +++ b/src/core/main/custom/hotkey.ts @@ -86,7 +86,8 @@ export class Hotkey extends EventEmitter { enabled: boolean = false; conditionMap: Map boolean> = new Map(); - private scope: symbol = Symbol(); + /** 当前作用域 */ + scope: symbol = Symbol(); private scopeStack: symbol[] = []; private grouping: string = 'none'; @@ -226,6 +227,8 @@ export class Hotkey extends EventEmitter { // 检查全局启用情况 if (!this.enabled) return false; const when = this.conditionMap.get(this.scope)!; + if (type === 'down') this.checkPress(key); + else this.checkPressEnd(key); if (!when()) return false; const toEmit = this.keyMap.get(key); if (!toEmit) return false; @@ -253,9 +256,6 @@ export class Hotkey extends EventEmitter { }); this.emit('emit', key, assist, type); - if (type === 'down') this.checkPress(key); - else this.checkPressEnd(key); - return emitted; } diff --git a/src/core/render/preset/floor.ts b/src/core/render/preset/floor.ts index fd970fe..044127f 100644 --- a/src/core/render/preset/floor.ts +++ b/src/core/render/preset/floor.ts @@ -289,4 +289,8 @@ export class LayerOpenDoorAnimate implements ILayerRenderExtends { awake(layer: Layer) { this.layer = layer; } + + openDoor(x: number, y: number) {} + + closeDoor(x: number, y: number) {} } diff --git a/src/plugin/game/fallback.ts b/src/plugin/game/fallback.ts index fc92d65..50a637a 100644 --- a/src/plugin/game/fallback.ts +++ b/src/plugin/game/fallback.ts @@ -25,45 +25,47 @@ export function init() { const pressedArrow: Set = new Set(); Mota.r(() => { const gameKey = Mota.require('var', 'gameKey'); - gameKey - .realize('moveUp', onMoveKeyDown('up'), { type: 'down' }) - .realize('moveUp', onMoveKeyUp('up')) - .realize('moveDown', onMoveKeyDown('down'), { type: 'down' }) - .realize('moveDown', onMoveKeyUp('down')) - .realize('moveLeft', onMoveKeyDown('left'), { type: 'down' }) - .realize('moveLeft', onMoveKeyUp('left')) - .realize('moveRight', onMoveKeyDown('right'), { type: 'down' }) - .realize('moveRight', onMoveKeyUp('right')); + const { moveUp, moveDown, moveLeft, moveRight } = gameKey.data; + const symbol = Symbol.for('@key_main'); + gameKey.on('press', code => { + if (core.status.lockControl || gameKey.scope !== symbol) return; + if (code === moveUp.key) onMoveKeyDown('up'); + if (code === moveDown.key) onMoveKeyDown('down'); + if (code === moveLeft.key) onMoveKeyDown('left'); + if (code === moveRight.key) onMoveKeyDown('right'); + }); + gameKey.on('release', code => { + if (code === moveUp.key) onMoveKeyUp('up'); + if (code === moveDown.key) onMoveKeyUp('down'); + if (code === moveLeft.key) onMoveKeyUp('left'); + if (code === moveRight.key) onMoveKeyUp('right'); + }); }); function onMoveKeyDown(type: Dir) { - return () => { - pressedArrow.add(type); - moveDir = type; + pressedArrow.add(type); + moveDir = type; + if (!moving) { + stepDir = moveDir; + readyMove(); + } + if (moving && stopChian) { + stopChian = false; + } + } + + function onMoveKeyUp(type: Dir) { + pressedArrow.delete(type); + if (pressedArrow.size === 0) { + stopChian = true; + } else { + const arr = [...pressedArrow]; + moveDir = arr[0]; if (!moving) { stepDir = moveDir; readyMove(); } - if (moving && stopChian) { - stopChian = false; - } - }; - } - - function onMoveKeyUp(type: Dir) { - return () => { - pressedArrow.delete(type); - if (pressedArrow.size === 0) { - stopChian = true; - } else { - const arr = [...pressedArrow]; - moveDir = arr[0]; - if (!moving) { - stepDir = moveDir; - readyMove(); - } - } - }; + } } async function readyMove() { @@ -108,11 +110,6 @@ export function init() { stopChian = true; return; } - if (core.status.lockControl) { - pressedArrow.clear(); - stopChian = true; - return; - } if (checkCanMoveStatus()) { if (!moving) { stepDir = moveDir; @@ -275,6 +272,10 @@ export function init() { adapters['hero-adapter']?.all('setImage', img); }; + control.prototype.isMoving = function () { + return moving; + }; + hook.on('reset', () => { moveDir = core.status.hero.loc.direction; stepDir = moveDir;