mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-21 09:09:19 +01:00
* Grabbed reverted changes from stuff
* Added version migrator for rage fist data + deepMergeSpriteData tests
* fixed formattign
* Fied a few
* Fixed constructor (maybe), moved deepCopy and deepMergeSpriteData to own file
`common.ts` is hella bloated so seems legit
* Moved empty moveset verification mapping thing to upgrade script bc i wanted to
* Fixed tests
* test added
* Fixed summondata being cleared inside summonPhase, removed `summonDataPrimer`
like seriously how come no-one checked this
* Fixed test
I forgot that we outsped and oneshot
* Fixed test
* huhjjjjjb
* Hopefully fixed bug
my sanity and homework are paying the price for this lol
* added commented out console.log statement
uncomment to see new berry data
* Fixed migrate script, re-added deprecated attributes out of necessity
* Fixed failing test by not trying to mock rng
* Fixed test
* Fixed tests
* Update ability.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update ability.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update overrides.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update berry-phase.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update encounter-phase.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update game-data.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update move-phase.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Added utility function `randSeedFloat`
basically just `Phaser.math.RND.realInRange(0, 1)`
* Applied review comments, cleaned up code a bit
* Removed unnecessary null checks for turnData and co.
I explicitly made them initialized by default for this very reason
* Added tests for Last Resort regarding moveHistory
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update battle-scene.ts
Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
* Update the-winstrate-challenge-encounter.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update ability.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update move.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update move.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update move.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update battle-anims.ts
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
* Update pokemon.ts comments
* Fixed a few outstanding issues with documentation
* Updated switch summon phase comment
* Re-added BattleSummonData as TempSummonData
* Hppefully fixed -1 sprite scale glitch
* Fixed comment
* Reveted `pokemon-forms.ts`
* Fuxed constructor
* fixed -1 bug
* Revert "Added utility function `randSeedFloat`"
This reverts commit 4c3447c851.
---------
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
156 lines
5.0 KiB
TypeScript
156 lines
5.0 KiB
TypeScript
import type { InputFieldConfig } from "./form-modal-ui-handler";
|
|
import { FormModalUiHandler } from "./form-modal-ui-handler";
|
|
import type { ModalConfig } from "./modal-ui-handler";
|
|
import { UiMode } from "#enums/ui-mode";
|
|
import { TextStyle, addTextObject } from "./text";
|
|
import i18next from "i18next";
|
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
|
import { globalScene } from "#app/global-scene";
|
|
|
|
interface LanguageSetting {
|
|
inputFieldFontSize?: string;
|
|
warningMessageFontSize?: string;
|
|
errorMessageFontSize?: string;
|
|
}
|
|
|
|
const languageSettings: { [key: string]: LanguageSetting } = {
|
|
"es-ES": {
|
|
inputFieldFontSize: "50px",
|
|
errorMessageFontSize: "40px",
|
|
},
|
|
};
|
|
|
|
export default class RegistrationFormUiHandler extends FormModalUiHandler {
|
|
getModalTitle(_config?: ModalConfig): string {
|
|
return i18next.t("menu:register");
|
|
}
|
|
|
|
getWidth(_config?: ModalConfig): number {
|
|
return 160;
|
|
}
|
|
|
|
getMargin(_config?: ModalConfig): [number, number, number, number] {
|
|
return [0, 0, 48, 0];
|
|
}
|
|
|
|
getButtonTopMargin(): number {
|
|
return 8;
|
|
}
|
|
|
|
getButtonLabels(_config?: ModalConfig): string[] {
|
|
return [i18next.t("menu:register"), i18next.t("menu:backToLogin")];
|
|
}
|
|
|
|
getReadableErrorMessage(error: string): string {
|
|
const colonIndex = error?.indexOf(":");
|
|
if (colonIndex > 0) {
|
|
error = error.slice(0, colonIndex);
|
|
}
|
|
switch (error) {
|
|
case "invalid username":
|
|
return i18next.t("menu:invalidRegisterUsername");
|
|
case "invalid password":
|
|
return i18next.t("menu:invalidRegisterPassword");
|
|
case "failed to add account record":
|
|
return i18next.t("menu:usernameAlreadyUsed");
|
|
}
|
|
|
|
return super.getReadableErrorMessage(error);
|
|
}
|
|
|
|
override getInputFieldConfigs(): InputFieldConfig[] {
|
|
const inputFieldConfigs: InputFieldConfig[] = [];
|
|
inputFieldConfigs.push({ label: i18next.t("menu:username") });
|
|
inputFieldConfigs.push({
|
|
label: i18next.t("menu:password"),
|
|
isPassword: true,
|
|
});
|
|
inputFieldConfigs.push({
|
|
label: i18next.t("menu:confirmPassword"),
|
|
isPassword: true,
|
|
});
|
|
return inputFieldConfigs;
|
|
}
|
|
|
|
setup(): void {
|
|
super.setup();
|
|
|
|
this.modalContainer.list.forEach((child: Phaser.GameObjects.GameObject) => {
|
|
if (child instanceof Phaser.GameObjects.Text && child !== this.titleText) {
|
|
const inputFieldFontSize = languageSettings[i18next.resolvedLanguage!]?.inputFieldFontSize;
|
|
if (inputFieldFontSize) {
|
|
child.setFontSize(inputFieldFontSize);
|
|
}
|
|
}
|
|
});
|
|
|
|
const warningMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.warningMessageFontSize ?? "42px";
|
|
const label = addTextObject(10, 87, i18next.t("menu:registrationAgeWarning"), TextStyle.TOOLTIP_CONTENT, {
|
|
fontSize: warningMessageFontSize,
|
|
});
|
|
|
|
this.modalContainer.add(label);
|
|
}
|
|
|
|
show(args: any[]): boolean {
|
|
if (super.show(args)) {
|
|
const config = args[0] as ModalConfig;
|
|
|
|
const originalRegistrationAction = this.submitAction;
|
|
this.submitAction = _ => {
|
|
if (globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
|
|
// Prevent overlapping overrides on action modification
|
|
this.submitAction = originalRegistrationAction;
|
|
this.sanitizeInputs();
|
|
globalScene.ui.setMode(UiMode.LOADING, { buttonActions: [] });
|
|
const onFail = error => {
|
|
globalScene.ui.setMode(UiMode.REGISTRATION_FORM, Object.assign(config, { errorMessage: error?.trim() }));
|
|
globalScene.ui.playError();
|
|
const errorMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.errorMessageFontSize;
|
|
if (errorMessageFontSize) {
|
|
this.errorMessage.setFontSize(errorMessageFontSize);
|
|
}
|
|
};
|
|
if (!this.inputs[0].text) {
|
|
return onFail(i18next.t("menu:emptyUsername"));
|
|
}
|
|
if (!this.inputs[1].text) {
|
|
return onFail(this.getReadableErrorMessage("invalid password"));
|
|
}
|
|
if (this.inputs[1].text !== this.inputs[2].text) {
|
|
return onFail(i18next.t("menu:passwordNotMatchingConfirmPassword"));
|
|
}
|
|
const [usernameInput, passwordInput] = this.inputs;
|
|
pokerogueApi.account
|
|
.register({
|
|
username: usernameInput.text,
|
|
password: passwordInput.text,
|
|
})
|
|
.then(registerError => {
|
|
if (!registerError) {
|
|
pokerogueApi.account
|
|
.login({
|
|
username: usernameInput.text,
|
|
password: passwordInput.text,
|
|
})
|
|
.then(loginError => {
|
|
if (!loginError) {
|
|
originalRegistrationAction?.();
|
|
} else {
|
|
onFail(loginError);
|
|
}
|
|
});
|
|
} else {
|
|
onFail(registerError);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|