mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-08 00:19:29 +02:00
Compare commits
6 Commits
2c921837b4
...
21284437de
Author | SHA1 | Date | |
---|---|---|---|
|
21284437de | ||
|
1633df75c4 | ||
|
92c42694cd | ||
|
3c44ce5ad0 | ||
|
740ce787f9 | ||
|
90c3a7ed89 |
BIN
public/images/logo_fake.png
Executable file
BIN
public/images/logo_fake.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
@ -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;
|
||||||
|
}
|
||||||
|
@ -94,3 +94,10 @@ export const AVERAGE_ENCOUNTERS_PER_RUN_TARGET = 12;
|
|||||||
* So anti-variance adds -15/256 to the spawn weight check for ME spawn.
|
* So anti-variance adds -15/256 to the spawn weight check for ME spawn.
|
||||||
*/
|
*/
|
||||||
export const ANTI_VARIANCE_WEIGHT_MODIFIER = 15;
|
export const ANTI_VARIANCE_WEIGHT_MODIFIER = 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The chance (out of 1) that a different title logo will show when the title screen is drawn.
|
||||||
|
* Inverted during April Fools (such that this becomes the chance for the _normal_ title logo is displayed).
|
||||||
|
* Default: `10000` (0.01%)
|
||||||
|
*/
|
||||||
|
export const FAKE_TITLE_LOGO_CHANCE = 10000;
|
||||||
|
@ -43,5 +43,6 @@ export enum UiMode {
|
|||||||
TEST_DIALOGUE,
|
TEST_DIALOGUE,
|
||||||
AUTO_COMPLETE,
|
AUTO_COMPLETE,
|
||||||
ADMIN,
|
ADMIN,
|
||||||
MYSTERY_ENCOUNTER
|
MYSTERY_ENCOUNTER,
|
||||||
|
CHANGE_PASSWORD_FORM,
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ export class LoadingScene extends SceneBase {
|
|||||||
|
|
||||||
this.loadImage("loading_bg", "arenas");
|
this.loadImage("loading_bg", "arenas");
|
||||||
this.loadImage("logo", "");
|
this.loadImage("logo", "");
|
||||||
|
this.loadImage("logo_fake", "");
|
||||||
|
|
||||||
// Load menu images
|
// Load menu images
|
||||||
this.loadAtlas("bg", "ui");
|
this.loadAtlas("bg", "ui");
|
||||||
|
@ -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!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,6 +397,16 @@ export class TimedEventManager {
|
|||||||
return timedEvents.some((te: TimedEvent) => this.isActive(te));
|
return timedEvents.some((te: TimedEvent) => this.isActive(te));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the current event is active and for April Fools.
|
||||||
|
* @returns Whether the April Fools event is currently active.
|
||||||
|
*/
|
||||||
|
isAprilFoolsActive(): boolean {
|
||||||
|
return timedEvents.some(
|
||||||
|
te => this.isActive(te) && te.hasOwnProperty("bannerKey") && te.bannerKey!.startsWith("aprf"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
activeEventHasBanner(): boolean {
|
activeEventHasBanner(): boolean {
|
||||||
const activeEvents = timedEvents.filter(te => this.isActive(te) && te.hasOwnProperty("bannerKey"));
|
const activeEvents = timedEvents.filter(te => this.isActive(te) && te.hasOwnProperty("bannerKey"));
|
||||||
return activeEvents.length > 0;
|
return activeEvents.length > 0;
|
||||||
|
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 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;
|
||||||
|
|
||||||
if (this.buttonBgs.length) {
|
// #region: Override button pointerDown
|
||||||
this.buttonBgs[0].off("pointerdown");
|
// Override the pointerDown event for the buttonBgs to call the `submitAction` and `cancelAction`
|
||||||
this.buttonBgs[0].on("pointerdown", () => {
|
// properties that we set above, allowing their behavior to change after this method terminates
|
||||||
if (this.submitAction && globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
|
// Some subclasses use this to add behavior to the submit and cancel action
|
||||||
this.submitAction();
|
|
||||||
|
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.y += 24;
|
||||||
this.modalContainer.setAlpha(0);
|
this.modalContainer.setAlpha(0);
|
||||||
|
@ -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: () => {
|
||||||
|
@ -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 {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { pokerogueApi } from "#api/pokerogue-api";
|
import { pokerogueApi } from "#api/pokerogue-api";
|
||||||
|
import { FAKE_TITLE_LOGO_CHANCE } from "#app/constants";
|
||||||
import { timedEventManager } from "#app/global-event-manager";
|
import { timedEventManager } from "#app/global-event-manager";
|
||||||
import { globalScene } from "#app/global-scene";
|
import { globalScene } from "#app/global-scene";
|
||||||
import { TimedEventDisplay } from "#app/timed-event-manager";
|
import { TimedEventDisplay } from "#app/timed-event-manager";
|
||||||
@ -41,7 +42,7 @@ export class TitleUiHandler extends OptionSelectUiHandler {
|
|||||||
this.titleContainer.setAlpha(0);
|
this.titleContainer.setAlpha(0);
|
||||||
ui.add(this.titleContainer);
|
ui.add(this.titleContainer);
|
||||||
|
|
||||||
const logo = globalScene.add.image(globalScene.game.canvas.width / 6 / 2, 8, "logo");
|
const logo = globalScene.add.image(globalScene.scaledCanvas.width / 2, 8, this.getLogo());
|
||||||
logo.setOrigin(0.5, 0);
|
logo.setOrigin(0.5, 0);
|
||||||
this.titleContainer.add(logo);
|
this.titleContainer.add(logo);
|
||||||
|
|
||||||
@ -186,4 +187,14 @@ export class TitleUiHandler extends OptionSelectUiHandler {
|
|||||||
ease: "Sine.easeInOut",
|
ease: "Sine.easeInOut",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the logo file path to load, with a 0.1% chance to use the fake logo instead.
|
||||||
|
* @returns The path to the image.
|
||||||
|
*/
|
||||||
|
private getLogo(): string {
|
||||||
|
// Invert spawn chances on april fools
|
||||||
|
const aprilFools = timedEventManager.isAprilFoolsActive();
|
||||||
|
return aprilFools === !!randInt(FAKE_TITLE_LOGO_CHANCE) ? "logo_fake" : "logo";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,12 +70,16 @@ export function padInt(value: number, length: number, padWith?: string): string
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random integer between min and min + range
|
* Returns a **completely unseeded** random integer between `min` and `min + range`.
|
||||||
* @param range The amount of possible numbers
|
* @param range - The amount of possible numbers to pick
|
||||||
* @param min The starting number
|
* @param min - The minimum number to pick; default `0`
|
||||||
|
* @returns A psuedo-random, unseeded integer within the interval [min, min+range].
|
||||||
|
* @remarks
|
||||||
|
* This should not be used for battles or other outwards-facing randomness;
|
||||||
|
* battles are intended to be seeded and deterministic.
|
||||||
*/
|
*/
|
||||||
export function randInt(range: number, min = 0): number {
|
export function randInt(range: number, min = 0): number {
|
||||||
if (range === 1) {
|
if (range <= 1) {
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
return Math.floor(Math.random() * range) + min;
|
return Math.floor(Math.random() * range) + min;
|
||||||
|
Loading…
Reference in New Issue
Block a user