[Fix] implemented most code optimizations and callbacks to the modified locales folder

This commit is contained in:
Mikhail Shueb 2025-06-27 05:18:54 +01:00
parent 79ddcd4217
commit fde0a3f149
3 changed files with 36 additions and 42 deletions

View File

@ -2850,18 +2850,22 @@ export default class BattleScene extends SceneBase {
} }
return false; return false;
} }
/**
* Attempt to discard one or more copies of a held item.
* @param itemModifier - The {@linkcode PokemonHeldItemModifier} being discarded
* @param discardQuantity - The number of copies to remove (up to the amount currently held); default `1`
* @returns Whether the item was successfully discarded.
* Removing fewer items than requested is still considered a success.
*/
tryDiscardHeldItemModifier(itemModifier: PokemonHeldItemModifier, discardQuantity = 1): boolean { tryDiscardHeldItemModifier(itemModifier: PokemonHeldItemModifier, discardQuantity = 1): boolean {
const countTaken = Math.min(discardQuantity, itemModifier.stackCount); const countTaken = Math.min(discardQuantity, itemModifier.stackCount);
itemModifier.stackCount -= countTaken; itemModifier.stackCount -= countTaken;
const removeOld = itemModifier.stackCount === 0; if (itemModifier.stackCount > 0) {
return true;
if (removeOld) {
return this.removeModifier(itemModifier);
} }
return true; return this.removeModifier(itemModifier);
} }
canTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferQuantity = 1): boolean { canTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferQuantity = 1): boolean {

View File

@ -102,7 +102,7 @@ export enum PartyUiMode {
*/ */
SELECT, SELECT,
/** /**
* Indicates that the party UI is open to select a party member from which to discard an item from * Indicates that the party UI is open to select a party member from which items will be discarded.
* This type of selection can be cancelled. * This type of selection can be cancelled.
*/ */
DISCARD, DISCARD,
@ -159,7 +159,7 @@ export default class PartyUiHandler extends MessageUiHandler {
private partySlotsContainer: Phaser.GameObjects.Container; private partySlotsContainer: Phaser.GameObjects.Container;
private partySlots: PartySlot[]; private partySlots: PartySlot[];
private partyCancelButton: PartyCancelButton; private partyCancelButton: PartyCancelButton;
private PartyDiscardModeButton: PartyDiscardModeButton; private partyDiscardModeButton: PartyDiscardModeButton;
private partyMessageBox: Phaser.GameObjects.NineSlice; private partyMessageBox: Phaser.GameObjects.NineSlice;
private moveInfoOverlay: MoveInfoOverlay; private moveInfoOverlay: MoveInfoOverlay;
@ -317,7 +317,7 @@ export default class PartyUiHandler extends MessageUiHandler {
partyContainer.add(partyDiscardModeButton); partyContainer.add(partyDiscardModeButton);
this.PartyDiscardModeButton = partyDiscardModeButton; this.partyDiscardModeButton = partyDiscardModeButton;
// prepare move overlay. in case it appears to be too big, set the overlayScale to .5 // prepare move overlay. in case it appears to be too big, set the overlayScale to .5
const overlayScale = 1; const overlayScale = 1;
@ -367,7 +367,7 @@ export default class PartyUiHandler extends MessageUiHandler {
} }
this.populatePartySlots(); this.populatePartySlots();
this.PartyDiscardModeButton.toggleIcon(this.partyUiMode); this.partyDiscardModeButton.toggleIcon(this.partyUiMode);
this.setCursor(0); this.setCursor(0);
return true; return true;
@ -1013,7 +1013,7 @@ export default class PartyUiHandler extends MessageUiHandler {
ui.playError(); ui.playError();
break; break;
} }
this.PartyDiscardModeButton.toggleIcon(this.partyUiMode); this.partyDiscardModeButton.toggleIcon(this.partyUiMode);
ui.playSelect(); ui.playSelect();
} }
// Pressing return button // Pressing return button
@ -1036,7 +1036,7 @@ export default class PartyUiHandler extends MessageUiHandler {
this.clearTransfer(); this.clearTransfer();
ui.playSelect(); ui.playSelect();
} else if (this.allowCancel()) { } else if (this.allowCancel()) {
this.PartyDiscardModeButton.clear(); this.partyDiscardModeButton.clear();
if (this.selectCallback) { if (this.selectCallback) {
const selectCallback = this.selectCallback; const selectCallback = this.selectCallback;
this.selectCallback = null; this.selectCallback = null;
@ -1058,26 +1058,20 @@ export default class PartyUiHandler extends MessageUiHandler {
let success = false; let success = false;
switch (button) { switch (button) {
case Button.UP: case Button.UP:
if (this.cursor === 1) {
if (this.isItemManageMode()) { if (this.isItemManageMode()) {
if (this.cursor === 1) {
success = this.setCursor(globalScene.currentBattle.double ? 0 : 7); success = this.setCursor(globalScene.currentBattle.double ? 0 : 7);
break; break;
} }
}
if (this.cursor === 2) { if (this.cursor === 2) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double ? 7 : 1); success = this.setCursor(globalScene.currentBattle.double ? 7 : 1);
break; break;
} }
}
if (this.cursor === 6) { if (this.cursor === 6) {
if (this.isItemManageMode()) {
success = this.setCursor(slotCount <= globalScene.currentBattle.getBattlerCount() ? 7 : slotCount - 1); success = this.setCursor(slotCount <= globalScene.currentBattle.getBattlerCount() ? 7 : slotCount - 1);
break; break;
} }
}
if (this.cursor === 7) { if (this.cursor === 7) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double && slotCount > 1 ? 1 : 0); success = this.setCursor(globalScene.currentBattle.double && slotCount > 1 ? 1 : 0);
break; break;
} }
@ -1085,20 +1079,16 @@ export default class PartyUiHandler extends MessageUiHandler {
success = this.setCursor(this.cursor ? (this.cursor < 6 ? this.cursor - 1 : slotCount - 1) : 6); success = this.setCursor(this.cursor ? (this.cursor < 6 ? this.cursor - 1 : slotCount - 1) : 6);
break; break;
case Button.DOWN: case Button.DOWN:
if (this.cursor === 0) {
if (this.isItemManageMode()) { if (this.isItemManageMode()) {
if (this.cursor === 0) {
success = this.setCursor(globalScene.currentBattle.double && slotCount > 1 ? 1 : 7); success = this.setCursor(globalScene.currentBattle.double && slotCount > 1 ? 1 : 7);
break; break;
} }
}
if (this.cursor === 1) { if (this.cursor === 1) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double ? 7 : slotCount > 2 ? 2 : 6); success = this.setCursor(globalScene.currentBattle.double ? 7 : slotCount > 2 ? 2 : 6);
break; break;
} }
}
if (this.cursor === 7) { if (this.cursor === 7) {
if (this.isItemManageMode()) {
success = this.setCursor( success = this.setCursor(
slotCount > globalScene.currentBattle.getBattlerCount() ? globalScene.currentBattle.getBattlerCount() : 6, slotCount > globalScene.currentBattle.getBattlerCount() ? globalScene.currentBattle.getBattlerCount() : 6,
); );
@ -1170,14 +1160,14 @@ export default class PartyUiHandler extends MessageUiHandler {
} else if (this.lastCursor === 6) { } else if (this.lastCursor === 6) {
this.partyCancelButton.deselect(); this.partyCancelButton.deselect();
} else if (this.lastCursor === 7) { } else if (this.lastCursor === 7) {
this.PartyDiscardModeButton.deselect(); this.partyDiscardModeButton.deselect();
} }
if (cursor < 6) { if (cursor < 6) {
this.partySlots[cursor].select(); this.partySlots[cursor].select();
} else if (cursor === 6) { } else if (cursor === 6) {
this.partyCancelButton.select(); this.partyCancelButton.select();
} else if (cursor === 7) { } else if (cursor === 7) {
this.PartyDiscardModeButton.select(); this.partyDiscardModeButton.select();
} }
} }
return changed; return changed;

View File

@ -33,13 +33,13 @@ describe("UI - Transfer Items", () => {
{ name: "BERRY", count: 2, type: BerryType.APICOT }, { name: "BERRY", count: 2, type: BerryType.APICOT },
{ name: "BERRY", count: 2, type: BerryType.LUM }, { name: "BERRY", count: 2, type: BerryType.LUM },
]); ]);
game.override.moveset([MoveId.DRAGON_CLAW]); game.override.moveset(MoveId.DRAGON_CLAW);
game.override.enemySpecies(SpeciesId.MAGIKARP); game.override.enemySpecies(SpeciesId.MAGIKARP);
game.override.enemyMoveset([MoveId.SPLASH]); game.override.enemyMoveset(MoveId.SPLASH);
await game.classicMode.startBattle([SpeciesId.RAYQUAZA, SpeciesId.RAYQUAZA, SpeciesId.RAYQUAZA]); await game.classicMode.startBattle([SpeciesId.RAYQUAZA, SpeciesId.RAYQUAZA, SpeciesId.RAYQUAZA]);
game.move.select(MoveId.DRAGON_CLAW); game.move.use(MoveId.DRAGON_CLAW);
}); });
it("manage button exists in the proper screen", async () => { it("manage button exists in the proper screen", async () => {
@ -47,7 +47,7 @@ describe("UI - Transfer Items", () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(ModifierSelectUiHandler); expect(game.scene.ui.getHandler()).toBeInstanceOf(ModifierSelectUiHandler);
const handler = game.scene.ui.getHandler() as ModifierSelectUiHandler; const handler = game.scene.ui.getHandler() as ModifierSelectUiHandler;
handler.setCursor(1); //manage items menu, manage button should exist handler.setCursor(1); // Select/click manage items button
handler.processInput(Button.ACTION); handler.processInput(Button.ACTION);
void game.scene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.MODIFIER_TRANSFER); void game.scene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.MODIFIER_TRANSFER);
@ -55,19 +55,19 @@ describe("UI - Transfer Items", () => {
await game.phaseInterceptor.to("BattleEndPhase"); await game.phaseInterceptor.to("BattleEndPhase");
game.phaseInterceptor.addToNextPrompt("SelectModifierPhase", UiMode.PARTY, () => { game.onNextPrompt("SelectModifierPhase", UiMode.PARTY, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(PartyUiHandler); expect(game.scene.ui.getHandler()).toBeInstanceOf(PartyUiHandler);
const handler = game.scene.ui.getHandler() as PartyUiHandler; const handler = game.scene.ui.getHandler() as PartyUiHandler;
handler.processInput(Button.DOWN); handler.processInput(Button.DOWN);
handler.processInput(Button.ACTION); handler.processInput(Button.ACTION);
expect(handler.optionsContainer.list.length).toBe(0); //should select manage button,which has no menu expect(handler.optionsContainer.list).toHaveLength(0); // should select manage button, which has no menu
game.phaseInterceptor.unlock(); game.phaseInterceptor.unlock();
}); });
await game.phaseInterceptor.to("SelectModifierPhase"); await game.phaseInterceptor.to("SelectModifierPhase");
}, 20000); });
it("manage button doesn't exist in the other screens", async () => { it("manage button doesn't exist in the other screens", async () => {
game.onNextPrompt("SelectModifierPhase", UiMode.MODIFIER_SELECT, () => { game.onNextPrompt("SelectModifierPhase", UiMode.MODIFIER_SELECT, () => {
@ -94,5 +94,5 @@ describe("UI - Transfer Items", () => {
}); });
await game.phaseInterceptor.to("SelectModifierPhase"); await game.phaseInterceptor.to("SelectModifierPhase");
}, 20000); });
}); });