This commit is contained in:
Tiago Rodrigues 2025-06-20 06:11:47 +00:00 committed by GitHub
commit 12c763ea92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 599 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -0,0 +1,62 @@
{
"textures": [
{
"image": "party_discard.png",
"format": "RGBA8888",
"size": {
"w": 52,
"h": 32
},
"scale": 1,
"frames": [
{
"filename": "normal",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 52,
"h": 16
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
},
"frame": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
}
},
{
"filename": "selected",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 52,
"h": 16
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
},
"frame": {
"x": 0,
"y": 16,
"w": 52,
"h": 16
}
}
]
}
],
"meta": {
"app": "https://www.codeandweb.com/texturepacker",
"version": "3.0",
"smartupdate": "$TexturePacker:SmartUpdate:17219773dfffd6b1204d988fea3f9462:1127ad21d64bc7ebb9df4fc28f3d2d39:7ad46e8fb4648c3d3d84a746ecb371ea$"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

View File

@ -0,0 +1,62 @@
{
"textures": [
{
"image": "party_transfer.png",
"format": "RGBA8888",
"size": {
"w": 52,
"h": 32
},
"scale": 1,
"frames": [
{
"filename": "normal",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 52,
"h": 16
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
},
"frame": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
}
},
{
"filename": "selected",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 52,
"h": 16
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
},
"frame": {
"x": 0,
"y": 16,
"w": 52,
"h": 16
}
}
]
}
],
"meta": {
"app": "https://www.codeandweb.com/texturepacker",
"version": "3.0",
"smartupdate": "$TexturePacker:SmartUpdate:17219773dfffd6b1204d988fea3f9462:1127ad21d64bc7ebb9df4fc28f3d2d39:7ad46e8fb4648c3d3d84a746ecb371ea$"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -0,0 +1,62 @@
{
"textures": [
{
"image": "party_discard.png",
"format": "RGBA8888",
"size": {
"w": 75,
"h": 46
},
"scale": 1,
"frames": [
{
"filename": "normal",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 75,
"h": 23
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
},
"frame": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
}
},
{
"filename": "selected",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 75,
"h": 23
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
},
"frame": {
"x": 0,
"y": 23,
"w": 75,
"h": 23
}
}
]
}
],
"meta": {
"app": "https://www.codeandweb.com/texturepacker",
"version": "3.0",
"smartupdate": "$TexturePacker:SmartUpdate:17219773dfffd6b1204d988fea3f9462:1127ad21d64bc7ebb9df4fc28f3d2d39:7ad46e8fb4648c3d3d84a746ecb371ea$"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -0,0 +1,62 @@
{
"textures": [
{
"image": "party_transfer.png",
"format": "RGBA8888",
"size": {
"w": 75,
"h": 46
},
"scale": 1,
"frames": [
{
"filename": "normal",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 75,
"h": 23
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
},
"frame": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
}
},
{
"filename": "selected",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 75,
"h": 23
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
},
"frame": {
"x": 0,
"y": 23,
"w": 75,
"h": 23
}
}
]
}
],
"meta": {
"app": "https://www.codeandweb.com/texturepacker",
"version": "3.0",
"smartupdate": "$TexturePacker:SmartUpdate:17219773dfffd6b1204d988fea3f9462:1127ad21d64bc7ebb9df4fc28f3d2d39:7ad46e8fb4648c3d3d84a746ecb371ea$"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -2806,6 +2806,19 @@ export default class BattleScene extends SceneBase {
return false;
}
tryDiscardHeldItemModifier(itemModifier: PokemonHeldItemModifier, discardQuantity = 1): boolean {
const countTaken = Math.min(discardQuantity, itemModifier.stackCount);
itemModifier.stackCount -= countTaken;
const removeOld = itemModifier.stackCount === 0;
if (removeOld) {
return this.removeModifier(itemModifier);
}
return true;
}
canTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferQuantity = 1): boolean {
const mod = itemModifier.clone() as PokemonHeldItemModifier;
const source = mod.pokemonId ? mod.getPokemon() : null;

View File

@ -131,6 +131,7 @@ export class LoadingScene extends SceneBase {
this.loadImage("party_bg", "ui");
this.loadImage("party_bg_double", "ui");
this.loadImage("party_bg_double_manage", "ui");
this.loadAtlas("party_slot_main", "ui");
this.loadAtlas("party_slot", "ui");
this.loadImage("party_slot_overlay_lv", "ui");
@ -138,6 +139,8 @@ export class LoadingScene extends SceneBase {
this.loadAtlas("party_slot_hp_overlay", "ui");
this.loadAtlas("party_pb", "ui");
this.loadAtlas("party_cancel", "ui");
this.loadAtlas("party_discard", "ui");
this.loadAtlas("party_transfer", "ui");
this.loadImage("summary_bg", "ui");
this.loadImage("summary_overlay_shiny", "ui");

View File

@ -68,7 +68,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
if (context) {
context.font = styleOptions.fontSize + "px " + styleOptions.fontFamily;
this.transferButtonWidth = context.measureText(i18next.t("modifierSelectUiHandler:transfer")).width;
this.transferButtonWidth = context.measureText("Manage Items").width; // Missing "Manage Items" call from locales.
this.checkButtonWidth = context.measureText(i18next.t("modifierSelectUiHandler:checkTeam")).width;
}
@ -80,7 +80,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
this.transferButtonContainer.setVisible(false);
ui.add(this.transferButtonContainer);
const transferButtonText = addTextObject(-4, -2, i18next.t("modifierSelectUiHandler:transfer"), TextStyle.PARTY);
const transferButtonText = addTextObject(-4, -2, "Manage Items", TextStyle.PARTY); // Missing "Manage Items" call from locales.
transferButtonText.setName("text-transfer-btn");
transferButtonText.setOrigin(1, 0);
this.transferButtonContainer.add(transferButtonText);

View File

@ -101,6 +101,11 @@ export enum PartyUiMode {
* This is generally used in for Mystery Encounter or special effects that require the player to select a Pokemon
*/
SELECT,
/**
* Indicates that the party UI is open to select a party member from which to discard an item from
* This type of selection can be cancelled.
*/
DISCARD,
}
export enum PartyOption {
@ -119,6 +124,7 @@ export enum PartyOption {
RELEASE,
RENAME,
SELECT,
DISCARD,
SCROLL_UP = 1000,
SCROLL_DOWN = 1001,
FORM_CHANGE_ITEM = 2000,
@ -153,6 +159,7 @@ export default class PartyUiHandler extends MessageUiHandler {
private partySlotsContainer: Phaser.GameObjects.Container;
private partySlots: PartySlot[];
private partyCancelButton: PartyCancelButton;
private PartyDiscardModeButton: PartyDiscardModeButton;
private partyMessageBox: Phaser.GameObjects.NineSlice;
private moveInfoOverlay: MoveInfoOverlay;
@ -306,6 +313,12 @@ export default class PartyUiHandler extends MessageUiHandler {
this.iconAnimHandler = new PokemonIconAnimHandler();
this.iconAnimHandler.setup();
const partyDiscardModeButton = new PartyDiscardModeButton(60, -globalScene.game.canvas.height / 15 - 1);
partyContainer.add(partyDiscardModeButton);
this.PartyDiscardModeButton = partyDiscardModeButton;
// prepare move overlay. in case it appears to be too big, set the overlayScale to .5
const overlayScale = 1;
this.moveInfoOverlay = new MoveInfoOverlay({
@ -347,8 +360,14 @@ export default class PartyUiHandler extends MessageUiHandler {
this.showMovePp = args.length > 6 && args[6];
this.partyContainer.setVisible(true);
this.partyBg.setTexture(`party_bg${globalScene.currentBattle.double ? "_double" : ""}`);
if (this.isItemManageMode()) {
this.partyBg.setTexture(`party_bg${globalScene.currentBattle.double ? "_double_manage" : ""}`);
} else {
this.partyBg.setTexture(`party_bg${globalScene.currentBattle.double ? "_double" : ""}`);
}
this.populatePartySlots();
this.PartyDiscardModeButton.toggleIcon(this.partyUiMode);
this.setCursor(0);
return true;
@ -593,7 +612,7 @@ export default class PartyUiHandler extends MessageUiHandler {
const option = this.options[this.optionsCursor];
if (button === Button.LEFT) {
/** Decrease quantity for the current item and update UI */
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
if (this.isItemManageMode()) {
this.transferQuantities[option] =
this.transferQuantities[option] === 1
? this.transferQuantitiesMax[option]
@ -607,7 +626,7 @@ export default class PartyUiHandler extends MessageUiHandler {
if (button === Button.RIGHT) {
/** Increase quantity for the current item and update UI */
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
if (this.isItemManageMode()) {
this.transferQuantities[option] =
this.transferQuantities[option] === this.transferQuantitiesMax[option]
? 1
@ -637,6 +656,34 @@ export default class PartyUiHandler extends MessageUiHandler {
return success;
}
private processDiscardMenuInput(pokemon: PlayerPokemon) {
const ui = this.getUi();
this.clearOptions();
const itemModifiers = this.getTransferrableItemsFromPokemon(pokemon);
let success = true;
if (this.optionsCursor === itemModifiers.length) {
for (let i = 0; i < itemModifiers.length; i++) {
success = globalScene.tryDiscardHeldItemModifier(itemModifiers[i], this.transferQuantities[i]);
}
} else {
success = globalScene.tryDiscardHeldItemModifier(
itemModifiers[this.optionsCursor],
this.transferQuantities[this.optionsCursor],
);
}
if (success) {
this.showText("Item has been discarded.", undefined, () => this.showText("", 0), null, true); // missing confirm message call from i18next.t.
ui.playSelect();
} else {
ui.playError();
}
return success;
}
private moveOptionCursor(button: Button.UP | Button.DOWN): boolean {
if (button === Button.UP) {
return this.setCursor(this.optionsCursor ? this.optionsCursor - 1 : this.options.length - 1);
@ -723,6 +770,10 @@ export default class PartyUiHandler extends MessageUiHandler {
return this.processModifierTransferModeInput(pokemon);
}
if (this.partyUiMode === PartyUiMode.DISCARD) {
return this.processDiscardMenuInput(pokemon);
}
// options specific to the mode (moves)
if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) {
return this.processRememberMoveModeInput(pokemon);
@ -862,7 +913,7 @@ export default class PartyUiHandler extends MessageUiHandler {
}
if (button === Button.LEFT || button === Button.RIGHT) {
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
if (this.isItemManageMode()) {
return this.processModifierTransferModeLeftRightInput(button);
}
}
@ -917,10 +968,17 @@ export default class PartyUiHandler extends MessageUiHandler {
return !(this.partyUiMode === PartyUiMode.FAINT_SWITCH || this.partyUiMode === PartyUiMode.REVIVAL_BLESSING);
}
private isItemManageMode(): boolean {
return this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER || this.partyUiMode === PartyUiMode.DISCARD;
}
private processPartyActionInput(): boolean {
const ui = this.getUi();
if (this.cursor < 6) {
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && !this.transferMode) {
if (
(this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && !this.transferMode) ||
this.partyUiMode === PartyUiMode.DISCARD
) {
/** Initialize item quantities for the selected Pokemon */
const itemModifiers = globalScene.findModifiers(
m =>
@ -934,6 +992,24 @@ export default class PartyUiHandler extends MessageUiHandler {
this.showOptions();
ui.playSelect();
}
if (this.cursor === 7) {
switch (this.partyUiMode) {
case PartyUiMode.DISCARD:
this.partyUiMode = PartyUiMode.MODIFIER_TRANSFER;
ui.playSelect();
break;
case PartyUiMode.MODIFIER_TRANSFER:
this.partyUiMode = PartyUiMode.DISCARD;
ui.playSelect();
break;
default:
ui.playError();
break;
}
this.PartyDiscardModeButton.toggleIcon(this.partyUiMode);
ui.playSelect();
}
// Pressing return button
if (this.cursor === 6) {
if (!this.allowCancel()) {
@ -954,6 +1030,7 @@ export default class PartyUiHandler extends MessageUiHandler {
this.clearTransfer();
ui.playSelect();
} else if (this.allowCancel()) {
this.PartyDiscardModeButton.clear();
if (this.selectCallback) {
const selectCallback = this.selectCallback;
this.selectCallback = null;
@ -975,9 +1052,53 @@ export default class PartyUiHandler extends MessageUiHandler {
let success = false;
switch (button) {
case Button.UP:
if (this.cursor === 1) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double ? 0 : 7);
break;
}
}
if (this.cursor === 2) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double ? 7 : 1);
break;
}
}
if (this.cursor === 6) {
if (this.isItemManageMode()) {
success = this.setCursor(slotCount <= globalScene.currentBattle.getBattlerCount() ? 7 : slotCount - 1);
break;
}
}
if (this.cursor === 7) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double && slotCount > 1 ? 1 : 0);
break;
}
}
success = this.setCursor(this.cursor ? (this.cursor < 6 ? this.cursor - 1 : slotCount - 1) : 6);
break;
case Button.DOWN:
if (this.cursor === 0) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double && slotCount > 1 ? 1 : 7);
break;
}
}
if (this.cursor === 1) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double ? 7 : slotCount > 2 ? 2 : 6);
break;
}
}
if (this.cursor === 7) {
if (this.isItemManageMode()) {
success = this.setCursor(
slotCount > globalScene.currentBattle.getBattlerCount() ? globalScene.currentBattle.getBattlerCount() : 6,
);
break;
}
}
success = this.setCursor(this.cursor < 6 ? (this.cursor < slotCount - 1 ? this.cursor + 1 : 6) : 0);
break;
case Button.LEFT:
@ -986,7 +1107,7 @@ export default class PartyUiHandler extends MessageUiHandler {
}
break;
case Button.RIGHT:
if (slotCount === battlerCount) {
if ((this.cursor === 7 && this.isItemManageMode()) || slotCount === battlerCount) {
success = this.setCursor(6);
break;
}
@ -1042,11 +1163,15 @@ export default class PartyUiHandler extends MessageUiHandler {
this.partySlots[this.lastCursor].deselect();
} else if (this.lastCursor === 6) {
this.partyCancelButton.deselect();
} else if (this.lastCursor === 7) {
this.PartyDiscardModeButton.deselect();
}
if (cursor < 6) {
this.partySlots[cursor].select();
} else if (cursor === 6) {
this.partyCancelButton.select();
} else if (cursor === 7) {
this.PartyDiscardModeButton.select();
}
}
return changed;
@ -1141,14 +1266,16 @@ export default class PartyUiHandler extends MessageUiHandler {
optionsMessage = i18next.t("partyUiHandler:selectAnotherPokemonToSplice");
}
break;
case PartyUiMode.DISCARD:
optionsMessage = "Select a held item to discard.\nUse < and > to change quantity."; //Missing discard i18next.t call message
}
this.showText(optionsMessage, 0);
this.updateOptions();
/** When an item is being selected for transfer, the message box is taller as the message occupies two lines */
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
/** When an item is being selected for transfer or discard, the message box is taller as the message occupies two lines */
if (this.isItemManageMode()) {
this.partyMessageBox.setSize(262 - Math.max(this.optionsBg.displayWidth - 56, 0), 42);
} else {
this.partyMessageBox.setSize(262 - Math.max(this.optionsBg.displayWidth - 56, 0), 30);
@ -1274,6 +1401,9 @@ export default class PartyUiHandler extends MessageUiHandler {
this.addCommonOptions(pokemon);
}
break;
case PartyUiMode.DISCARD:
this.updateOptionsWithModifierTransferMode(pokemon);
break;
// TODO: This still needs to be broken up.
// It could use a rework differentiating different kind of switches
// to treat baton passing separately from switching on faint.
@ -1378,7 +1508,8 @@ export default class PartyUiHandler extends MessageUiHandler {
optionName = "↓";
} else if (
(this.partyUiMode !== PartyUiMode.REMEMBER_MOVE_MODIFIER &&
(this.partyUiMode !== PartyUiMode.MODIFIER_TRANSFER || this.transferMode)) ||
(this.partyUiMode !== PartyUiMode.MODIFIER_TRANSFER || this.transferMode) &&
this.partyUiMode !== PartyUiMode.DISCARD) ||
option === PartyOption.CANCEL
) {
switch (option) {
@ -1441,7 +1572,7 @@ export default class PartyUiHandler extends MessageUiHandler {
const itemModifiers = this.getItemModifiers(pokemon);
const itemModifier = itemModifiers[option];
if (
this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER &&
this.isItemManageMode() &&
this.transferQuantitiesMax[option] > 1 &&
!this.transferMode &&
itemModifier !== undefined &&
@ -1471,7 +1602,6 @@ export default class PartyUiHandler extends MessageUiHandler {
optionText.x = 15 - this.optionsBg.width;
}
}
startTransfer(): void {
this.transferMode = true;
this.transferCursor = this.cursor;
@ -1660,7 +1790,9 @@ class PartySlot extends Phaser.GameObjects.Container {
? -184 +
(globalScene.currentBattle.double ? -40 : 0) +
(28 + (globalScene.currentBattle.double ? 8 : 0)) * slotIndex
: -124 + (globalScene.currentBattle.double ? -8 : 0) + slotIndex * 64,
: partyUiMode === PartyUiMode.MODIFIER_TRANSFER
? -124 + (globalScene.currentBattle.double ? -20 : 0) + slotIndex * 55
: -124 + (globalScene.currentBattle.double ? -8 : 0) + slotIndex * 64,
);
this.slotIndex = slotIndex;
@ -1916,7 +2048,6 @@ class PartySlot extends Phaser.GameObjects.Container {
class PartyCancelButton extends Phaser.GameObjects.Container {
private selected: boolean;
private partyCancelBg: Phaser.GameObjects.Sprite;
private partyCancelPb: Phaser.GameObjects.Sprite;
@ -1925,7 +2056,6 @@ class PartyCancelButton extends Phaser.GameObjects.Container {
this.setup();
}
setup() {
const partyCancelBg = globalScene.add.sprite(0, 0, "party_cancel");
this.add(partyCancelBg);
@ -1963,3 +2093,94 @@ class PartyCancelButton extends Phaser.GameObjects.Container {
this.partyCancelPb.setFrame("party_pb");
}
}
class PartyDiscardModeButton extends Phaser.GameObjects.Container {
private selected: boolean;
private transferIcon: Phaser.GameObjects.Sprite;
private discardIcon: Phaser.GameObjects.Sprite;
private partyDiscardPb: Phaser.GameObjects.Sprite;
private textBox: Phaser.GameObjects.Text;
constructor(x: number, y: number) {
super(globalScene, x, y);
this.setup();
}
setup() {
this.transferIcon = globalScene.add.sprite(0, 0, "party_transfer");
this.discardIcon = globalScene.add.sprite(0, 0, "party_discard");
this.partyDiscardPb = globalScene.add.sprite(-20, 0, "party_pb");
this.textBox = addTextObject(-8, -7, i18next.t("partyUiHandler:TRANSFER"), TextStyle.PARTY);
this.add(this.transferIcon);
this.add(this.discardIcon);
this.add(this.partyDiscardPb);
this.add(this.textBox);
this.clear();
}
select() {
if (this.selected) {
return;
}
this.selected = true;
this.transferIcon.setFrame("selected");
this.discardIcon.setFrame("selected");
this.partyDiscardPb.setFrame("party_pb_sel");
}
deselect() {
if (!this.selected) {
return;
}
this.selected = false;
this.transferIcon.setFrame("normal");
this.discardIcon.setFrame("normal");
this.partyDiscardPb.setFrame("party_pb");
}
toggleIcon(partyMode: number) {
switch (partyMode) {
case PartyUiMode.DISCARD:
this.transferIcon.setVisible(true);
this.discardIcon.setVisible(false);
this.partyDiscardPb.setVisible(true);
this.textBox.setVisible(true);
this.textBox.setText(i18next.t("partyUiHandler:TRANSFER"));
this.setPosition(
globalScene.currentBattle.double ? 64 : 60,
globalScene.currentBattle.double ? -48 : -globalScene.game.canvas.height / 15 - 1,
);
this.transferIcon.displayWidth = this.textBox.text.length * 9 + 3;
break;
case PartyUiMode.MODIFIER_TRANSFER:
this.transferIcon.setVisible(false);
this.discardIcon.setVisible(true);
this.partyDiscardPb.setVisible(true);
this.textBox.setVisible(true);
this.textBox.setText("Discard");
this.setPosition(
globalScene.currentBattle.double ? 64 : 60,
globalScene.currentBattle.double ? -48 : -globalScene.game.canvas.height / 15 - 1,
);
this.discardIcon.displayWidth = this.textBox.text.length * 9 + 3;
break;
default:
return;
}
}
clear() {
this.transferIcon.setVisible(false);
this.discardIcon.setVisible(false);
this.textBox.setVisible(false);
this.partyDiscardPb.setVisible(false);
}
}

View File

@ -0,0 +1,98 @@
import { BerryType } from "#app/enums/berry-type";
import { Button } from "#app/enums/buttons";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
import PartyUiHandler, { PartyUiMode } from "#app/ui/party-ui-handler";
import { UiMode } from "#enums/ui-mode";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("UI - Transfer Items", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(async () => {
game = new GameManager(phaserGame);
game.override.battleStyle("single");
game.override.startingLevel(100);
game.override.startingWave(1);
game.override.startingHeldItems([
{ name: "BERRY", count: 1, type: BerryType.SITRUS },
{ name: "BERRY", count: 2, type: BerryType.APICOT },
{ name: "BERRY", count: 2, type: BerryType.LUM },
]);
game.override.moveset([MoveId.DRAGON_CLAW]);
game.override.enemySpecies(SpeciesId.MAGIKARP);
game.override.enemyMoveset([MoveId.SPLASH]);
await game.classicMode.startBattle([SpeciesId.RAYQUAZA, SpeciesId.RAYQUAZA, SpeciesId.RAYQUAZA]);
game.move.select(MoveId.DRAGON_CLAW);
});
it("manage button exists in the proper screen", async () => {
game.onNextPrompt("SelectModifierPhase", UiMode.MODIFIER_SELECT, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(ModifierSelectUiHandler);
const handler = game.scene.ui.getHandler() as ModifierSelectUiHandler;
handler.setCursor(1); //manage items menu, manage button should exist
handler.processInput(Button.ACTION);
void game.scene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.MODIFIER_TRANSFER);
});
await game.phaseInterceptor.to("BattleEndPhase");
game.phaseInterceptor.addToNextPrompt("SelectModifierPhase", UiMode.PARTY, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(PartyUiHandler);
const handler = game.scene.ui.getHandler() as PartyUiHandler;
handler.processInput(Button.DOWN);
handler.processInput(Button.ACTION);
expect(handler.optionsContainer.list.length).toBe(0); //should select manage button,which has no menu
game.phaseInterceptor.unlock();
});
await game.phaseInterceptor.to("SelectModifierPhase");
}, 20000);
it("manage button doesn't exist in the other screens", async () => {
game.onNextPrompt("SelectModifierPhase", UiMode.MODIFIER_SELECT, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(ModifierSelectUiHandler);
const handler = game.scene.ui.getHandler() as ModifierSelectUiHandler;
handler.setCursor(2); //check team menu,manage button shouldn't exist
handler.processInput(Button.ACTION);
void game.scene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.MODIFIER_TRANSFER);
});
await game.phaseInterceptor.to("BattleEndPhase");
game.phaseInterceptor.addToNextPrompt("SelectModifierPhase", UiMode.PARTY, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(PartyUiHandler);
const handler = game.scene.ui.getHandler() as PartyUiHandler;
handler.processInput(Button.DOWN);
handler.processInput(Button.ACTION);
expect(handler.optionsContainer.list.length).toBeGreaterThan(0); //should select a pokemon, which has at least the cancel option
game.phaseInterceptor.unlock();
});
await game.phaseInterceptor.to("SelectModifierPhase");
}, 20000);
});