tab -> spaces

This commit is contained in:
Greenlamp 2024-05-03 18:54:06 +02:00
parent 5197311cd8
commit 1d2bc88cab
3 changed files with 258 additions and 259 deletions

View File

@ -63,7 +63,6 @@ import { STARTING_WAVE_OVERRIDE, OPP_SPECIES_OVERRIDE, SEED_OVERRIDE, STARTING_B
import {InputsController} from "./inputs-controller"; import {InputsController} from "./inputs-controller";
import {UiInputs} from "./ui-inputs"; import {UiInputs} from "./ui-inputs";
export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1"; export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1";
const DEBUG_RNG = false; const DEBUG_RNG = false;

View File

@ -41,44 +41,44 @@ export class InputsController extends Phaser.Plugins.ScenePlugin {
private time: Time; private time: Time;
constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string) { constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string) {
super(scene, pluginManager, pluginKey); super(scene, pluginManager, pluginKey);
this.game = pluginManager.game; this.game = pluginManager.game;
this.scene = scene; this.scene = scene;
this.time = this.scene.time; this.time = this.scene.time;
this.buttonKeys = []; this.buttonKeys = [];
for (const b of Utils.getEnumValues(Button)) { for (const b of Utils.getEnumValues(Button)) {
this.interactions[b] = { this.interactions[b] = {
pressTime: false, pressTime: false,
isPressed: false, isPressed: false,
} }
} }
// We don't want the menu key to be repeated // We don't want the menu key to be repeated
delete this.interactions[Button.MENU]; delete this.interactions[Button.MENU];
} }
boot() { boot() {
this.eventEmitter = this.systems.events; this.eventEmitter = this.systems.events;
this.events = new Phaser.Events.EventEmitter(); this.events = new Phaser.Events.EventEmitter();
this.game.events.on(Phaser.Core.Events.STEP, this.update, this); this.game.events.on(Phaser.Core.Events.STEP, this.update, this);
if (typeof this.systems.input.gamepad !== 'undefined') { if (typeof this.systems.input.gamepad !== 'undefined') {
this.systems.input.gamepad.on('connected', function (thisGamepad) { this.systems.input.gamepad.on('connected', function (thisGamepad) {
this.refreshGamepads(); this.refreshGamepads();
this.setupGamepad(thisGamepad); this.setupGamepad(thisGamepad);
}, this); }, this);
// Check to see if the gamepad has already been setup by the browser // Check to see if the gamepad has already been setup by the browser
this.systems.input.gamepad.refreshPads(); this.systems.input.gamepad.refreshPads();
if (this.systems.input.gamepad.total) { if (this.systems.input.gamepad.total) {
this.refreshGamepads(); this.refreshGamepads();
for (const thisGamepad of this.gamepads) { for (const thisGamepad of this.gamepads) {
this.systems.input.gamepad.emit('connected', thisGamepad); this.systems.input.gamepad.emit('connected', thisGamepad);
} }
} }
this.systems.input.gamepad.on('down', this.gamepadButtonDown, this); this.systems.input.gamepad.on('down', this.gamepadButtonDown, this);
this.systems.input.gamepad.on('up', this.gamepadButtonUp, this); this.systems.input.gamepad.on('up', this.gamepadButtonUp, this);
} }
// Keyboard // Keyboard
@ -86,139 +86,139 @@ export class InputsController extends Phaser.Plugins.ScenePlugin {
} }
update() { update() {
for (const b of Utils.getEnumValues(Button)) { for (const b of Utils.getEnumValues(Button)) {
if (!this.interactions.hasOwnProperty(b)) continue; if (!this.interactions.hasOwnProperty(b)) continue;
if (this.repeatInputDurationJustPassed(b)) { if (this.repeatInputDurationJustPassed(b)) {
this.events.emit('input_down', { this.events.emit('input_down', {
controller_type: 'keyboard', controller_type: 'keyboard',
button: b, button: b,
}); });
this.setLastProcessedMovementTime(b); this.setLastProcessedMovementTime(b);
} }
} }
} }
setupGamepad(thisGamepad): void { setupGamepad(thisGamepad): void {
let gamepadID = thisGamepad.id.toLowerCase(); let gamepadID = thisGamepad.id.toLowerCase();
const mappedPad = this.mapGamepad(gamepadID); const mappedPad = this.mapGamepad(gamepadID);
this.player = { this.player = {
'mapping': mappedPad.gamepadMapping, 'mapping': mappedPad.gamepadMapping,
} }
} }
refreshGamepads() :void { refreshGamepads() :void {
// Sometimes, gamepads are undefined. For some reason. // Sometimes, gamepads are undefined. For some reason.
this.gamepads = this.systems.input.gamepad.gamepads.filter(function (el) { this.gamepads = this.systems.input.gamepad.gamepads.filter(function (el) {
return el != null; return el != null;
}); });
for (const [index, thisGamepad] of this.gamepads.entries()) { for (const [index, thisGamepad] of this.gamepads.entries()) {
thisGamepad.index = index; // Overwrite the gamepad index, in case we had undefined gamepads earlier thisGamepad.index = index; // Overwrite the gamepad index, in case we had undefined gamepads earlier
} }
} }
getActionGamepadMapping() { getActionGamepadMapping() {
const gamepadMapping = {}; const gamepadMapping = {};
gamepadMapping[this.player.mapping.LC_N] = Button.UP; gamepadMapping[this.player.mapping.LC_N] = Button.UP;
gamepadMapping[this.player.mapping.LC_S] = Button.DOWN; gamepadMapping[this.player.mapping.LC_S] = Button.DOWN;
gamepadMapping[this.player.mapping.LC_W] = Button.LEFT; gamepadMapping[this.player.mapping.LC_W] = Button.LEFT;
gamepadMapping[this.player.mapping.LC_E] = Button.RIGHT; gamepadMapping[this.player.mapping.LC_E] = Button.RIGHT;
gamepadMapping[this.player.mapping.TOUCH] = Button.SUBMIT; gamepadMapping[this.player.mapping.TOUCH] = Button.SUBMIT;
gamepadMapping[this.player.mapping.RC_S] = Button.ACTION; gamepadMapping[this.player.mapping.RC_S] = Button.ACTION;
gamepadMapping[this.player.mapping.RC_E] = Button.CANCEL; gamepadMapping[this.player.mapping.RC_E] = Button.CANCEL;
gamepadMapping[this.player.mapping.SELECT] = Button.STATS; gamepadMapping[this.player.mapping.SELECT] = Button.STATS;
gamepadMapping[this.player.mapping.START] = Button.MENU; gamepadMapping[this.player.mapping.START] = Button.MENU;
gamepadMapping[this.player.mapping.RB] = Button.CYCLE_SHINY; gamepadMapping[this.player.mapping.RB] = Button.CYCLE_SHINY;
gamepadMapping[this.player.mapping.LB] = Button.CYCLE_FORM; gamepadMapping[this.player.mapping.LB] = Button.CYCLE_FORM;
gamepadMapping[this.player.mapping.LT] = Button.CYCLE_GENDER; gamepadMapping[this.player.mapping.LT] = Button.CYCLE_GENDER;
gamepadMapping[this.player.mapping.RT] = Button.CYCLE_ABILITY; gamepadMapping[this.player.mapping.RT] = Button.CYCLE_ABILITY;
gamepadMapping[this.player.mapping.RC_W] = Button.CYCLE_NATURE; gamepadMapping[this.player.mapping.RC_W] = Button.CYCLE_NATURE;
gamepadMapping[this.player.mapping.RC_N] = Button.CYCLE_VARIANT; gamepadMapping[this.player.mapping.RC_N] = Button.CYCLE_VARIANT;
gamepadMapping[this.player.mapping.LS] = Button.SPEED_UP; gamepadMapping[this.player.mapping.LS] = Button.SPEED_UP;
gamepadMapping[this.player.mapping.RS] = Button.SLOW_DOWN; gamepadMapping[this.player.mapping.RS] = Button.SLOW_DOWN;
return gamepadMapping; return gamepadMapping;
} }
gamepadButtonDown(pad, button, value): void { gamepadButtonDown(pad, button, value): void {
const actionMapping = this.getActionGamepadMapping(); const actionMapping = this.getActionGamepadMapping();
const buttonDown = actionMapping.hasOwnProperty(button.index) && actionMapping[button.index]; const buttonDown = actionMapping.hasOwnProperty(button.index) && actionMapping[button.index];
if (buttonDown !== undefined) { if (buttonDown !== undefined) {
this.events.emit('input_down', { this.events.emit('input_down', {
controller_type: 'gamepad', controller_type: 'gamepad',
button: buttonDown, button: buttonDown,
}); });
this.setLastProcessedMovementTime(buttonDown); this.setLastProcessedMovementTime(buttonDown);
} }
} }
gamepadButtonUp(pad, button, value): void { gamepadButtonUp(pad, button, value): void {
const actionMapping = this.getActionGamepadMapping(); const actionMapping = this.getActionGamepadMapping();
const buttonUp = actionMapping.hasOwnProperty(button.index) && actionMapping[button.index]; const buttonUp = actionMapping.hasOwnProperty(button.index) && actionMapping[button.index];
if (buttonUp !== undefined) { if (buttonUp !== undefined) {
this.events.emit('input_up', { this.events.emit('input_up', {
controller_type: 'gamepad', controller_type: 'gamepad',
button: buttonUp, button: buttonUp,
}); });
this.delLastProcessedMovementTime(buttonUp); this.delLastProcessedMovementTime(buttonUp);
} }
} }
setupKeyboardControls(): void { setupKeyboardControls(): void {
const keyCodes = Phaser.Input.Keyboard.KeyCodes; const keyCodes = Phaser.Input.Keyboard.KeyCodes;
const keyConfig = { const keyConfig = {
[Button.UP]: [keyCodes.UP, keyCodes.W], [Button.UP]: [keyCodes.UP, keyCodes.W],
[Button.DOWN]: [keyCodes.DOWN, keyCodes.S], [Button.DOWN]: [keyCodes.DOWN, keyCodes.S],
[Button.LEFT]: [keyCodes.LEFT, keyCodes.A], [Button.LEFT]: [keyCodes.LEFT, keyCodes.A],
[Button.RIGHT]: [keyCodes.RIGHT, keyCodes.D], [Button.RIGHT]: [keyCodes.RIGHT, keyCodes.D],
[Button.SUBMIT]: [keyCodes.ENTER], [Button.SUBMIT]: [keyCodes.ENTER],
[Button.ACTION]: [keyCodes.SPACE, keyCodes.Z], [Button.ACTION]: [keyCodes.SPACE, keyCodes.Z],
[Button.CANCEL]: [keyCodes.BACKSPACE, keyCodes.X], [Button.CANCEL]: [keyCodes.BACKSPACE, keyCodes.X],
[Button.MENU]: [keyCodes.ESC, keyCodes.M], [Button.MENU]: [keyCodes.ESC, keyCodes.M],
[Button.STATS]: [keyCodes.SHIFT, keyCodes.C], [Button.STATS]: [keyCodes.SHIFT, keyCodes.C],
[Button.CYCLE_SHINY]: [keyCodes.R], [Button.CYCLE_SHINY]: [keyCodes.R],
[Button.CYCLE_FORM]: [keyCodes.F], [Button.CYCLE_FORM]: [keyCodes.F],
[Button.CYCLE_GENDER]: [keyCodes.G], [Button.CYCLE_GENDER]: [keyCodes.G],
[Button.CYCLE_ABILITY]: [keyCodes.E], [Button.CYCLE_ABILITY]: [keyCodes.E],
[Button.CYCLE_NATURE]: [keyCodes.N], [Button.CYCLE_NATURE]: [keyCodes.N],
[Button.CYCLE_VARIANT]: [keyCodes.V], [Button.CYCLE_VARIANT]: [keyCodes.V],
[Button.SPEED_UP]: [keyCodes.PLUS], [Button.SPEED_UP]: [keyCodes.PLUS],
[Button.SLOW_DOWN]: [keyCodes.MINUS] [Button.SLOW_DOWN]: [keyCodes.MINUS]
}; };
const mobileKeyConfig = {}; const mobileKeyConfig = {};
for (const b of Utils.getEnumValues(Button)) { for (const b of Utils.getEnumValues(Button)) {
const keys: Phaser.Input.Keyboard.Key[] = []; const keys: Phaser.Input.Keyboard.Key[] = [];
if (keyConfig.hasOwnProperty(b)) { if (keyConfig.hasOwnProperty(b)) {
for (let k of keyConfig[b]) for (let k of keyConfig[b])
keys.push(this.systems.input.keyboard.addKey(k, false)); keys.push(this.systems.input.keyboard.addKey(k, false));
mobileKeyConfig[Button[b]] = keys[0]; mobileKeyConfig[Button[b]] = keys[0];
} }
this.buttonKeys[b] = keys; this.buttonKeys[b] = keys;
} }
initTouchControls(mobileKeyConfig); initTouchControls(mobileKeyConfig);
this.listenInputKeyboard(); this.listenInputKeyboard();
} }
listenInputKeyboard(): void { listenInputKeyboard(): void {
this.buttonKeys.forEach((row, index) => { this.buttonKeys.forEach((row, index) => {
for (const key of row) { for (const key of row) {
key.on('down', () => { key.on('down', () => {
this.events.emit('input_down', { this.events.emit('input_down', {
controller_type: 'keyboard', controller_type: 'keyboard',
button: index, button: index,
}); });
this.setLastProcessedMovementTime(index); this.setLastProcessedMovementTime(index);
}); });
key.on('up', () => { key.on('up', () => {
this.events.emit('input_up', { this.events.emit('input_up', {
controller_type: 'keyboard', controller_type: 'keyboard',
button: index, button: index,
}); });
this.delLastProcessedMovementTime(index); this.delLastProcessedMovementTime(index);
}); });
} }
}) });
} }
mapGamepad(id) { mapGamepad(id) {
@ -244,24 +244,24 @@ export class InputsController extends Phaser.Plugins.ScenePlugin {
* firing a repeated input - this is to prevent multiple buttons from firing repeatedly. * firing a repeated input - this is to prevent multiple buttons from firing repeatedly.
*/ */
repeatInputDurationJustPassed(button: Button): boolean { repeatInputDurationJustPassed(button: Button): boolean {
if (this.buttonLock === null || this.buttonLock !== button) { if (this.buttonLock === null || this.buttonLock !== button) {
return false; return false;
} }
if (this.time.now - this.interactions[button].pressTime >= repeatInputDelayMillis) { if (this.time.now - this.interactions[button].pressTime >= repeatInputDelayMillis) {
this.buttonLock = null; this.buttonLock = null;
return true; return true;
} }
} }
setLastProcessedMovementTime(button: Button): void { setLastProcessedMovementTime(button: Button): void {
if (!this.interactions.hasOwnProperty(button)) return; if (!this.interactions.hasOwnProperty(button)) return;
this.buttonLock = button; this.buttonLock = button;
this.interactions[button].pressTime = this.time.now; this.interactions[button].pressTime = this.time.now;
} }
delLastProcessedMovementTime(button: Button): void { delLastProcessedMovementTime(button: Button): void {
if (!this.interactions.hasOwnProperty(button)) return; if (!this.interactions.hasOwnProperty(button)) return;
this.buttonLock = null; this.buttonLock = null;
this.interactions[button].pressTime = null; this.interactions[button].pressTime = null;
} }
} }

View File

@ -8,15 +8,15 @@ import SettingsUiHandler from "#app/ui/settings-ui-handler";
export class UiInputs extends Phaser.Plugins.ScenePlugin { export class UiInputs extends Phaser.Plugins.ScenePlugin {
private game: Phaser.Game; private game: Phaser.Game;
private scene: Phaser.Scene; private scene: Phaser.Scene;
private events; private events;
constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string) { constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string) {
super(scene, pluginManager, pluginKey); super(scene, pluginManager, pluginKey);
this.game = pluginManager.game; this.game = pluginManager.game;
this.scene = scene; this.scene = scene;
this.events = this.scene.inputController.events this.events = this.scene.inputController.events
} }
boot() { boot() {
@ -24,136 +24,136 @@ export class UiInputs extends Phaser.Plugins.ScenePlugin {
} }
listenInputs(): void { listenInputs(): void {
this.events.on('input_down', (event) => { this.events.on('input_down', (event) => {
const actions = this.getActionsKeyDown(); const actions = this.getActionsKeyDown();
if (!actions.hasOwnProperty(event.button)) return; if (!actions.hasOwnProperty(event.button)) return;
const [inputSuccess, vibrationLength] = actions[event.button](); const [inputSuccess, vibrationLength] = actions[event.button]();
if (inputSuccess && this.scene.enableVibration && typeof navigator.vibrate !== 'undefined') if (inputSuccess && this.scene.enableVibration && typeof navigator.vibrate !== 'undefined')
navigator.vibrate(vibrationLength); navigator.vibrate(vibrationLength);
}, this); }, this);
this.events.on('input_up', (event) => { this.events.on('input_up', (event) => {
const actions = this.getActionsKeyUp(); const actions = this.getActionsKeyUp();
if (!actions.hasOwnProperty(event.button)) return; if (!actions.hasOwnProperty(event.button)) return;
const [inputSuccess, vibrationLength] = actions[event.button](); const [inputSuccess, vibrationLength] = actions[event.button]();
if (inputSuccess && this.scene.enableVibration && typeof navigator.vibrate !== 'undefined') if (inputSuccess && this.scene.enableVibration && typeof navigator.vibrate !== 'undefined')
navigator.vibrate(vibrationLength); navigator.vibrate(vibrationLength);
}, this); }, this);
} }
getActionsKeyDown() { getActionsKeyDown() {
const actions = {}; const actions = {};
actions[Button.UP] = () => this.buttonDirection(Button.UP); actions[Button.UP] = () => this.buttonDirection(Button.UP);
actions[Button.DOWN] = () => this.buttonDirection(Button.DOWN); actions[Button.DOWN] = () => this.buttonDirection(Button.DOWN);
actions[Button.LEFT] = () => this.buttonDirection(Button.LEFT); actions[Button.LEFT] = () => this.buttonDirection(Button.LEFT);
actions[Button.RIGHT] = () => this.buttonDirection(Button.RIGHT); actions[Button.RIGHT] = () => this.buttonDirection(Button.RIGHT);
actions[Button.SUBMIT] = () => this.buttonTouch(); actions[Button.SUBMIT] = () => this.buttonTouch();
actions[Button.ACTION] = () => this.buttonAb(Button.ACTION); actions[Button.ACTION] = () => this.buttonAb(Button.ACTION);
actions[Button.CANCEL] = () => this.buttonAb(Button.CANCEL); actions[Button.CANCEL] = () => this.buttonAb(Button.CANCEL);
actions[Button.MENU] = () => this.buttonMenu(); actions[Button.MENU] = () => this.buttonMenu();
actions[Button.STATS] = () => this.buttonStats(true); actions[Button.STATS] = () => this.buttonStats(true);
actions[Button.CYCLE_SHINY] = () => this.buttonCycleOption(Button.CYCLE_SHINY); actions[Button.CYCLE_SHINY] = () => this.buttonCycleOption(Button.CYCLE_SHINY);
actions[Button.CYCLE_FORM] = () => this.buttonCycleOption(Button.CYCLE_FORM); actions[Button.CYCLE_FORM] = () => this.buttonCycleOption(Button.CYCLE_FORM);
actions[Button.CYCLE_GENDER] = () => this.buttonCycleOption(Button.CYCLE_GENDER); actions[Button.CYCLE_GENDER] = () => this.buttonCycleOption(Button.CYCLE_GENDER);
actions[Button.CYCLE_ABILITY] = () => this.buttonCycleOption(Button.CYCLE_ABILITY); actions[Button.CYCLE_ABILITY] = () => this.buttonCycleOption(Button.CYCLE_ABILITY);
actions[Button.CYCLE_NATURE] = () => this.buttonCycleOption(Button.CYCLE_NATURE); actions[Button.CYCLE_NATURE] = () => this.buttonCycleOption(Button.CYCLE_NATURE);
actions[Button.CYCLE_VARIANT] = () => this.buttonCycleOption(Button.CYCLE_VARIANT); actions[Button.CYCLE_VARIANT] = () => this.buttonCycleOption(Button.CYCLE_VARIANT);
actions[Button.SPEED_UP] = () => this.buttonSpeedChange(); actions[Button.SPEED_UP] = () => this.buttonSpeedChange();
actions[Button.SLOW_DOWN] = () => this.buttonSpeedChange(false); actions[Button.SLOW_DOWN] = () => this.buttonSpeedChange(false);
return actions; return actions;
} }
getActionsKeyUp() { getActionsKeyUp() {
const actions = {}; const actions = {};
actions[Button.STATS] = () => this.buttonStats(false); actions[Button.STATS] = () => this.buttonStats(false);
return actions; return actions;
} }
buttonDirection(direction): Array<boolean | number> { buttonDirection(direction): Array<boolean | number> {
const inputSuccess = this.scene.ui.processInput(direction); const inputSuccess = this.scene.ui.processInput(direction);
const vibrationLength = 5; const vibrationLength = 5;
return [inputSuccess, vibrationLength]; return [inputSuccess, vibrationLength];
} }
buttonAb(button): Array<boolean | number> { buttonAb(button): Array<boolean | number> {
const inputSuccess = this.scene.ui.processInput(button); const inputSuccess = this.scene.ui.processInput(button);
return [inputSuccess, 0]; return [inputSuccess, 0];
} }
buttonTouch(): Array<boolean | number> { buttonTouch(): Array<boolean | number> {
const inputSuccess = this.scene.ui.processInput(Button.SUBMIT) || this.scene.ui.processInput(Button.ACTION); const inputSuccess = this.scene.ui.processInput(Button.SUBMIT) || this.scene.ui.processInput(Button.ACTION);
return [inputSuccess, 0]; return [inputSuccess, 0];
} }
buttonStats(pressed = true): Array<boolean | number> { buttonStats(pressed = true): Array<boolean | number> {
if (pressed) { if (pressed) {
for (let p of this.scene.getField().filter(p => p?.isActive(true))) for (let p of this.scene.getField().filter(p => p?.isActive(true)))
p.toggleStats(true); p.toggleStats(true);
} else { } else {
for (let p of this.scene.getField().filter(p => p?.isActive(true))) for (let p of this.scene.getField().filter(p => p?.isActive(true)))
p.toggleStats(false); p.toggleStats(false);
} }
return [true, 0]; return [true, 0];
} }
buttonMenu(): Array<boolean | number> { buttonMenu(): Array<boolean | number> {
let inputSuccess; let inputSuccess;
if (this.scene.disableMenu) if (this.scene.disableMenu)
return [true, 0]; return [true, 0];
switch (this.scene.ui?.getMode()) { switch (this.scene.ui?.getMode()) {
case Mode.MESSAGE: case Mode.MESSAGE:
if (!(this.scene.ui.getHandler() as MessageUiHandler).pendingPrompt) if (!(this.scene.ui.getHandler() as MessageUiHandler).pendingPrompt)
return [true, 0]; return [true, 0];
case Mode.TITLE: case Mode.TITLE:
case Mode.COMMAND: case Mode.COMMAND:
case Mode.FIGHT: case Mode.FIGHT:
case Mode.BALL: case Mode.BALL:
case Mode.TARGET_SELECT: case Mode.TARGET_SELECT:
case Mode.SAVE_SLOT: case Mode.SAVE_SLOT:
case Mode.PARTY: case Mode.PARTY:
case Mode.SUMMARY: case Mode.SUMMARY:
case Mode.STARTER_SELECT: case Mode.STARTER_SELECT:
case Mode.CONFIRM: case Mode.CONFIRM:
case Mode.OPTION_SELECT: case Mode.OPTION_SELECT:
this.scene.ui.setOverlayMode(Mode.MENU); this.scene.ui.setOverlayMode(Mode.MENU);
inputSuccess = true; inputSuccess = true;
break; break;
case Mode.MENU: case Mode.MENU:
case Mode.SETTINGS: case Mode.SETTINGS:
case Mode.ACHIEVEMENTS: case Mode.ACHIEVEMENTS:
this.scene.ui.revertMode(); this.scene.ui.revertMode();
this.scene.playSound('select'); this.scene.playSound('select');
inputSuccess = true; inputSuccess = true;
break; break;
default: default:
return [true, 0]; return [true, 0];
} }
return [inputSuccess, 0]; return [inputSuccess, 0];
} }
buttonCycleOption(button): Array<boolean | number> { buttonCycleOption(button): Array<boolean | number> {
let inputSuccess; let inputSuccess;
if (this.scene.ui?.getHandler() instanceof StarterSelectUiHandler) { if (this.scene.ui?.getHandler() instanceof StarterSelectUiHandler) {
inputSuccess = this.scene.ui.processInput(button); inputSuccess = this.scene.ui.processInput(button);
} }
return [inputSuccess, 0]; return [inputSuccess, 0];
} }
buttonSpeedChange(up= true): Array<boolean | number> { buttonSpeedChange(up= true): Array<boolean | number> {
if (up) { if (up) {
if (this.scene.gameSpeed < 5) { if (this.scene.gameSpeed < 5) {
this.scene.gameData.saveSetting(Setting.Game_Speed, settingOptions[Setting.Game_Speed].indexOf(`${this.scene.gameSpeed}x`) + 1); this.scene.gameData.saveSetting(Setting.Game_Speed, settingOptions[Setting.Game_Speed].indexOf(`${this.scene.gameSpeed}x`) + 1);
if (this.scene.ui?.getMode() === Mode.SETTINGS) if (this.scene.ui?.getMode() === Mode.SETTINGS)
(this.scene.ui.getHandler() as SettingsUiHandler).show([]); (this.scene.ui.getHandler() as SettingsUiHandler).show([]);
} }
return [0, 0]; return [0, 0];
} }
if (this.scene.gameSpeed > 1) { if (this.scene.gameSpeed > 1) {
this.scene.gameData.saveSetting(Setting.Game_Speed, Math.max(settingOptions[Setting.Game_Speed].indexOf(`${this.scene.gameSpeed}x`) - 1, 0)); this.scene.gameData.saveSetting(Setting.Game_Speed, Math.max(settingOptions[Setting.Game_Speed].indexOf(`${this.scene.gameSpeed}x`) - 1, 0));
if (this.scene.ui?.getMode() === Mode.SETTINGS) if (this.scene.ui?.getMode() === Mode.SETTINGS)
(this.scene.ui.getHandler() as SettingsUiHandler).show([]); (this.scene.ui.getHandler() as SettingsUiHandler).show([]);
} }
return [0, 0]; return [0, 0];
} }
} }