mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-06 16:32:16 +02:00
use existing direction inputs
This commit is contained in:
parent
6d8df79195
commit
8071af00ea
@ -93,11 +93,7 @@ export enum Button {
|
|||||||
CYCLE_NATURE,
|
CYCLE_NATURE,
|
||||||
CYCLE_VARIANT,
|
CYCLE_VARIANT,
|
||||||
SPEED_UP,
|
SPEED_UP,
|
||||||
SLOW_DOWN,
|
SLOW_DOWN
|
||||||
LEFT_STICK_UP,
|
|
||||||
LEFT_STICK_DOWN,
|
|
||||||
LEFT_STICK_LEFT,
|
|
||||||
LEFT_STICK_RIGHT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PokeballCounts {
|
export interface PokeballCounts {
|
||||||
@ -1459,10 +1455,10 @@ export default class BattleScene extends SceneBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private analogStickDirections = {
|
private analogStickDirections = {
|
||||||
[Button.LEFT_STICK_UP]: false,
|
[Button.UP]: false,
|
||||||
[Button.LEFT_STICK_DOWN]: false,
|
[Button.DOWN]: false,
|
||||||
[Button.LEFT_STICK_LEFT]: false,
|
[Button.LEFT]: false,
|
||||||
[Button.LEFT_STICK_RIGHT]: false
|
[Button.RIGHT]: false
|
||||||
};
|
};
|
||||||
|
|
||||||
handleAnalogStick(): void {
|
handleAnalogStick(): void {
|
||||||
@ -1476,40 +1472,40 @@ export default class BattleScene extends SceneBase {
|
|||||||
if (Math.abs(leftStickX) > Math.abs(leftStickY)) {
|
if (Math.abs(leftStickX) > Math.abs(leftStickY)) {
|
||||||
if (leftStickX < -this.analogStickThreshold) {
|
if (leftStickX < -this.analogStickThreshold) {
|
||||||
// Left analog stick moved to the left
|
// Left analog stick moved to the left
|
||||||
this.handleAnalogStickDirection(Button.LEFT_STICK_LEFT, Button.LEFT);
|
this.handleAnalogStickDirection(Button.LEFT);
|
||||||
} else if (leftStickX > this.analogStickThreshold) {
|
} else if (leftStickX > this.analogStickThreshold) {
|
||||||
// Left analog stick moved to the right
|
// Left analog stick moved to the right
|
||||||
this.handleAnalogStickDirection(Button.LEFT_STICK_RIGHT, Button.RIGHT);
|
this.handleAnalogStickDirection(Button.RIGHT);
|
||||||
} else {
|
} else {
|
||||||
// Left analog stick is in the neutral position horizontally
|
// Left analog stick is in the neutral position horizontally
|
||||||
this.analogStickDirections[Button.LEFT_STICK_LEFT] = false;
|
this.analogStickDirections[Button.LEFT] = false;
|
||||||
this.analogStickDirections[Button.LEFT_STICK_RIGHT] = false;
|
this.analogStickDirections[Button.RIGHT] = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (leftStickY < -this.analogStickThreshold) {
|
if (leftStickY < -this.analogStickThreshold) {
|
||||||
// Left analog stick moved up
|
// Left analog stick moved up
|
||||||
this.handleAnalogStickDirection(Button.LEFT_STICK_UP, Button.UP);
|
this.handleAnalogStickDirection(Button.UP);
|
||||||
} else if (leftStickY > this.analogStickThreshold) {
|
} else if (leftStickY > this.analogStickThreshold) {
|
||||||
// Left analog stick moved down
|
// Left analog stick moved down
|
||||||
this.handleAnalogStickDirection(Button.LEFT_STICK_DOWN, Button.DOWN);
|
this.handleAnalogStickDirection(Button.DOWN);
|
||||||
} else {
|
} else {
|
||||||
// Left analog stick is in the neutral position vertically
|
// Left analog stick is in the neutral position vertically
|
||||||
this.analogStickDirections[Button.LEFT_STICK_UP] = false;
|
this.analogStickDirections[Button.UP] = false;
|
||||||
this.analogStickDirections[Button.LEFT_STICK_DOWN] = false;
|
this.analogStickDirections[Button.DOWN] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleAnalogStickDirection(analogStickButton: Button, direction: Button): void {
|
private handleAnalogStickDirection(button: Button): void {
|
||||||
if (!this.analogStickDirections[analogStickButton]) {
|
if (!this.analogStickDirections[button]) {
|
||||||
// First button press
|
// First button press
|
||||||
this.ui.processInput(direction);
|
this.ui.processInput(button);
|
||||||
this.setLastProcessedMovementTime(analogStickButton);
|
this.setLastProcessedMovementTime(button);
|
||||||
this.analogStickDirections[analogStickButton] = true;
|
this.analogStickDirections[button] = true;
|
||||||
} else if (this.repeatInputDurationJustPassed(analogStickButton)) {
|
} else if (this.repeatInputDurationJustPassed(button)) {
|
||||||
// Subsequent holds
|
// Subsequent holds
|
||||||
this.ui.processInput(direction);
|
this.ui.processInput(button);
|
||||||
this.setLastProcessedMovementTime(analogStickButton);
|
this.setLastProcessedMovementTime(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -1534,7 +1530,7 @@ export default class BattleScene extends SceneBase {
|
|||||||
|
|
||||||
buttonJustPressed(button: Button): boolean {
|
buttonJustPressed(button: Button): boolean {
|
||||||
const gamepad = this.input.gamepad?.gamepads[0];
|
const gamepad = this.input.gamepad?.gamepads[0];
|
||||||
return this.buttonKeys[button].some(k => Phaser.Input.Keyboard.JustDown(k)) || this.gamepadButtonJustDown(gamepad?.buttons[this.gamepadKeyConfig[button]]);
|
return this.buttonKeys[button].some(k => Phaser.Input.Keyboard.JustDown(k)) || this.gamepadButtonJustDown(gamepad?.buttons[this.gamepadKeyConfig[button]])
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1564,8 +1560,8 @@ export default class BattleScene extends SceneBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAnalogStickButton = button >= Button.LEFT_STICK_UP && button <= Button.LEFT_STICK_RIGHT;
|
const analogStickHeld = this.analogStickDirections[button];
|
||||||
const isButtonPressed = isAnalogStickButton || this.buttonKeys[button]?.some(k => k.isDown);
|
const isButtonPressed = analogStickHeld || this.buttonKeys[button]?.some(k => k.isDown);
|
||||||
|
|
||||||
if (!isButtonPressed && this.gamepadButtonStates.every(b => b == false)) {
|
if (!isButtonPressed && this.gamepadButtonStates.every(b => b == false)) {
|
||||||
this.movementButtonLock = null;
|
this.movementButtonLock = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user