mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-10 17:39:31 +02:00
Compare commits
4 Commits
7d0645f33a
...
d54accd048
Author | SHA1 | Date | |
---|---|---|---|
|
d54accd048 | ||
|
1a907c22bd | ||
|
83180002df | ||
|
1633df75c4 |
@ -15,3 +15,10 @@ export interface AccountRegisterRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface AccountChangePwRequest {
|
||||
password: string;
|
||||
}
|
||||
export interface AccountChangePwResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
@ -2115,8 +2115,8 @@ export class SlowStartTag extends AbilityBattlerTag {
|
||||
|
||||
export class HighestStatBoostTag extends AbilityBattlerTag {
|
||||
public declare readonly tagType: HighestStatBoostTagType;
|
||||
public stat: Stat;
|
||||
public multiplier: number;
|
||||
public stat: EffectiveStat = Stat.ATK;
|
||||
public multiplier = 1.3;
|
||||
|
||||
constructor(tagType: HighestStatBoostTagType, ability: AbilityId) {
|
||||
super(tagType, ability, BattlerTagLapseType.CUSTOM, 1);
|
||||
@ -2128,28 +2128,28 @@ export class HighestStatBoostTag extends AbilityBattlerTag {
|
||||
*/
|
||||
public override loadTag<T extends this>(source: BaseBattlerTag & Pick<T, "tagType" | "stat" | "multiplier">): void {
|
||||
super.loadTag(source);
|
||||
this.stat = source.stat as Stat;
|
||||
this.stat = source.stat;
|
||||
this.multiplier = source.multiplier;
|
||||
}
|
||||
|
||||
onAdd(pokemon: Pokemon): void {
|
||||
super.onAdd(pokemon);
|
||||
|
||||
let highestStat: EffectiveStat;
|
||||
EFFECTIVE_STATS.map(s =>
|
||||
pokemon.getEffectiveStat(s, undefined, undefined, undefined, undefined, undefined, undefined, undefined, true),
|
||||
).reduce((highestValue: number, value: number, i: number) => {
|
||||
if (value > highestValue) {
|
||||
highestStat = EFFECTIVE_STATS[i];
|
||||
return value;
|
||||
}
|
||||
return highestValue;
|
||||
}, 0);
|
||||
const highestStat = EFFECTIVE_STATS.reduce(
|
||||
(curr: [EffectiveStat, number], stat: EffectiveStat) => {
|
||||
const value = pokemon.getEffectiveStat(stat, undefined, undefined, true, true, true, false, true, true);
|
||||
if (value > curr[1]) {
|
||||
curr[0] = stat;
|
||||
curr[1] = value;
|
||||
}
|
||||
return curr;
|
||||
},
|
||||
[Stat.ATK, 0],
|
||||
)[0];
|
||||
|
||||
highestStat = highestStat!; // tell TS compiler it's defined!
|
||||
this.stat = highestStat;
|
||||
|
||||
this.multiplier = this.stat === Stat.SPD ? 1.5 : 1.3;
|
||||
this.multiplier = highestStat === Stat.SPD ? 1.5 : 1.3;
|
||||
globalScene.phaseManager.queueMessage(
|
||||
i18next.t("battlerTags:highestStatBoostOnAdd", {
|
||||
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
|
||||
@ -2614,7 +2614,7 @@ export class IceFaceBlockDamageTag extends FormBlockDamageTag {
|
||||
*/
|
||||
export class CommandedTag extends SerializableBattlerTag {
|
||||
public override readonly tagType = BattlerTagType.COMMANDED;
|
||||
public readonly tatsugiriFormKey: string;
|
||||
public readonly tatsugiriFormKey: string = "curly";
|
||||
|
||||
constructor(sourceId: number) {
|
||||
super(BattlerTagType.COMMANDED, BattlerTagLapseType.CUSTOM, 0, MoveId.NONE, sourceId);
|
||||
@ -2668,7 +2668,7 @@ export class StockpilingTag extends SerializableBattlerTag {
|
||||
super(BattlerTagType.STOCKPILING, BattlerTagLapseType.CUSTOM, 1, sourceMove);
|
||||
}
|
||||
|
||||
private onStatStagesChanged: StatStageChangeCallback = (_, statsChanged, statChanges) => {
|
||||
private onStatStagesChanged(_: Pokemon | null, statsChanged: BattleStat[], statChanges: number[]) {
|
||||
const defChange = statChanges[statsChanged.indexOf(Stat.DEF)] ?? 0;
|
||||
const spDefChange = statChanges[statsChanged.indexOf(Stat.SPDEF)] ?? 0;
|
||||
|
||||
@ -2678,7 +2678,11 @@ export class StockpilingTag extends SerializableBattlerTag {
|
||||
if (spDefChange) {
|
||||
this.statChangeCounts[Stat.SPDEF]++;
|
||||
}
|
||||
};
|
||||
|
||||
// Removed during bundling; used to ensure this method's signature retains parity
|
||||
// with the `StatStageChangeCallback` type.
|
||||
this.onStatStagesChanged satisfies StatStageChangeCallback;
|
||||
}
|
||||
|
||||
public override loadTag(
|
||||
source: BaseBattlerTag & Pick<StockpilingTag, "tagType" | "stockpiledCount" | "statChangeCounts">,
|
||||
@ -2718,7 +2722,7 @@ export class StockpilingTag extends SerializableBattlerTag {
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
this.onStatStagesChanged,
|
||||
this.onStatStagesChanged.bind(this),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -43,5 +43,6 @@ export enum UiMode {
|
||||
TEST_DIALOGUE,
|
||||
AUTO_COMPLETE,
|
||||
ADMIN,
|
||||
MYSTERY_ENCOUNTER
|
||||
MYSTERY_ENCOUNTER,
|
||||
CHANGE_PASSWORD_FORM,
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { ApiBase } from "#api/api-base";
|
||||
import { SESSION_ID_COOKIE_NAME } from "#app/constants";
|
||||
import type {
|
||||
AccountChangePwRequest,
|
||||
AccountInfoResponse,
|
||||
AccountLoginRequest,
|
||||
AccountLoginResponse,
|
||||
@ -95,4 +96,19 @@ export class PokerogueAccountApi extends ApiBase {
|
||||
|
||||
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!";
|
||||
}
|
||||
}
|
||||
|
124
src/ui/change-password-form-ui-handler.ts
Normal file
124
src/ui/change-password-form-ui-handler.ts
Normal 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
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
|
||||
protected inputs: InputText[];
|
||||
protected errorMessage: Phaser.GameObjects.Text;
|
||||
protected submitAction: Function | null;
|
||||
protected cancelAction: (() => void) | null;
|
||||
protected tween: Phaser.Tweens.Tween;
|
||||
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)) {
|
||||
this.inputContainers.map(ic => ic.setVisible(true));
|
||||
|
||||
const config = args[0] as FormModalConfig;
|
||||
|
||||
this.submitAction = config.buttonActions.length ? config.buttonActions[0] : null;
|
||||
this.cancelAction = config.buttonActions[1] ?? null;
|
||||
|
||||
if (this.buttonBgs.length) {
|
||||
this.buttonBgs[0].off("pointerdown");
|
||||
this.buttonBgs[0].on("pointerdown", () => {
|
||||
if (this.submitAction && globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
|
||||
this.submitAction();
|
||||
// #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
|
||||
|
||||
this.buttonBgs[0].off("pointerdown");
|
||||
this.buttonBgs[0].on("pointerdown", () => {
|
||||
if (this.submitAction && globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
|
||||
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.setAlpha(0);
|
||||
|
@ -311,6 +311,17 @@ export class MenuUiHandler extends MessageUiHandler {
|
||||
},
|
||||
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"),
|
||||
handler: () => {
|
||||
|
@ -7,7 +7,7 @@ import { UiHandler } from "#ui/ui-handler";
|
||||
import { addWindow, WindowVariant } from "#ui/ui-theme";
|
||||
|
||||
export interface ModalConfig {
|
||||
buttonActions: Function[];
|
||||
buttonActions: ((...args: any[]) => any)[];
|
||||
}
|
||||
|
||||
export abstract class ModalUiHandler extends UiHandler {
|
||||
|
@ -13,6 +13,7 @@ import { BallUiHandler } from "#ui/ball-ui-handler";
|
||||
import { BattleMessageUiHandler } from "#ui/battle-message-ui-handler";
|
||||
import type { BgmBar } from "#ui/bgm-bar";
|
||||
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 { ConfirmUiHandler } from "#ui/confirm-ui-handler";
|
||||
import { EggGachaUiHandler } from "#ui/egg-gacha-ui-handler";
|
||||
@ -102,6 +103,7 @@ const noTransitionModes = [
|
||||
UiMode.ADMIN,
|
||||
UiMode.MYSTERY_ENCOUNTER,
|
||||
UiMode.RUN_INFO,
|
||||
UiMode.CHANGE_PASSWORD_FORM,
|
||||
];
|
||||
|
||||
export class UI extends Phaser.GameObjects.Container {
|
||||
@ -172,6 +174,7 @@ export class UI extends Phaser.GameObjects.Container {
|
||||
new AutoCompleteUiHandler(),
|
||||
new AdminUiHandler(),
|
||||
new MysteryEncounterUiHandler(),
|
||||
new ChangePasswordFormUiHandler(),
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user