Changing options so that each case is completely separate (almost)

This commit is contained in:
Wlowscha 2025-05-14 09:30:59 +02:00
parent eba75dbfa3
commit ee4cb23c44
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04

View File

@ -440,6 +440,7 @@ export default class PartyUiHandler extends MessageUiHandler {
const ui = this.getUi(); const ui = this.getUi();
this.clearOptions(); this.clearOptions();
ui.playSelect(); ui.playSelect();
// TODO: Figure out how this edge case works
if (this.partyUiMode === PartyUiMode.RELEASE) { if (this.partyUiMode === PartyUiMode.RELEASE) {
this.doRelease(this.cursor); this.doRelease(this.cursor);
return true; return true;
@ -711,10 +712,10 @@ export default class PartyUiHandler extends MessageUiHandler {
if (option === PartyOption.RENAME) { if (option === PartyOption.RENAME) {
return this.processRenameOption(pokemon); return this.processRenameOption(pokemon);
} }
// TODO: Figure out why we need this edge case
if (option === PartyOption.RELEASE) { if (option === PartyOption.RELEASE) {
return this.processReleaseOption(pokemon); return this.processReleaseOption(pokemon);
} }
// TODO: Figure out better what this option is supposed to do---presumably we want a callback
if (option === PartyOption.SELECT) { if (option === PartyOption.SELECT) {
ui.playSelect(); ui.playSelect();
return true; return true;
@ -731,6 +732,19 @@ export default class PartyUiHandler extends MessageUiHandler {
this.clearOptions(); this.clearOptions();
} }
// For what modes is a selectCallback needed?
// PartyUiMode.SELECT
// PartyUiMode.RELEASE
// PartyUiMode.FAINT_SWITCH
// PartyUiMode.REVIVAL_BLESSING
// PartyUiMode.MODIFIER_TRANSFER
// PartyUiMode.CHECK
// PartyUiMode.SPLICE
// PartyUiMode.TM_MODIFIER
// PartyUiMode.REMEMBER_MOVE_MODIFIER
// PartyUiMode.MODIFIER
// PartyUiMode.POST_BATTLE_SWITCH
if (this.selectCallback) { if (this.selectCallback) {
if (option === PartyOption.TRANSFER) { if (option === PartyOption.TRANSFER) {
if (this.transferCursor !== this.cursor) { if (this.transferCursor !== this.cursor) {
@ -1097,6 +1111,7 @@ export default class PartyUiHandler extends MessageUiHandler {
} }
getItemModifiers(pokemon: Pokemon): PokemonHeldItemModifier[] { getItemModifiers(pokemon: Pokemon): PokemonHeldItemModifier[] {
// TODO: This conditional has no reason to be here
return this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER return this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER
? (globalScene.findModifiers( ? (globalScene.findModifiers(
m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === pokemon.id, m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === pokemon.id,
@ -1104,129 +1119,48 @@ export default class PartyUiHandler extends MessageUiHandler {
: []; : [];
} }
updateOptions(): void { updateOptionsWithRememberMoveModifierMode(pokemon): void {
const pokemon = globalScene.getPlayerParty()[this.cursor]; const learnableMoves = pokemon.getLearnableLevelMoves();
for (let m = 0; m < learnableMoves.length; m++) {
const learnableLevelMoves = this.options.push(m);
this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER ? pokemon.getLearnableLevelMoves() : []; }
if (learnableMoves?.length) {
if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER && learnableLevelMoves?.length) {
// show the move overlay with info for the first move // show the move overlay with info for the first move
this.moveInfoOverlay.show(allMoves[learnableLevelMoves[0]]); this.moveInfoOverlay.show(allMoves[learnableMoves[0]]);
} }
}
updateOptionsWithMoveModifierMode(pokemon): void {
// MOVE_1, MOVE_2, MOVE_3, MOVE_4
for (let m = 0; m < pokemon.moveset.length; m++) {
this.options.push(PartyOption.MOVE_1 + m);
}
}
updateOptionsWithModifierTransferMode(pokemon): void {
const itemModifiers = this.getItemModifiers(pokemon); const itemModifiers = this.getItemModifiers(pokemon);
for (let im = 0; im < itemModifiers.length; im++) {
if (this.options.length) { this.options.push(im);
this.options.splice(0, this.options.length);
this.optionsContainer.removeAll(true);
this.eraseOptionsCursor();
} }
if (itemModifiers.length > 1) {
this.options.push(PartyOption.ALL);
}
}
let formChangeItemModifiers: PokemonFormChangeItemModifier[] | undefined; addCommonOptions(pokemon): void {
this.options.push(PartyOption.SUMMARY);
this.options.push(PartyOption.POKEDEX);
this.options.push(PartyOption.RENAME);
if ( if (
this.partyUiMode !== PartyUiMode.MOVE_MODIFIER && pokemonEvolutions.hasOwnProperty(pokemon.species.speciesId) ||
this.partyUiMode !== PartyUiMode.REMEMBER_MOVE_MODIFIER && (pokemon.isFusion() && pokemon.fusionSpecies && pokemonEvolutions.hasOwnProperty(pokemon.fusionSpecies.speciesId))
(this.transferMode || this.partyUiMode !== PartyUiMode.MODIFIER_TRANSFER)
) { ) {
switch (this.partyUiMode) { this.options.push(PartyOption.UNPAUSE_EVOLUTION);
case PartyUiMode.SWITCH:
case PartyUiMode.FAINT_SWITCH:
case PartyUiMode.POST_BATTLE_SWITCH:
if (this.cursor >= globalScene.currentBattle.getBattlerCount()) {
const allowBatonModifierSwitch = this.allowBatonModifierSwitch();
const isBatonPassMove = this.isBatonPassMove();
// isBatonPassMove and allowBatonModifierSwitch shouldn't ever be true
// at the same time, because they both explicitly check for a mutually
// exclusive partyUiMode. But better safe than sorry.
this.options.push(
isBatonPassMove && !allowBatonModifierSwitch ? PartyOption.PASS_BATON : PartyOption.SEND_OUT,
);
if (allowBatonModifierSwitch && !isBatonPassMove) {
// the BATON modifier gives an extra switch option for
// pokemon-command switches, allowing buffs to be optionally passed
this.options.push(PartyOption.PASS_BATON);
}
}
break;
case PartyUiMode.REVIVAL_BLESSING:
this.options.push(PartyOption.REVIVE);
break;
case PartyUiMode.MODIFIER:
this.options.push(PartyOption.APPLY);
break;
case PartyUiMode.TM_MODIFIER:
this.options.push(PartyOption.TEACH);
break;
case PartyUiMode.MODIFIER_TRANSFER:
this.options.push(PartyOption.TRANSFER);
break;
case PartyUiMode.SPLICE:
if (this.transferMode) {
if (this.cursor !== this.transferCursor) {
this.options.push(PartyOption.SPLICE);
}
} else {
this.options.push(PartyOption.APPLY);
}
break;
case PartyUiMode.RELEASE:
this.options.push(PartyOption.RELEASE);
break;
case PartyUiMode.CHECK:
if (globalScene.getCurrentPhase() instanceof SelectModifierPhase) {
formChangeItemModifiers = this.getFormChangeItemsModifiers(pokemon);
for (let i = 0; i < formChangeItemModifiers.length; i++) {
this.options.push(PartyOption.FORM_CHANGE_ITEM + i);
}
}
break;
case PartyUiMode.SELECT:
this.options.push(PartyOption.SELECT);
break;
}
this.options.push(PartyOption.SUMMARY);
this.options.push(PartyOption.POKEDEX);
this.options.push(PartyOption.RENAME);
if (
pokemonEvolutions.hasOwnProperty(pokemon.species.speciesId) ||
(pokemon.isFusion() &&
pokemon.fusionSpecies &&
pokemonEvolutions.hasOwnProperty(pokemon.fusionSpecies.speciesId))
) {
this.options.push(PartyOption.UNPAUSE_EVOLUTION);
}
if (this.partyUiMode === PartyUiMode.SWITCH) {
if (pokemon.isFusion()) {
this.options.push(PartyOption.UNSPLICE);
}
this.options.push(PartyOption.RELEASE);
} else if (this.partyUiMode === PartyUiMode.SPLICE && pokemon.isFusion()) {
this.options.push(PartyOption.UNSPLICE);
}
} else if (this.partyUiMode === PartyUiMode.MOVE_MODIFIER) {
for (let m = 0; m < pokemon.moveset.length; m++) {
this.options.push(PartyOption.MOVE_1 + m);
}
} else if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) {
const learnableMoves = pokemon.getLearnableLevelMoves();
for (let m = 0; m < learnableMoves.length; m++) {
this.options.push(m);
}
} else {
for (let im = 0; im < itemModifiers.length; im++) {
this.options.push(im);
}
if (itemModifiers.length > 1) {
this.options.push(PartyOption.ALL);
}
} }
}
addCancelAndScrollOptions(): void {
this.optionsScrollTotal = this.options.length; this.optionsScrollTotal = this.options.length;
const optionStartIndex = this.optionsScrollCursor; const optionStartIndex = this.optionsScrollCursor;
const optionEndIndex = Math.min( const optionEndIndex = Math.min(
@ -1248,6 +1182,106 @@ export default class PartyUiHandler extends MessageUiHandler {
} }
this.options.push(PartyOption.CANCEL); this.options.push(PartyOption.CANCEL);
}
updateOptions(): void {
const pokemon = globalScene.getPlayerParty()[this.cursor];
if (this.options.length) {
this.options.splice(0, this.options.length);
this.optionsContainer.removeAll(true);
this.eraseOptionsCursor();
}
switch (this.partyUiMode) {
case PartyUiMode.MOVE_MODIFIER:
this.updateOptionsWithMoveModifierMode(pokemon);
break;
case PartyUiMode.REMEMBER_MOVE_MODIFIER:
this.updateOptionsWithRememberMoveModifierMode(pokemon);
break;
case PartyUiMode.MODIFIER_TRANSFER:
if (!this.transferMode) {
this.updateOptionsWithModifierTransferMode(pokemon);
} else {
this.options.push(PartyOption.TRANSFER);
this.addCommonOptions(pokemon);
}
break;
// TODO: This still needs to be broken up
case PartyUiMode.SWITCH:
case PartyUiMode.FAINT_SWITCH:
case PartyUiMode.POST_BATTLE_SWITCH:
if (this.cursor >= globalScene.currentBattle.getBattlerCount()) {
const allowBatonModifierSwitch = this.allowBatonModifierSwitch();
const isBatonPassMove = this.isBatonPassMove();
// isBatonPassMove and allowBatonModifierSwitch shouldn't ever be true
// at the same time, because they both explicitly check for a mutually
// exclusive partyUiMode. But better safe than sorry.
this.options.push(
isBatonPassMove && !allowBatonModifierSwitch ? PartyOption.PASS_BATON : PartyOption.SEND_OUT,
);
if (allowBatonModifierSwitch && !isBatonPassMove) {
// the BATON modifier gives an extra switch option for
// pokemon-command switches, allowing buffs to be optionally passed
this.options.push(PartyOption.PASS_BATON);
}
}
this.addCommonOptions(pokemon);
if (this.partyUiMode === PartyUiMode.SWITCH) {
if (pokemon.isFusion()) {
this.options.push(PartyOption.UNSPLICE);
}
this.options.push(PartyOption.RELEASE);
}
break;
case PartyUiMode.REVIVAL_BLESSING:
this.options.push(PartyOption.REVIVE);
this.addCommonOptions(pokemon);
break;
case PartyUiMode.MODIFIER:
this.options.push(PartyOption.APPLY);
this.addCommonOptions(pokemon);
break;
case PartyUiMode.TM_MODIFIER:
this.options.push(PartyOption.TEACH);
this.addCommonOptions(pokemon);
break;
case PartyUiMode.SPLICE:
if (this.transferMode) {
if (this.cursor !== this.transferCursor) {
this.options.push(PartyOption.SPLICE);
}
} else {
this.options.push(PartyOption.APPLY);
}
this.addCommonOptions(pokemon);
if (pokemon.isFusion()) {
this.options.push(PartyOption.UNSPLICE);
}
break;
case PartyUiMode.RELEASE:
this.options.push(PartyOption.RELEASE);
this.addCommonOptions(pokemon);
break;
case PartyUiMode.CHECK:
if (globalScene.getCurrentPhase() instanceof SelectModifierPhase) {
const formChangeItemModifiers = this.getFormChangeItemsModifiers(pokemon);
for (let i = 0; i < formChangeItemModifiers.length; i++) {
this.options.push(PartyOption.FORM_CHANGE_ITEM + i);
}
}
this.addCommonOptions(pokemon);
break;
case PartyUiMode.SELECT:
this.options.push(PartyOption.SELECT);
this.addCommonOptions(pokemon);
break;
}
// Generic, these are applied to all Modes
this.addCancelAndScrollOptions();
this.updateOptionsWindow(); this.updateOptionsWindow();
} }