mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-06 08:22:16 +02:00
aggregate directions and some action into a same method + fix menu return value
This commit is contained in:
parent
6de2051338
commit
4f4f4e035a
@ -251,6 +251,7 @@ export default class BattleScene extends SceneBase {
|
|||||||
listenInputs() {
|
listenInputs() {
|
||||||
this.inputController.events.on('input_down', (event) => {
|
this.inputController.events.on('input_down', (event) => {
|
||||||
const actions = this.getActionsKeyDown();
|
const actions = this.getActionsKeyDown();
|
||||||
|
if (!actions.hasOwnProperty(event.button)) return;
|
||||||
const [inputSuccess, vibrationLength] = actions[event.button]();
|
const [inputSuccess, vibrationLength] = actions[event.button]();
|
||||||
if (inputSuccess && this.enableVibration && typeof navigator.vibrate !== 'undefined')
|
if (inputSuccess && this.enableVibration && typeof navigator.vibrate !== 'undefined')
|
||||||
navigator.vibrate(vibrationLength);
|
navigator.vibrate(vibrationLength);
|
||||||
@ -1280,53 +1281,26 @@ export default class BattleScene extends SceneBase {
|
|||||||
return biomes[Utils.randSeedInt(biomes.length)];
|
return biomes[Utils.randSeedInt(biomes.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
button_up() {
|
buttonDirection(direction) {
|
||||||
const inputSuccess = this.ui.processInput(Button.UP);
|
const inputSuccess = this.ui.processInput(direction);
|
||||||
const vibrationLength = 5;
|
const vibrationLength = 5;
|
||||||
this.setLastProcessedMovementTime(Button.UP);
|
this.setLastProcessedMovementTime(direction);
|
||||||
return [inputSuccess, vibrationLength];
|
return [inputSuccess, vibrationLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
button_down() {
|
buttonAb(button) {
|
||||||
const inputSuccess = this.ui.processInput(Button.DOWN);
|
const inputSuccess = this.ui.processInput(button);
|
||||||
const vibrationLength = 5;
|
this.setLastProcessedMovementTime(button);
|
||||||
this.setLastProcessedMovementTime(Button.DOWN);
|
return [inputSuccess, 0];
|
||||||
return [inputSuccess, vibrationLength];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button_left() {
|
buttonTouch() {
|
||||||
const inputSuccess = this.ui.processInput(Button.LEFT);
|
|
||||||
const vibrationLength = 5;
|
|
||||||
this.setLastProcessedMovementTime(Button.LEFT);
|
|
||||||
return [inputSuccess, vibrationLength];
|
|
||||||
}
|
|
||||||
|
|
||||||
button_right() {
|
|
||||||
const inputSuccess = this.ui.processInput(Button.RIGHT);
|
|
||||||
const vibrationLength = 5;
|
|
||||||
this.setLastProcessedMovementTime(Button.RIGHT);
|
|
||||||
return [inputSuccess, vibrationLength];
|
|
||||||
}
|
|
||||||
|
|
||||||
button_touch() {
|
|
||||||
const inputSuccess = this.ui.processInput(Button.SUBMIT) || this.ui.processInput(Button.ACTION);
|
const inputSuccess = this.ui.processInput(Button.SUBMIT) || this.ui.processInput(Button.ACTION);
|
||||||
this.setLastProcessedMovementTime(Button.SUBMIT);
|
this.setLastProcessedMovementTime(Button.SUBMIT);
|
||||||
return [inputSuccess, 0];
|
return [inputSuccess, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
button_action() {
|
buttonStats(pressed = true) {
|
||||||
const inputSuccess = this.ui.processInput(Button.ACTION);
|
|
||||||
this.setLastProcessedMovementTime(Button.ACTION);
|
|
||||||
return [inputSuccess, 0];
|
|
||||||
}
|
|
||||||
|
|
||||||
button_cancel() {
|
|
||||||
const inputSuccess = this.ui.processInput(Button.CANCEL);
|
|
||||||
this.setLastProcessedMovementTime(Button.CANCEL);
|
|
||||||
return [inputSuccess, 0];
|
|
||||||
}
|
|
||||||
|
|
||||||
button_stats(pressed = true) {
|
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
for (let p of this.getField().filter(p => p?.isActive(true)))
|
for (let p of this.getField().filter(p => p?.isActive(true)))
|
||||||
p.toggleStats(true);
|
p.toggleStats(true);
|
||||||
@ -1338,14 +1312,14 @@ export default class BattleScene extends SceneBase {
|
|||||||
return [0, 0];
|
return [0, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
button_menu() {
|
buttonMenu() {
|
||||||
let inputSuccess;
|
let inputSuccess;
|
||||||
if (this.disableMenu)
|
if (this.disableMenu)
|
||||||
return;
|
return [0, 0];
|
||||||
switch (this.ui?.getMode()) {
|
switch (this.ui?.getMode()) {
|
||||||
case Mode.MESSAGE:
|
case Mode.MESSAGE:
|
||||||
if (!(this.ui.getHandler() as MessageUiHandler).pendingPrompt)
|
if (!(this.ui.getHandler() as MessageUiHandler).pendingPrompt)
|
||||||
return;
|
return [0, 0];
|
||||||
case Mode.TITLE:
|
case Mode.TITLE:
|
||||||
case Mode.COMMAND:
|
case Mode.COMMAND:
|
||||||
case Mode.FIGHT:
|
case Mode.FIGHT:
|
||||||
@ -1368,12 +1342,12 @@ export default class BattleScene extends SceneBase {
|
|||||||
inputSuccess = true;
|
inputSuccess = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return [0, 0];
|
||||||
}
|
}
|
||||||
return [inputSuccess, 0];
|
return [inputSuccess, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
button_cycle_option(button) {
|
buttonCycleOption(button) {
|
||||||
let inputSuccess;
|
let inputSuccess;
|
||||||
if (this.ui?.getHandler() instanceof StarterSelectUiHandler) {
|
if (this.ui?.getHandler() instanceof StarterSelectUiHandler) {
|
||||||
inputSuccess = this.ui.processInput(button);
|
inputSuccess = this.ui.processInput(button);
|
||||||
@ -1382,17 +1356,18 @@ export default class BattleScene extends SceneBase {
|
|||||||
return [inputSuccess, 0];
|
return [inputSuccess, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
button_speed_up() {
|
buttonSpeedChange(up= true) {
|
||||||
if (this.gameSpeed < 5) {
|
if (up) {
|
||||||
this.gameData.saveSetting(Setting.Game_Speed, settingOptions[Setting.Game_Speed].indexOf(`${this.gameSpeed}x`) + 1);
|
console.log('speed up');
|
||||||
if (this.ui?.getMode() === Mode.SETTINGS)
|
if (this.gameSpeed < 5) {
|
||||||
(this.ui.getHandler() as SettingsUiHandler).show([]);
|
this.gameData.saveSetting(Setting.Game_Speed, settingOptions[Setting.Game_Speed].indexOf(`${this.gameSpeed}x`) + 1);
|
||||||
|
if (this.ui?.getMode() === Mode.SETTINGS)
|
||||||
|
(this.ui.getHandler() as SettingsUiHandler).show([]);
|
||||||
|
}
|
||||||
|
return [0, 0];
|
||||||
}
|
}
|
||||||
return [0, 0];
|
|
||||||
}
|
|
||||||
|
|
||||||
button_speed_down() {
|
|
||||||
if (this.gameSpeed > 1) {
|
if (this.gameSpeed > 1) {
|
||||||
|
console.log('speed down');
|
||||||
this.gameData.saveSetting(Setting.Game_Speed, Math.max(settingOptions[Setting.Game_Speed].indexOf(`${this.gameSpeed}x`) - 1, 0));
|
this.gameData.saveSetting(Setting.Game_Speed, Math.max(settingOptions[Setting.Game_Speed].indexOf(`${this.gameSpeed}x`) - 1, 0));
|
||||||
if (this.ui?.getMode() === Mode.SETTINGS)
|
if (this.ui?.getMode() === Mode.SETTINGS)
|
||||||
(this.ui.getHandler() as SettingsUiHandler).show([]);
|
(this.ui.getHandler() as SettingsUiHandler).show([]);
|
||||||
@ -1402,29 +1377,29 @@ export default class BattleScene extends SceneBase {
|
|||||||
|
|
||||||
getActionsKeyDown() {
|
getActionsKeyDown() {
|
||||||
const actions = {};
|
const actions = {};
|
||||||
actions[Button.UP] = () => this.button_up();
|
actions[Button.UP] = () => this.buttonDirection(Button.UP);
|
||||||
actions[Button.DOWN] = () => this.button_down();
|
actions[Button.DOWN] = () => this.buttonDirection(Button.DOWN);
|
||||||
actions[Button.LEFT] = () => this.button_left();
|
actions[Button.LEFT] = () => this.buttonDirection(Button.LEFT);
|
||||||
actions[Button.RIGHT] = () => this.button_right();
|
actions[Button.RIGHT] = () => this.buttonDirection(Button.RIGHT);
|
||||||
actions[Button.SUBMIT] = () => this.button_touch();
|
actions[Button.SUBMIT] = () => this.buttonTouch();
|
||||||
actions[Button.ACTION] = () => this.button_action();
|
actions[Button.ACTION] = () => this.buttonAb(Button.ACTION);
|
||||||
actions[Button.CANCEL] = () => this.button_cancel();
|
actions[Button.CANCEL] = () => this.buttonAb(Button.CANCEL);
|
||||||
actions[Button.MENU] = () => this.button_menu();
|
actions[Button.MENU] = () => this.buttonMenu();
|
||||||
actions[Button.STATS] = () => this.button_stats(true);
|
actions[Button.STATS] = () => this.buttonStats(true);
|
||||||
actions[Button.CYCLE_SHINY] = () => this.button_cycle_option(Button.CYCLE_SHINY);
|
actions[Button.CYCLE_SHINY] = () => this.buttonCycleOption(Button.CYCLE_SHINY);
|
||||||
actions[Button.CYCLE_FORM] = () => this.button_cycle_option(Button.CYCLE_FORM);
|
actions[Button.CYCLE_FORM] = () => this.buttonCycleOption(Button.CYCLE_FORM);
|
||||||
actions[Button.CYCLE_GENDER] = () => this.button_cycle_option(Button.CYCLE_GENDER);
|
actions[Button.CYCLE_GENDER] = () => this.buttonCycleOption(Button.CYCLE_GENDER);
|
||||||
actions[Button.CYCLE_ABILITY] = () => this.button_cycle_option(Button.CYCLE_ABILITY);
|
actions[Button.CYCLE_ABILITY] = () => this.buttonCycleOption(Button.CYCLE_ABILITY);
|
||||||
actions[Button.CYCLE_NATURE] = () => this.button_cycle_option(Button.CYCLE_NATURE);
|
actions[Button.CYCLE_NATURE] = () => this.buttonCycleOption(Button.CYCLE_NATURE);
|
||||||
actions[Button.CYCLE_VARIANT] = () => this.button_cycle_option(Button.CYCLE_VARIANT);
|
actions[Button.CYCLE_VARIANT] = () => this.buttonCycleOption(Button.CYCLE_VARIANT);
|
||||||
actions[Button.SPEED_UP] = () => this.button_speed_up();
|
actions[Button.SPEED_UP] = () => this.buttonSpeedChange();
|
||||||
actions[Button.SLOW_DOWN] = () => this.button_speed_down();
|
actions[Button.SLOW_DOWN] = () => this.buttonSpeedChange(false);
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
getActionsKeyUp() {
|
getActionsKeyUp() {
|
||||||
const actions = {};
|
const actions = {};
|
||||||
actions[Button.STATS] = () => this.button_stats(false);
|
actions[Button.STATS] = () => this.buttonStats(false);
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user