mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-09-24 07:23:24 +02:00
Extract left/right logic to own method
Co-authored-by: Wlowscha <54003515+Wlowscha@users.noreply.github.com>
This commit is contained in:
parent
b4f699dbef
commit
f3194e77c6
@ -248,6 +248,26 @@ export class AbstractSettingsUiHandler extends MessageUiHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submethod of {@linkcode processInput} to handle left/right input for changing option values
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* If the cursor is positioned on a boundary option, will apply clamping / wrapping as appropriate
|
||||||
|
* @param cursor - Current cursor position in the settings menu
|
||||||
|
* @param dir - Direction to pan when scrolling, -1 for left, 1 for right
|
||||||
|
* @returns `true` if the action associated with the button was successfully processed, `false` otherwise.
|
||||||
|
*/
|
||||||
|
private processLeftRightInput(cursor: number, dir: -1 | 1): boolean {
|
||||||
|
let boundaryAction = Phaser.Math.Wrap;
|
||||||
|
let upperBound = this.optionValueLabels[cursor].length;
|
||||||
|
if (this.settings[cursor]?.clamp) {
|
||||||
|
boundaryAction = Phaser.Math.Clamp;
|
||||||
|
// clamping is right inclusive; wrapping isn't
|
||||||
|
upperBound -= 1;
|
||||||
|
}
|
||||||
|
return this.setOptionCursor(cursor, boundaryAction(this.optionCursors[cursor] + dir, 0, upperBound), true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes input from a specified button.
|
* Processes input from a specified button.
|
||||||
* This method handles navigation through a UI menu, including movement through menu items
|
* This method handles navigation through a UI menu, including movement through menu items
|
||||||
@ -269,8 +289,6 @@ export class AbstractSettingsUiHandler extends MessageUiHandler {
|
|||||||
// Reverts UI to its previous state on cancel.
|
// Reverts UI to its previous state on cancel.
|
||||||
globalScene.ui.revertMode();
|
globalScene.ui.revertMode();
|
||||||
} else {
|
} else {
|
||||||
/** Direction to pan when scrolling, -1 for left, 1 for right */
|
|
||||||
let dir: -1 | 1 = 1;
|
|
||||||
const cursor = this.cursor + this.scrollCursor;
|
const cursor = this.cursor + this.scrollCursor;
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case Button.UP:
|
case Button.UP:
|
||||||
@ -306,20 +324,12 @@ export class AbstractSettingsUiHandler extends MessageUiHandler {
|
|||||||
success = successA && successB; // Indicates a successful cursor and scroll adjustment.
|
success = successA && successB; // Indicates a successful cursor and scroll adjustment.
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// biome-ignore lint/suspicious/noFallthroughSwitchClause: intentional
|
|
||||||
case Button.LEFT:
|
case Button.LEFT:
|
||||||
dir = -1;
|
success = this.processLeftRightInput(cursor, -1);
|
||||||
case Button.RIGHT: {
|
break;
|
||||||
let boundaryAction = Phaser.Math.Wrap;
|
case Button.RIGHT:
|
||||||
let upperBound = this.optionValueLabels[cursor].length;
|
success = this.processLeftRightInput(cursor, 1);
|
||||||
if (this.settings[cursor]?.clamp) {
|
|
||||||
boundaryAction = Phaser.Math.Clamp;
|
|
||||||
// clamping is right inclusive; wrapping isn't
|
|
||||||
upperBound -= 1;
|
|
||||||
}
|
|
||||||
success = this.setOptionCursor(cursor, boundaryAction(this.optionCursors[cursor] + dir, 0, upperBound), true);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case Button.CYCLE_FORM:
|
case Button.CYCLE_FORM:
|
||||||
case Button.CYCLE_SHINY:
|
case Button.CYCLE_SHINY:
|
||||||
success = this.navigationContainer.navigate(button);
|
success = this.navigationContainer.navigate(button);
|
||||||
|
Loading…
Reference in New Issue
Block a user