Simplified calls to revertSessionSlot + changed function name per feedback

This commit is contained in:
frutescens 2024-09-30 14:53:43 -07:00
parent 7baa626d00
commit a06057196e
2 changed files with 36 additions and 25 deletions

View File

@ -269,7 +269,7 @@ export default class RunInfoUiHandler extends UiHandler {
break; break;
} }
} else if (this.runInfo.battleType === BattleType.TRAINER) { } else if (this.runInfo.battleType === BattleType.TRAINER) {
this.loadTrainerSprites(enemyContainer); this.showTrainerSprites(enemyContainer);
const row_limit = 3; const row_limit = 3;
this.runInfo.enemyParty.forEach((p, i) => { this.runInfo.enemyParty.forEach((p, i) => {
const pokeball = this.scene.add.sprite(0, 0, "pb"); const pokeball = this.scene.add.sprite(0, 0, "pb");
@ -367,7 +367,7 @@ export default class RunInfoUiHandler extends UiHandler {
* Used by parseRunStatus and parseTrainerDefeat * Used by parseRunStatus and parseTrainerDefeat
* @param {Phaser.GameObjects.Container} enemyContainer a Phaser Container that should hold enemy sprites * @param {Phaser.GameObjects.Container} enemyContainer a Phaser Container that should hold enemy sprites
*/ */
private loadTrainerSprites(enemyContainer: Phaser.GameObjects.Container) { private showTrainerSprites(enemyContainer: Phaser.GameObjects.Container) {
// Creating the trainer sprite and adding it to enemyContainer // Creating the trainer sprite and adding it to enemyContainer
const tObj = this.runInfo.trainer.toTrainer(this.scene); const tObj = this.runInfo.trainer.toTrainer(this.scene);
// Loads trainer assets on demand, as they are not loaded by default in the scene // Loads trainer assets on demand, as they are not loaded by default in the scene
@ -413,8 +413,8 @@ export default class RunInfoUiHandler extends UiHandler {
* Party Pokemon have their icons, terastalization status, and level shown. * Party Pokemon have their icons, terastalization status, and level shown.
*/ */
private parseTrainerDefeat(enemyContainer: Phaser.GameObjects.Container) { private parseTrainerDefeat(enemyContainer: Phaser.GameObjects.Container) {
// Load trainer sprites // Loads and adds trainer sprites to the UI
this.loadTrainerSprites(enemyContainer); this.showTrainerSprites(enemyContainer);
// Determining which Terastallize Modifier belongs to which Pokemon // Determining which Terastallize Modifier belongs to which Pokemon
// Creates a dictionary {PokemonId: TeraShardType} // Creates a dictionary {PokemonId: TeraShardType}
const teraPokemon = {}; const teraPokemon = {};

View File

@ -153,24 +153,19 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
switch (button) { switch (button) {
case Button.UP: case Button.UP:
if (this.scrollCursor === 0 && this.cursor === 2) { if (this.scrollCursor === 0 && this.cursor === 2) {
this.revertSessionSlot(this.cursor); success = this.setScrollCursor(this.scrollCursor, this.cursor);
success = this.setScrollCursor(this.scrollCursor);
success = this.setCursor(this.cursor-1); success = this.setCursor(this.cursor-1);
} else if (this.cursor < 2) { } else if (this.cursor < 2) {
this.revertSessionSlot(this.cursor); success = (this.cursor === 0) ? this.setCursor(this.cursor) : this.setCursor(this.cursor - 1, this.cursor);
success = (this.cursor === 0) ? this.setCursor(this.cursor) : this.setCursor(this.cursor - 1);
} else if (this.scrollCursor) { } else if (this.scrollCursor) {
this.revertSessionSlot(this.scrollCursor + this.cursor); success = this.setScrollCursor(this.scrollCursor - 1, this.scrollCursor + this.cursor);
success = this.setScrollCursor(this.scrollCursor - 1);
} }
break; break;
case Button.DOWN: case Button.DOWN:
if (this.cursor < 2) { if (this.cursor < 2) {
this.revertSessionSlot(this.cursor); success = this.setCursor(this.cursor + 1, this.cursor);
success = this.setCursor(this.cursor + 1);
} else if (this.scrollCursor < sessionSlotCount - 3) { } else if (this.scrollCursor < sessionSlotCount - 3) {
this.revertSessionSlot(this.scrollCursor + this.cursor); success = this.setScrollCursor(this.scrollCursor + 1, this.scrollCursor + this.cursor);
success = this.setScrollCursor(this.scrollCursor + 1);
} }
break; break;
case Button.RIGHT: case Button.RIGHT:
@ -213,14 +208,13 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
this.saveSlotSelectMessageBoxContainer.setVisible(!!text?.length); this.saveSlotSelectMessageBoxContainer.setVisible(!!text?.length);
} }
revertSessionSlot(cursor: integer): void { /**
const sessionSlot = this.sessionSlots[cursor]; * setCursor takes user navigation as an input and positions the cursor accordingly
if (sessionSlot) { * @param cursor the index provided to the cursor
sessionSlot.setPosition(0, cursor * 56); * @param prevCursor the previous index occupied by the cursor - optional
} * @returns `true` if the cursor position has changed | `false` if it has not
} */
override setCursor(cursor: integer, prevCursor?: integer): boolean {
setCursor(cursor: integer): boolean {
const changed = super.setCursor(cursor); const changed = super.setCursor(cursor);
if (!this.cursorObj) { if (!this.cursorObj) {
@ -236,6 +230,8 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
const cursorIncrement = cursorPosition * 56; const cursorIncrement = cursorPosition * 56;
if (this.sessionSlots[cursorPosition] && this.cursorObj) { if (this.sessionSlots[cursorPosition] && this.cursorObj) {
const hasData = this.sessionSlots[cursorPosition].hasData; const hasData = this.sessionSlots[cursorPosition].hasData;
// If the session slot lacks session data, it does not move from its default, central position.
// Only session slots with session data will move leftwards and have a visible arrow.
if (!hasData) { if (!hasData) {
this.cursorObj.setPosition(151, 26 + cursorIncrement); this.cursorObj.setPosition(151, 26 + cursorIncrement);
this.sessionSlots[cursorPosition].setPosition(0, cursorIncrement); this.sessionSlots[cursorPosition].setPosition(0, cursorIncrement);
@ -245,26 +241,41 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
} }
this.setArrowVisibility(hasData); this.setArrowVisibility(hasData);
} }
if (!Utils.isNullOrUndefined(prevCursor)) {
this.revertSessionSlot(prevCursor);
}
return changed; return changed;
} }
/**
* Helper function that resets the session slot position to its default central position
* @param prevCursor the previous location of the cursor
*/
revertSessionSlot(prevCursor: integer): void {
const sessionSlot = this.sessionSlots[prevCursor];
if (sessionSlot) {
sessionSlot.setPosition(0, prevCursor * 56);
}
}
/** /**
* Helper function that checks if the session slot involved holds data or not * Helper function that checks if the session slot involved holds data or not
* @param hasData `true` if session slot contains data | 'false' if not * @param hasData `true` if session slot contains data | 'false' if not
*/ */
setArrowVisibility(hasData: boolean) { setArrowVisibility(hasData: boolean): void {
if (this.cursorObj) { if (this.cursorObj) {
const rightArrow = this.cursorObj?.getByName("rightArrow") as Phaser.GameObjects.Image; const rightArrow = this.cursorObj?.getByName("rightArrow") as Phaser.GameObjects.Image;
rightArrow.setVisible(hasData); rightArrow.setVisible(hasData);
} }
} }
setScrollCursor(scrollCursor: integer): boolean { setScrollCursor(scrollCursor: integer, priorCursor?: integer): boolean {
const changed = scrollCursor !== this.scrollCursor; const changed = scrollCursor !== this.scrollCursor;
if (changed) { if (changed) {
this.scrollCursor = scrollCursor; this.scrollCursor = scrollCursor;
this.setCursor(this.cursor); this.setCursor(this.cursor, priorCursor);
this.scene.tweens.add({ this.scene.tweens.add({
targets: this.sessionSlotsContainer, targets: this.sessionSlotsContainer,
y: this.sessionSlotsContainerInitialY - 56 * scrollCursor, y: this.sessionSlotsContainerInitialY - 56 * scrollCursor,