Compare commits

...

24 Commits

Author SHA1 Message Date
thisPieonFire
84f458a36d
Merge f7f863070f into 1633df75c4 2025-08-05 19:25:12 -04:00
Sirz Benjie
1633df75c4
[UI/UX] Add change password ui (#5938)
* Add change password ui

* Ensure input fields are cleared after submit or cancel

* Play select sound on successful submission or cancel

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
Co-authored-by: Wlowscha <54003515+Wlowscha@users.noreply.github.com>
2025-08-05 16:35:58 -06:00
thisPieonFire
f7f863070f
Merge branch 'beta' into Court-Change-Additions 2025-08-04 10:15:33 +02:00
Dean
5085367b68
Merge branch 'beta' into Court-Change-Additions 2025-08-02 20:03:43 -07:00
NightKev
0ee8b43d1e
Merge branch 'beta' into Court-Change-Additions 2025-07-31 00:34:58 -07:00
thisPieonFire
36ec4c3d3c
Merge branch 'beta' into Court-Change-Additions 2025-07-30 10:29:50 +02:00
thisPieonFire
fcaba40c01
Update court-change.test.ts 2025-07-29 16:30:54 +02:00
thisPieonFire
274af155e8
Added missing import (ArenaTagSide) 2025-07-29 11:49:31 +02:00
thisPieonFire
ec37801904
Merge branch 'beta' into Court-Change-Additions 2025-07-29 11:20:11 +02:00
Bertie690
acc5254bcf
Added missing import 2025-07-28 11:53:58 -04:00
thisPieonFire
a96a315ac1
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 14:42:52 +02:00
thisPieonFire
d60e8c7178
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 14:42:41 +02:00
thisPieonFire
1afb805e9d
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 14:42:31 +02:00
thisPieonFire
4ae0d71c83
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 14:42:15 +02:00
thisPieonFire
ad1174a705
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 14:41:58 +02:00
thisPieonFire
d8ebd27a9b
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 14:41:40 +02:00
thisPieonFire
8bc44baa3a
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 14:41:26 +02:00
thisPieonFire
e120a43c28
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 14:41:03 +02:00
PieonFire
9126849713 Improve formatting in the "Court Change" move unit test 2025-07-08 11:47:53 +02:00
PieonFire
e5cbb55ef0 Merge remote-tracking branch 'origin/Court-Change-Additions' into Court-Change-Additions
# Conflicts:
#	test/moves/court-change.test.ts
2025-07-08 11:45:04 +02:00
PieonFire
9ec543881b Add unit test for the "Court Change" move 2025-07-08 11:39:17 +02:00
thisPieonFire
a5e7239d0e
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 11:21:05 +02:00
thisPieonFire
4b29be1221
Update test/moves/court-change.test.ts
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-07-08 11:20:02 +02:00
PieonFire
753a3fb31f Add unit test for the "Court Change" move 2025-07-07 14:16:08 +02:00
10 changed files with 272 additions and 9 deletions

View File

@ -15,3 +15,10 @@ export interface AccountRegisterRequest {
username: string; username: string;
password: string; password: string;
} }
export interface AccountChangePwRequest {
password: string;
}
export interface AccountChangePwResponse {
success: boolean;
}

View File

@ -10888,7 +10888,7 @@ export function initMoves() {
.attr(MovePowerMultiplierAttr, (_user, target) => target.turnData.acted ? 1 : 2) .attr(MovePowerMultiplierAttr, (_user, target) => target.turnData.acted ? 1 : 2)
.bitingMove(), .bitingMove(),
new StatusMove(MoveId.COURT_CHANGE, PokemonType.NORMAL, 100, 10, -1, 0, 8) new StatusMove(MoveId.COURT_CHANGE, PokemonType.NORMAL, 100, 10, -1, 0, 8)
.attr(SwapArenaTagsAttr, [ ArenaTagType.AURORA_VEIL, ArenaTagType.LIGHT_SCREEN, ArenaTagType.MIST, ArenaTagType.REFLECT, ArenaTagType.SPIKES, ArenaTagType.STEALTH_ROCK, ArenaTagType.STICKY_WEB, ArenaTagType.TAILWIND, ArenaTagType.TOXIC_SPIKES ]), .attr(SwapArenaTagsAttr, [ ArenaTagType.AURORA_VEIL, ArenaTagType.LIGHT_SCREEN, ArenaTagType.MIST, ArenaTagType.REFLECT, ArenaTagType.SPIKES, ArenaTagType.STEALTH_ROCK, ArenaTagType.STICKY_WEB, ArenaTagType.TAILWIND, ArenaTagType.TOXIC_SPIKES, ArenaTagType.SAFEGUARD, ArenaTagType.FIRE_GRASS_PLEDGE, ArenaTagType.WATER_FIRE_PLEDGE, ArenaTagType.GRASS_WATER_PLEDGE ]),
/* Unused */ /* Unused */
new AttackMove(MoveId.MAX_FLARE, PokemonType.FIRE, MoveCategory.PHYSICAL, 10, -1, 10, -1, 0, 8) new AttackMove(MoveId.MAX_FLARE, PokemonType.FIRE, MoveCategory.PHYSICAL, 10, -1, 10, -1, 0, 8)
.target(MoveTarget.NEAR_ENEMY) .target(MoveTarget.NEAR_ENEMY)

View File

@ -43,5 +43,6 @@ export enum UiMode {
TEST_DIALOGUE, TEST_DIALOGUE,
AUTO_COMPLETE, AUTO_COMPLETE,
ADMIN, ADMIN,
MYSTERY_ENCOUNTER MYSTERY_ENCOUNTER,
CHANGE_PASSWORD_FORM,
} }

View File

@ -1,6 +1,7 @@
import { ApiBase } from "#api/api-base"; import { ApiBase } from "#api/api-base";
import { SESSION_ID_COOKIE_NAME } from "#app/constants"; import { SESSION_ID_COOKIE_NAME } from "#app/constants";
import type { import type {
AccountChangePwRequest,
AccountInfoResponse, AccountInfoResponse,
AccountLoginRequest, AccountLoginRequest,
AccountLoginResponse, AccountLoginResponse,
@ -95,4 +96,19 @@ export class PokerogueAccountApi extends ApiBase {
removeCookie(SESSION_ID_COOKIE_NAME); // we are always clearing the cookie. removeCookie(SESSION_ID_COOKIE_NAME); // we are always clearing the cookie.
} }
public async changePassword(changePwData: AccountChangePwRequest) {
try {
const response = await this.doPost("/account/changepw", changePwData, "form-urlencoded");
if (response.ok) {
return null;
}
console.warn("Change password failed!", response.status, response.statusText);
return response.text();
} catch (err) {
console.warn("Change password failed!", err);
}
return "Unknown error!";
}
} }

View File

@ -0,0 +1,124 @@
import { globalScene } from "#app/global-scene";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import { UiMode } from "#enums/ui-mode";
import type { InputFieldConfig } from "#ui/form-modal-ui-handler";
import { FormModalUiHandler } from "#ui/form-modal-ui-handler";
import type { ModalConfig } from "#ui/modal-ui-handler";
import i18next from "i18next";
export class ChangePasswordFormUiHandler extends FormModalUiHandler {
private readonly ERR_PASSWORD: string = "invalid password";
private readonly ERR_ACCOUNT_EXIST: string = "account doesn't exist";
private readonly ERR_PASSWORD_MISMATCH: string = "password doesn't match";
constructor(mode: UiMode | null = null) {
super(mode);
}
setup(): void {
super.setup();
}
override getModalTitle(_config?: ModalConfig): string {
return i18next.t("menu:changePassword");
}
override getWidth(_config?: ModalConfig): number {
return 160;
}
override getMargin(_config?: ModalConfig): [number, number, number, number] {
return [0, 0, 48, 0];
}
override getButtonLabels(_config?: ModalConfig): string[] {
return [i18next.t("settings:buttonSubmit"), i18next.t("menu:cancel")];
}
override getReadableErrorMessage(error: string): string {
const colonIndex = error?.indexOf(":");
if (colonIndex > 0) {
error = error.slice(0, colonIndex);
}
switch (error) {
case this.ERR_PASSWORD:
return i18next.t("menu:invalidRegisterPassword");
case this.ERR_ACCOUNT_EXIST:
return i18next.t("menu:accountNonExistent");
case this.ERR_PASSWORD_MISMATCH:
return i18next.t("menu:passwordNotMatchingConfirmPassword");
}
return super.getReadableErrorMessage(error);
}
override getInputFieldConfigs(): InputFieldConfig[] {
const inputFieldConfigs: InputFieldConfig[] = [];
inputFieldConfigs.push({
label: i18next.t("menu:password"),
isPassword: true,
});
inputFieldConfigs.push({
label: i18next.t("menu:confirmPassword"),
isPassword: true,
});
return inputFieldConfigs;
}
override show(args: [ModalConfig, ...any]): boolean {
if (super.show(args)) {
const config = args[0];
const originalSubmitAction = this.submitAction;
this.submitAction = () => {
if (globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
// Prevent overlapping overrides on action modification
this.submitAction = originalSubmitAction;
this.sanitizeInputs();
globalScene.ui.setMode(UiMode.LOADING, { buttonActions: [] });
const onFail = (error: string | null) => {
globalScene.ui.setMode(UiMode.CHANGE_PASSWORD_FORM, Object.assign(config, { errorMessage: error?.trim() }));
globalScene.ui.playError();
};
const [passwordInput, confirmPasswordInput] = this.inputs;
if (!passwordInput?.text) {
return onFail(this.getReadableErrorMessage("invalid password"));
}
if (passwordInput.text !== confirmPasswordInput.text) {
return onFail(this.ERR_PASSWORD_MISMATCH);
}
pokerogueApi.account.changePassword({ password: passwordInput.text }).then(error => {
if (!error && originalSubmitAction) {
globalScene.ui.playSelect();
originalSubmitAction();
// Only clear inputs if the action was successful
for (const input of this.inputs) {
input.setText("");
}
} else {
onFail(error);
}
});
}
};
// Upon pressing cancel, the inputs should be cleared
const originalCancelAction = this.cancelAction;
this.cancelAction = () => {
globalScene.ui.playSelect();
for (const input of this.inputs) {
input.setText("");
}
originalCancelAction?.();
};
return true;
}
return false;
}
override clear() {
super.clear();
this.setMouseCursorStyle("default"); //reset cursor
}
}

View File

@ -19,6 +19,7 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
protected inputs: InputText[]; protected inputs: InputText[];
protected errorMessage: Phaser.GameObjects.Text; protected errorMessage: Phaser.GameObjects.Text;
protected submitAction: Function | null; protected submitAction: Function | null;
protected cancelAction: (() => void) | null;
protected tween: Phaser.Tweens.Tween; protected tween: Phaser.Tweens.Tween;
protected formLabels: Phaser.GameObjects.Text[]; protected formLabels: Phaser.GameObjects.Text[];
@ -126,22 +127,37 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
}); });
} }
show(args: any[]): boolean { override show(args: any[]): boolean {
if (super.show(args)) { if (super.show(args)) {
this.inputContainers.map(ic => ic.setVisible(true)); this.inputContainers.map(ic => ic.setVisible(true));
const config = args[0] as FormModalConfig; const config = args[0] as FormModalConfig;
this.submitAction = config.buttonActions.length ? config.buttonActions[0] : null; this.submitAction = config.buttonActions.length ? config.buttonActions[0] : null;
this.cancelAction = config.buttonActions[1] ?? null;
// #region: Override button pointerDown
// Override the pointerDown event for the buttonBgs to call the `submitAction` and `cancelAction`
// properties that we set above, allowing their behavior to change after this method terminates
// Some subclasses use this to add behavior to the submit and cancel action
if (this.buttonBgs.length) {
this.buttonBgs[0].off("pointerdown"); this.buttonBgs[0].off("pointerdown");
this.buttonBgs[0].on("pointerdown", () => { this.buttonBgs[0].on("pointerdown", () => {
if (this.submitAction && globalScene.tweens.getTweensOf(this.modalContainer).length === 0) { if (this.submitAction && globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
this.submitAction(); this.submitAction();
} }
}); });
const cancelBg = this.buttonBgs[1];
if (cancelBg) {
cancelBg.off("pointerdown");
cancelBg.on("pointerdown", () => {
// The seemingly redundant cancelAction check is intentionally left in as a defensive programming measure
if (this.cancelAction && globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
this.cancelAction();
} }
});
}
//#endregion: Override pointerDown events
this.modalContainer.y += 24; this.modalContainer.y += 24;
this.modalContainer.setAlpha(0); this.modalContainer.setAlpha(0);

View File

@ -311,6 +311,17 @@ export class MenuUiHandler extends MessageUiHandler {
}, },
keepOpen: true, keepOpen: true,
}, },
{
// Note: i18n key is under `menu`, not `menuUiHandler` to avoid duplication
label: i18next.t("menu:changePassword"),
handler: () => {
ui.setOverlayMode(UiMode.CHANGE_PASSWORD_FORM, {
buttonActions: [() => ui.revertMode(), () => ui.revertMode()],
});
return true;
},
keepOpen: true,
},
{ {
label: i18next.t("menuUiHandler:consentPreferences"), label: i18next.t("menuUiHandler:consentPreferences"),
handler: () => { handler: () => {

View File

@ -7,7 +7,7 @@ import { UiHandler } from "#ui/ui-handler";
import { addWindow, WindowVariant } from "#ui/ui-theme"; import { addWindow, WindowVariant } from "#ui/ui-theme";
export interface ModalConfig { export interface ModalConfig {
buttonActions: Function[]; buttonActions: ((...args: any[]) => any)[];
} }
export abstract class ModalUiHandler extends UiHandler { export abstract class ModalUiHandler extends UiHandler {

View File

@ -13,6 +13,7 @@ import { BallUiHandler } from "#ui/ball-ui-handler";
import { BattleMessageUiHandler } from "#ui/battle-message-ui-handler"; import { BattleMessageUiHandler } from "#ui/battle-message-ui-handler";
import type { BgmBar } from "#ui/bgm-bar"; import type { BgmBar } from "#ui/bgm-bar";
import { GameChallengesUiHandler } from "#ui/challenges-select-ui-handler"; import { GameChallengesUiHandler } from "#ui/challenges-select-ui-handler";
import { ChangePasswordFormUiHandler } from "#ui/change-password-form-ui-handler";
import { CommandUiHandler } from "#ui/command-ui-handler"; import { CommandUiHandler } from "#ui/command-ui-handler";
import { ConfirmUiHandler } from "#ui/confirm-ui-handler"; import { ConfirmUiHandler } from "#ui/confirm-ui-handler";
import { EggGachaUiHandler } from "#ui/egg-gacha-ui-handler"; import { EggGachaUiHandler } from "#ui/egg-gacha-ui-handler";
@ -102,6 +103,7 @@ const noTransitionModes = [
UiMode.ADMIN, UiMode.ADMIN,
UiMode.MYSTERY_ENCOUNTER, UiMode.MYSTERY_ENCOUNTER,
UiMode.RUN_INFO, UiMode.RUN_INFO,
UiMode.CHANGE_PASSWORD_FORM,
]; ];
export class UI extends Phaser.GameObjects.Container { export class UI extends Phaser.GameObjects.Container {
@ -172,6 +174,7 @@ export class UI extends Phaser.GameObjects.Container {
new AutoCompleteUiHandler(), new AutoCompleteUiHandler(),
new AdminUiHandler(), new AdminUiHandler(),
new MysteryEncounterUiHandler(), new MysteryEncounterUiHandler(),
new ChangePasswordFormUiHandler(),
]; ];
} }

View File

@ -0,0 +1,85 @@
import { AbilityId } from "#enums/ability-id";
import { ArenaTagSide } from "#enums/arena-tag-side";
import { ArenaTagType } from "#enums/arena-tag-type";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import { Stat } from "#enums/stat";
import { StatusEffect } from "#enums/status-effect";
import { GameManager } from "#test/test-utils/game-manager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Move - Court Change", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.ability(AbilityId.BALL_FETCH)
.criticalHits(false)
.enemyAbility(AbilityId.STURDY)
.startingLevel(100)
.battleStyle("single")
.enemySpecies(SpeciesId.MAGIKARP)
.enemyMoveset(MoveId.SPLASH);
});
it("should swap combined Pledge effects to the opposite side", async () => {
game.override.battleStyle("double");
await game.classicMode.startBattle([SpeciesId.REGIELEKI, SpeciesId.SHUCKLE]);
const regieleki = game.field.getPlayerPokemon();
const enemyPokemon = game.field.getEnemyPokemon();
game.move.use(MoveId.WATER_PLEDGE);
game.move.use(MoveId.GRASS_PLEDGE, 1);
await game.toNextTurn();
// enemy team will be in the swamp and slowed
expect(game.scene.arena.getTagOnSide(ArenaTagType.GRASS_WATER_PLEDGE, ArenaTagSide.ENEMY)).toBeDefined();
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBe(enemyPokemon.getStat(Stat.SPD) / 4);
game.move.use(MoveId.COURT_CHANGE);
game.move.use(MoveId.SPLASH, 1);
await game.toEndOfTurn();
// own team should now be in the swamp and slowed
expect(game.scene.arena.getTagOnSide(ArenaTagType.GRASS_WATER_PLEDGE, ArenaTagSide.ENEMY)).toBeUndefined();
expect(game.scene.arena.getTagOnSide(ArenaTagType.GRASS_WATER_PLEDGE, ArenaTagSide.PLAYER)).toBeDefined();
expect(regieleki.getEffectiveStat(Stat.SPD)).toBe(regieleki.getStat(Stat.SPD) / 4);
});
it("should swap safeguard to the enemy side ", async () => {
game.override.enemyMoveset(MoveId.TOXIC_THREAD);
await game.classicMode.startBattle([SpeciesId.NINJASK]);
const ninjask = game.field.getPlayerPokemon();
game.move.use(MoveId.SAFEGUARD);
await game.move.forceEnemyMove(MoveId.TOXIC_THREAD);
await game.toNextTurn();
// Ninjask will not be poisoned because of Safeguard
expect(game.scene.arena.getTagOnSide(ArenaTagType.SAFEGUARD, ArenaTagSide.PLAYER)).toBeDefined();
expect(ninjask.status?.effect).toBeUndefined();
game.move.use(MoveId.COURT_CHANGE);
await game.toEndOfTurn();
// Ninjask should now be poisoned due to lack of Safeguard
expect(game.scene.arena.getTagOnSide(ArenaTagType.SAFEGUARD, ArenaTagSide.PLAYER)).toBeUndefined();
expect(game.scene.arena.getTagOnSide(ArenaTagType.SAFEGUARD, ArenaTagSide.ENEMY)).toBeDefined();
expect(ninjask.status?.effect).toBe(StatusEffect.POISON);
});
});