pokerogue/src/ui/registration-form-ui-handler.ts

139 lines
4.7 KiB
TypeScript
Raw Normal View History

import type { InputFieldConfig } from "./form-modal-ui-handler";
import { FormModalUiHandler } from "./form-modal-ui-handler";
import type { ModalConfig } from "./modal-ui-handler";
2023-12-30 18:41:25 -05:00
import { Mode } from "./ui";
2024-04-18 19:08:53 -04:00
import { TextStyle, addTextObject } from "./text";
import i18next from "i18next";
[Refactor] Pokerogue API client (#4583) * start migrating Utils.apiFetch to api class * move dailyranking to api * use api in title-ui-handler * remove: Utils.apiFetch * migrate `updateSystemSavedata` to api * migrate clear session savedata to api * migrate updateAllSavedata to api * migrate `updateSessionSavedata` to api * rename `api` to `pokerogue-api` * migrate unlink discord to pokerogue-api * migrate unlink google to pokerogue-api * update pokerogue-api login * migrate register account to pokerogue-api * remove Utils.apiPost * reset overrides.ts * chore: cleanup * fix env.development * fix circular dependencies with api * fix gamedata verify missing await * fix daily api calls in daily-run-scorebard * fix discord-link request body being empty there was a double `toUrlSearchParams()` call involved * add pokerogue-api test coverge * add test-utils `getApiBaseUrl()` method * add pokerogue-admin-api test coverage * add pokerogue-account-api test coverage * add pokerogue-daily-api test coverage * add pokerogue-savedata-api test coverage * fix some test describes * add pokerogue-session-savedata-api test coverage * add pokerogue-system-savedata-api test coverage * fix tests * fix tryExportData thanks @MokaStitcher * chore: fix menu-ui-handlers.ts * fix admin-ui-handler (types) * extend test-coverage for admin-api * remove outdated code * skip some clowning-around-encounter tests if events are active this is not a permanent solution * Update src/system/game-data.ts Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Revert "skip some clowning-around-encounter tests if events are active" This reverts commit a97dafe8b2479e9b2ddd49d4dc9710814d7c7b67. * mark `localServerUrl` and `apiUrl` as deprecated in `utils.ts` --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com>
2024-11-04 12:57:21 -08:00
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import { globalScene } from "#app/global-scene";
2023-12-30 18:41:25 -05:00
interface LanguageSetting {
inputFieldFontSize?: string,
warningMessageFontSize?: string,
errorMessageFontSize?: string,
}
const languageSettings: { [key: string]: LanguageSetting } = {
"es-ES": {
inputFieldFontSize: "50px",
errorMessageFontSize: "40px",
}
};
2023-12-30 18:41:25 -05:00
export default class RegistrationFormUiHandler extends FormModalUiHandler {
getModalTitle(config?: ModalConfig): string {
return i18next.t("menu:register");
2023-12-30 18:41:25 -05:00
}
getWidth(config?: ModalConfig): number {
return 160;
}
getMargin(config?: ModalConfig): [number, number, number, number] {
return [ 0, 0, 48, 0 ];
}
2024-04-18 19:08:53 -04:00
getButtonTopMargin(): number {
return 8;
}
2023-12-30 18:41:25 -05:00
getButtonLabels(config?: ModalConfig): string[] {
return [ i18next.t("menu:register"), i18next.t("menu:backToLogin") ];
2023-12-30 18:41:25 -05:00
}
getReadableErrorMessage(error: string): string {
const colonIndex = error?.indexOf(":");
if (colonIndex > 0) {
2023-12-30 18:41:25 -05:00
error = error.slice(0, colonIndex);
}
2023-12-30 18:41:25 -05:00
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");
2023-12-30 18:41:25 -05:00
}
return super.getReadableErrorMessage(error);
}
[Misc] Add admin for (un)linking 3rd party accounts (#4198) * Updated admin panel to allow the concept of unlinking accounts * Don't look too hard at this commit, nothing to see here * Admin stuff * Fixed linking and unlinking and updated menu options * Undid some changes and cleaned up some code * Updated some logic and added some comments * Updates to admin panel logic * Stupid promises everyone hates them and they deserver to die * Promise stuff still * Promises working thanks to Ydarissep on discord - pushing with debug code before it decides to stop working again * Removed debugging code * All discord functionality seems to be working here?? Not sure what happened but yay * Fixed up some bugs and code * Added registered date to the panel * Fixed and updated some minor error message related stuff * Minor changes * Fixed some minor bugs, made the save related errors have error codes, and added updated icons * Updated search field error * Missed a couple of things to push * Fixed linting and doc errors * Revert dev related code and clean up dev comments * Reverting utils * Updating front end to match back end from Pancakes' comments * make getFields and getInputFieldConfigs a single function of FormUiHandler * remove outdated doc * Apply suggestions from code review Moka review changes Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> * Added docs * eslint fixes * Fixed error not showing up in certain conditions --------- Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> Co-authored-by: MokaStitcher <millennium.stitcher@gmail.com> Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> Co-authored-by: innerthunder <brandonerickson98@gmail.com>
2024-10-24 06:00:07 +10:00
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;
}
2024-04-18 19:08:53 -04:00
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 });
2024-04-18 19:08:53 -04:00
this.modalContainer.add(label);
}
2023-12-30 18:41:25 -05:00
show(args: any[]): boolean {
if (super.show(args)) {
const config = args[0] as ModalConfig;
const originalRegistrationAction = this.submitAction;
this.submitAction = (_) => {
// Prevent overlapping overrides on action modification
this.submitAction = originalRegistrationAction;
this.sanitizeInputs();
globalScene.ui.setMode(Mode.LOADING, { buttonActions: []});
2023-12-30 18:41:25 -05:00
const onFail = error => {
globalScene.ui.setMode(Mode.REGISTRATION_FORM, Object.assign(config, { errorMessage: error?.trim() }));
globalScene.ui.playError();
const errorMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.errorMessageFontSize;
if (errorMessageFontSize) {
this.errorMessage.setFontSize(errorMessageFontSize);
}
2023-12-30 18:41:25 -05:00
};
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"));
}
[Refactor] Pokerogue API client (#4583) * start migrating Utils.apiFetch to api class * move dailyranking to api * use api in title-ui-handler * remove: Utils.apiFetch * migrate `updateSystemSavedata` to api * migrate clear session savedata to api * migrate updateAllSavedata to api * migrate `updateSessionSavedata` to api * rename `api` to `pokerogue-api` * migrate unlink discord to pokerogue-api * migrate unlink google to pokerogue-api * update pokerogue-api login * migrate register account to pokerogue-api * remove Utils.apiPost * reset overrides.ts * chore: cleanup * fix env.development * fix circular dependencies with api * fix gamedata verify missing await * fix daily api calls in daily-run-scorebard * fix discord-link request body being empty there was a double `toUrlSearchParams()` call involved * add pokerogue-api test coverge * add test-utils `getApiBaseUrl()` method * add pokerogue-admin-api test coverage * add pokerogue-account-api test coverage * add pokerogue-daily-api test coverage * add pokerogue-savedata-api test coverage * fix some test describes * add pokerogue-session-savedata-api test coverage * add pokerogue-system-savedata-api test coverage * fix tests * fix tryExportData thanks @MokaStitcher * chore: fix menu-ui-handlers.ts * fix admin-ui-handler (types) * extend test-coverage for admin-api * remove outdated code * skip some clowning-around-encounter tests if events are active this is not a permanent solution * Update src/system/game-data.ts Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Revert "skip some clowning-around-encounter tests if events are active" This reverts commit a97dafe8b2479e9b2ddd49d4dc9710814d7c7b67. * mark `localServerUrl` and `apiUrl` as deprecated in `utils.ts` --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com>
2024-11-04 12:57:21 -08:00
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) {
[Refactor] use typescript `strict-null` (#3259) * TS: enable strict-null * fix battle-scene.ts * fix voucher.ts * adapt more files to strict-null * adapt more files to strict-null ( 2) * adapt ability.ts to strict-null * adapt `arena.ts` to strict-null * adapt TagAddedEvent constructor to strict-null * adapt phases.ts.to strict-null * adapt status-effect.ts to strict-null * adapt `account.ts` to strict-null * adapt `configHandler.ts` to strict-null * adapt `ability.ts` to strict-null * adapt `biomes.ts` to strict-null * adapt `challenge.ts` to strict-null * adapt `daily-run.ts` to strict-null * adapt `nature.ts` to strict-null * adapt `pokemon-forms.ts` to strict-null * adapt `tainer-names.ts` to strict-null * adapt `types.ts` to strict-null * adapt `weather.ts` to strict-null * adapt `egg-hatch-phase.ts` to strict-null * adapt `evolution-phase.ts` to strict-null * adapt `pokemon-sprite-sparkle-handler.ts` to strict-null * adapt `evolution-phase.ts` to strict-null * adapt `game-mode.ts` to strict-null * adapt `utils.ts` to strict-null * adapt `voucher-ui-handler.ts` to strict-null * adapt `src/ui/unavailable-modal-ui-handler.ts` to strict-null * adapt `src/ui/ui.ts` to strict-null * adapt `src/ui/ui-theme.ts` to strict-null * adapt `src/ui/title-ui-handler.ts` to strict-null * adapt `src/ui/time-of-day-widget.ts` to strict-null * adapt `src/ui/text.ts` to strict-null * adapt `src/ui/target-select-ui-handler.ts` to strict-null * adapt `src/ui/settings/settings-keyboard-ui-handler.ts` to strict-null * adapt more files to strict-null (3) * adapt more files to strict-null (4) * adapt more files (mostly tests) to strict-null (5) * adapt more files to strict-null (6) * adapt more files to strict-null (7) * Update `src/data/pokemon-evolutions.ts` for strict-null Partial update `src/data/pokemon-species.ts` for strict-null * adapt more files to strict-null (8) * adapt more files to strict-null (9) * Strict some more nulls (still a few errors remaining) * adapt rest of the files to strict-null (9) * fix tests (check for null instead of undefined) * repalce a lot of `??` with bangs And added TODO notice as usual * fix more tests * all tests pass now * fix broken game-loop after trainer battle add some console.warn for missing cases and falling back to default * remove guessed fallback from utils.rgbHexToRgba * add TODO for this.currentBattle = null * adjust getPokemonById() return to include `null` * fix compilation errors * add test for pokemon.trySetStatus * `chanceMultiplier` shouldn't be optional * allow `null` for currentPhase * adjust hasExpSprite logic for no keymatch found * reduce bang usage in account.updateUserInfo() * fix new strict-null issues after merge * fix `strict-null` issues in dropdown.ts and sand_spit.test.ts * fix egg-gacha * adapt gul_missile.test.ts to strict-null * fix move.ts strict-null * fix i18n.ts strict-null * fix strict-null issues * fix baton_pass test after accidentially breaking it * chore: fix compiler errors * revert accidential changes in baton_pass.test.ts --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2024-08-07 09:23:12 -07:00
originalRegistrationAction && originalRegistrationAction();
} else {
[Refactor] Pokerogue API client (#4583) * start migrating Utils.apiFetch to api class * move dailyranking to api * use api in title-ui-handler * remove: Utils.apiFetch * migrate `updateSystemSavedata` to api * migrate clear session savedata to api * migrate updateAllSavedata to api * migrate `updateSessionSavedata` to api * rename `api` to `pokerogue-api` * migrate unlink discord to pokerogue-api * migrate unlink google to pokerogue-api * update pokerogue-api login * migrate register account to pokerogue-api * remove Utils.apiPost * reset overrides.ts * chore: cleanup * fix env.development * fix circular dependencies with api * fix gamedata verify missing await * fix daily api calls in daily-run-scorebard * fix discord-link request body being empty there was a double `toUrlSearchParams()` call involved * add pokerogue-api test coverge * add test-utils `getApiBaseUrl()` method * add pokerogue-admin-api test coverage * add pokerogue-account-api test coverage * add pokerogue-daily-api test coverage * add pokerogue-savedata-api test coverage * fix some test describes * add pokerogue-session-savedata-api test coverage * add pokerogue-system-savedata-api test coverage * fix tests * fix tryExportData thanks @MokaStitcher * chore: fix menu-ui-handlers.ts * fix admin-ui-handler (types) * extend test-coverage for admin-api * remove outdated code * skip some clowning-around-encounter tests if events are active this is not a permanent solution * Update src/system/game-data.ts Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Revert "skip some clowning-around-encounter tests if events are active" This reverts commit a97dafe8b2479e9b2ddd49d4dc9710814d7c7b67. * mark `localServerUrl` and `apiUrl` as deprecated in `utils.ts` --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com>
2024-11-04 12:57:21 -08:00
onFail(loginError);
}
2023-12-30 18:41:25 -05:00
});
} else {
[Refactor] Pokerogue API client (#4583) * start migrating Utils.apiFetch to api class * move dailyranking to api * use api in title-ui-handler * remove: Utils.apiFetch * migrate `updateSystemSavedata` to api * migrate clear session savedata to api * migrate updateAllSavedata to api * migrate `updateSessionSavedata` to api * rename `api` to `pokerogue-api` * migrate unlink discord to pokerogue-api * migrate unlink google to pokerogue-api * update pokerogue-api login * migrate register account to pokerogue-api * remove Utils.apiPost * reset overrides.ts * chore: cleanup * fix env.development * fix circular dependencies with api * fix gamedata verify missing await * fix daily api calls in daily-run-scorebard * fix discord-link request body being empty there was a double `toUrlSearchParams()` call involved * add pokerogue-api test coverge * add test-utils `getApiBaseUrl()` method * add pokerogue-admin-api test coverage * add pokerogue-account-api test coverage * add pokerogue-daily-api test coverage * add pokerogue-savedata-api test coverage * fix some test describes * add pokerogue-session-savedata-api test coverage * add pokerogue-system-savedata-api test coverage * fix tests * fix tryExportData thanks @MokaStitcher * chore: fix menu-ui-handlers.ts * fix admin-ui-handler (types) * extend test-coverage for admin-api * remove outdated code * skip some clowning-around-encounter tests if events are active this is not a permanent solution * Update src/system/game-data.ts Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Revert "skip some clowning-around-encounter tests if events are active" This reverts commit a97dafe8b2479e9b2ddd49d4dc9710814d7c7b67. * mark `localServerUrl` and `apiUrl` as deprecated in `utils.ts` --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com>
2024-11-04 12:57:21 -08:00
onFail(registerError);
}
2023-12-30 18:41:25 -05:00
});
};
return true;
}
return false;
}
}