mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 12:49:25 +08:00
fix: 优化移动手感
This commit is contained in:
parent
1c369251b1
commit
e5afdb73fd
@ -86,7 +86,8 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
|
||||
enabled: boolean = false;
|
||||
conditionMap: Map<symbol, () => 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<HotkeyEvent> {
|
||||
// 检查全局启用情况
|
||||
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<HotkeyEvent> {
|
||||
});
|
||||
this.emit('emit', key, assist, type);
|
||||
|
||||
if (type === 'down') this.checkPress(key);
|
||||
else this.checkPressEnd(key);
|
||||
|
||||
return emitted;
|
||||
}
|
||||
|
||||
|
@ -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) {}
|
||||
}
|
||||
|
@ -25,45 +25,47 @@ export function init() {
|
||||
const pressedArrow: Set<Dir> = 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;
|
||||
|
Loading…
Reference in New Issue
Block a user