From 77b754a7bb5d16d0f267ee700ef5ca188c641e24 Mon Sep 17 00:00:00 2001 From: Opaque02 <66582645+Opaque02@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:27:13 +1000 Subject: [PATCH] Fixed linting and doc errors --- src/ui/admin-ui-handler.ts | 59 +++++++++++++++----------- src/ui/form-modal-ui-handler.ts | 32 +++++++++----- src/ui/login-form-ui-handler.ts | 14 +++++- src/ui/registration-form-ui-handler.ts | 14 +++++- src/ui/rename-form-ui-handler.ts | 13 +++++- src/ui/test-dialogue-ui-handler.ts | 17 ++++++-- 6 files changed, 108 insertions(+), 41 deletions(-) diff --git a/src/ui/admin-ui-handler.ts b/src/ui/admin-ui-handler.ts index 8ab0074ae74..d4612cb0e35 100644 --- a/src/ui/admin-ui-handler.ts +++ b/src/ui/admin-ui-handler.ts @@ -2,7 +2,7 @@ import BattleScene from "#app/battle-scene"; import { ModalConfig } from "./modal-ui-handler"; import { Mode } from "./ui"; import * as Utils from "../utils"; -import { FormModalUiHandler } from "./form-modal-ui-handler"; +import { FormModalUiHandler, InputFieldConfigs } from "./form-modal-ui-handler"; import { Button } from "#app/enums/buttons"; import { TextStyle } from "./text"; @@ -41,13 +41,13 @@ export default class AdminUiHandler extends FormModalUiHandler { getFields(config?: ModalConfig): string[] { switch (this.adminMode) { case AdminMode.LINK: - return ["Username", "Discord ID"]; + return [ "Username", "Discord ID" ]; case AdminMode.SEARCH: - return ["Username"]; + return [ "Username" ]; case AdminMode.ADMIN: - return ["Username", "Discord ID", "Google ID", "Last played", "Registered"]; + return [ "Username", "Discord ID", "Google ID", "Last played", "Registered" ]; default: - return [""]; + return [ "" ]; } } @@ -56,22 +56,38 @@ export default class AdminUiHandler extends FormModalUiHandler { } getMargin(config?: ModalConfig): [number, number, number, number] { - return [0, 0, 0, 0]; + return [ 0, 0, 0, 0 ]; } getButtonLabels(config?: ModalConfig): string[] { switch (this.adminMode) { case AdminMode.LINK: - return ["Link Account", "Cancel"]; + return [ "Link Account", "Cancel" ]; case AdminMode.SEARCH: - return ["Find account", "Cancel"]; + return [ "Find account", "Cancel" ]; case AdminMode.ADMIN: - return ["Back to search", "Cancel"]; + return [ "Back to search", "Cancel" ]; default: - return ["Activate ADMIN", "Cancel"]; + return [ "Activate ADMIN", "Cancel" ]; } } + override getInputFieldConfigs(adminResult: AdminSearchInfo): InputFieldConfigs[] { + const inputFieldConfigs: InputFieldConfigs[] = []; + adminResult = adminResult ?? { username: "", discordId: "", googleId: "", lastLoggedIn: "", registered: "" }; + const adminKeys = Object.keys(adminResult); + const fields = this.getFields(); + const lockedFields: string[] = [ "username", "lastLoggedIn", "registered" ]; + fields.forEach((field, i) => { + const readOnly = (this.adminMode === AdminMode.ADMIN && (lockedFields.includes(adminKeys[i]) || adminResult[adminKeys[i]] !== "")); + inputFieldConfigs.push({ + label: field, + isReadOnly: readOnly + }); + }); + return inputFieldConfigs; + } + processInput(button: Button): boolean { if (button === Button.SUBMIT && this.submitAction) { this.submitAction(); @@ -89,7 +105,8 @@ export default class AdminUiHandler extends FormModalUiHandler { const fields = this.getFields(); const hasTitle = !!this.getModalTitle(); - this.updateFields(fields, hasTitle); + + this.updateFields(this.getInputFieldConfigs(this.adminResult), hasTitle); this.updateContainer(this.config); const labels = this.getButtonLabels(); @@ -114,10 +131,10 @@ export default class AdminUiHandler extends FormModalUiHandler { const adminSearchResult: AdminSearchInfo = this.convertInputsToAdmin(); // this converts the input texts into a single object for use later const validFields = this.areFieldsValid(this.adminMode); if (validFields.error) { - this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error + this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error return this.showMessage(validFields.errorMessage ?? "", adminSearchResult, true); } - this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); + this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); if (this.adminMode === AdminMode.LINK) { this.adminLinkUnlink(adminSearchResult, "discord", "link") .then(response => { @@ -160,12 +177,11 @@ export default class AdminUiHandler extends FormModalUiHandler { this.inputs[0].setText(adminResult.username); break; case AdminMode.ADMIN: - const lockedFields: string[] = ["username", "lastLoggedIn", "registered"]; Object.keys(adminResult).forEach((aR, i) => { this.inputs[i].setText(adminResult[aR]); if (aR === "discordId" || aR === "googleId") { const nineSlice = this.inputContainers[i].list.find(iC => iC.type === "NineSlice"); - const img = this.scene.add.image(this.inputContainers[i].x + nineSlice.width + this.buttonGap, this.inputContainers[i].y + (Math.floor(nineSlice.height / 2)), adminResult[aR] === "" ? "link_icon" : "unlink_icon"); + const img = this.scene.add.image(this.inputContainers[i].x + nineSlice!.width + this.buttonGap, this.inputContainers[i].y + (Math.floor(nineSlice!.height / 2)), adminResult[aR] === "" ? "link_icon" : "unlink_icon"); img.setName(`adminBtn_${aR}`); img.setOrigin(0.5, 0.5); //img.setScale(0.5); @@ -175,14 +191,14 @@ export default class AdminUiHandler extends FormModalUiHandler { const mode = adminResult[aR] === "" ? "link" : "unlink"; // this figures out if we're linking or unlinking a service const validFields = this.areFieldsValid(this.adminMode, service); if (validFields.error) { - this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error + this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error return this.showMessage(validFields.errorMessage ?? "", adminResult, true); } this.adminLinkUnlink(this.convertInputsToAdmin(), service, mode).then(response => { if (response.error) { return this.showMessage(response.errorType, adminResult, true); } else { - this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); + this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); this.adminSearch(adminResult) .then(response => { if (response.error) { @@ -196,11 +212,6 @@ export default class AdminUiHandler extends FormModalUiHandler { this.addInteractionHoverEffect(img); this.modalContainer.add(img); } - if (lockedFields.includes(aR) || adminResult[aR] !== "") { - this.inputs[i].setReadOnly(true); - } else { - this.inputs[i].setReadOnly(false); - } }); break; } @@ -311,7 +322,7 @@ export default class AdminUiHandler extends FormModalUiHandler { // this is used to remove the existing fields on the admin panel so they can be updated - const itemsToRemove: string[] = ["formLabel", "adminBtn"]; // this is the start of the names for each element we want to remove + const itemsToRemove: string[] = [ "formLabel", "adminBtn" ]; // this is the start of the names for each element we want to remove const removeArray: any[] = []; const mC = this.modalContainer.list; for (let i = mC.length - 1; i >= 0; i--) { @@ -320,7 +331,7 @@ export default class AdminUiHandler extends FormModalUiHandler { * It then also checks for any containers that are within this.modalContainer, and checks if any of its child elements are of type rexInputText * and if either of these conditions are met, the element is destroyed */ - if (itemsToRemove.some(iTR => mC[i].name.includes(iTR)) || (mC[i].type === "Container" && mC[i].list.find(m => m.type === "rexInputText"))) { + if (itemsToRemove.some(iTR => mC[i].name.includes(iTR)) || (mC[i].type === "Container" && (mC[i] as Phaser.GameObjects.Container).list.find(m => m.type === "rexInputText"))) { removeArray.push(mC[i]); } } diff --git a/src/ui/form-modal-ui-handler.ts b/src/ui/form-modal-ui-handler.ts index 39ce31f5d5c..0c0a2aa274c 100644 --- a/src/ui/form-modal-ui-handler.ts +++ b/src/ui/form-modal-ui-handler.ts @@ -5,7 +5,6 @@ import { TextStyle, addTextInputObject, addTextObject } from "./text"; import { WindowVariant, addWindow } from "./ui-theme"; import InputText from "phaser3-rex-plugins/plugins/inputtext"; import * as Utils from "../utils"; -import i18next from "i18next"; import { Button } from "#enums/buttons"; export interface FormModalConfig extends ModalConfig { @@ -32,6 +31,8 @@ export abstract class FormModalUiHandler extends ModalUiHandler { abstract getFields(): string[]; + abstract getInputFieldConfigs(args?: any): InputFieldConfigs[]; + getHeight(config?: ModalConfig): number { return 20 * this.getFields().length + (this.getModalTitle() ? 26 : 0) + ((config as FormModalConfig)?.errorMessage ? 12 : 0) + this.getButtonTopMargin() + 28; } @@ -47,27 +48,29 @@ export abstract class FormModalUiHandler extends ModalUiHandler { setup(): void { super.setup(); - const fields = this.getFields(); + //const fields = this.getFields(); + const config = this.getInputFieldConfigs(); const hasTitle = !!this.getModalTitle(); - if (fields.length > 1 && fields[0]!=="") { - this.updateFields(fields, hasTitle); + if (config.length >= 1) { + this.updateFields(config, hasTitle); } - this.errorMessage = addTextObject(this.scene, 10, (hasTitle ? 31 : 5) + 20 * (fields.length - 1) + 16 + this.getButtonTopMargin(), "", TextStyle.TOOLTIP_CONTENT); + this.errorMessage = addTextObject(this.scene, 10, (hasTitle ? 31 : 5) + 20 * (config.length - 1) + 16 + this.getButtonTopMargin(), "", TextStyle.TOOLTIP_CONTENT); this.errorMessage.setColor(this.getTextColor(TextStyle.SUMMARY_PINK)); this.errorMessage.setShadowColor(this.getTextColor(TextStyle.SUMMARY_PINK, true)); this.errorMessage.setVisible(false); this.modalContainer.add(this.errorMessage); } - updateFields(fields: string[], hasTitle: boolean) { + //updateFields(fields: string[], hasTitle: boolean) { + updateFields(fieldsConfig: InputFieldConfigs[], hasTitle: boolean) { this.inputContainers = []; this.inputs = []; - this.formLabels= []; - fields.forEach((field, f) => { - const label = addTextObject(this.scene, 10, (hasTitle ? 31 : 5) + 20 * f, field, TextStyle.TOOLTIP_CONTENT); + this.formLabels = []; + fieldsConfig.forEach((config, f) => { + const label = addTextObject(this.scene, 10, (hasTitle ? 31 : 5) + 20 * f, config.label, TextStyle.TOOLTIP_CONTENT); label.name = "formLabel" + f; this.formLabels.push(label); @@ -78,8 +81,9 @@ export abstract class FormModalUiHandler extends ModalUiHandler { const inputBg = addWindow(this.scene, 0, 0, 80, 16, false, false, 0, 0, WindowVariant.XTHIN); - const isPassword = field.includes(i18next.t("menu:password")) || field.includes(i18next.t("menu:confirmPassword")); - const input = addTextInputObject(this.scene, 4, -2, 440, 116, TextStyle.TOOLTIP_CONTENT, { type: isPassword ? "password" : "text", maxLength: isPassword ? 64 : 20 }); + const isPassword = config?.isPassword; + const isReadOnly = config?.isReadOnly; + const input = addTextInputObject(this.scene, 4, -2, 440, 116, TextStyle.TOOLTIP_CONTENT, { type: isPassword ? "password" : "text", maxLength: isPassword ? 64 : 20, readOnly: isReadOnly }); input.setOrigin(0, 0); inputContainer.add(inputBg); @@ -163,3 +167,9 @@ export abstract class FormModalUiHandler extends ModalUiHandler { } } } + +export interface InputFieldConfigs { + label: string, + isPassword?: boolean, + isReadOnly?: boolean +} diff --git a/src/ui/login-form-ui-handler.ts b/src/ui/login-form-ui-handler.ts index 7d473ece641..45b67fa490a 100644 --- a/src/ui/login-form-ui-handler.ts +++ b/src/ui/login-form-ui-handler.ts @@ -1,4 +1,4 @@ -import { FormModalUiHandler } from "./form-modal-ui-handler"; +import { FormModalUiHandler, InputFieldConfigs } from "./form-modal-ui-handler"; import { ModalConfig } from "./modal-ui-handler"; import * as Utils from "../utils"; import { Mode } from "./ui"; @@ -114,6 +114,18 @@ export default class LoginFormUiHandler extends FormModalUiHandler { return super.getReadableErrorMessage(error); } + override getInputFieldConfigs(): InputFieldConfigs[] { + const inputFieldConfigs: InputFieldConfigs[] = []; + const fields = this.getFields(); + fields.forEach((field, i) => { + inputFieldConfigs.push({ + label: field, + isPassword: field.includes(i18next.t("menu:password")) || field.includes(i18next.t("menu:confirmPassword")) + }); + }); + return inputFieldConfigs; + } + override show(args: any[]): boolean { if (super.show(args)) { diff --git a/src/ui/registration-form-ui-handler.ts b/src/ui/registration-form-ui-handler.ts index c94d060c0b7..0cf50e7d55c 100644 --- a/src/ui/registration-form-ui-handler.ts +++ b/src/ui/registration-form-ui-handler.ts @@ -1,4 +1,4 @@ -import { FormModalUiHandler } from "./form-modal-ui-handler"; +import { FormModalUiHandler, InputFieldConfigs } from "./form-modal-ui-handler"; import { ModalConfig } from "./modal-ui-handler"; import * as Utils from "../utils"; import { Mode } from "./ui"; @@ -61,6 +61,18 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler { return super.getReadableErrorMessage(error); } + override getInputFieldConfigs(): InputFieldConfigs[] { + const inputFieldConfigs: InputFieldConfigs[] = []; + const fields = this.getFields(); + fields.forEach((field, i) => { + inputFieldConfigs.push({ + label: field, + isPassword: field.includes(i18next.t("menu:password")) || field.includes(i18next.t("menu:confirmPassword")) + }); + }); + return inputFieldConfigs; + } + setup(): void { super.setup(); diff --git a/src/ui/rename-form-ui-handler.ts b/src/ui/rename-form-ui-handler.ts index 078177cafb1..2c97d8a03a1 100644 --- a/src/ui/rename-form-ui-handler.ts +++ b/src/ui/rename-form-ui-handler.ts @@ -1,4 +1,4 @@ -import { FormModalUiHandler } from "./form-modal-ui-handler"; +import { FormModalUiHandler, InputFieldConfigs } from "./form-modal-ui-handler"; import { ModalConfig } from "./modal-ui-handler"; import i18next from "i18next"; import { PlayerPokemon } from "#app/field/pokemon"; @@ -33,6 +33,17 @@ export default class RenameFormUiHandler extends FormModalUiHandler { return super.getReadableErrorMessage(error); } + override getInputFieldConfigs(): InputFieldConfigs[] { + const inputFieldConfigs: InputFieldConfigs[] = []; + const fields = this.getFields(); + fields.forEach((field, i) => { + inputFieldConfigs.push({ + label: field + }); + }); + return inputFieldConfigs; + } + show(args: any[]): boolean { if (super.show(args)) { const config = args[0] as ModalConfig; diff --git a/src/ui/test-dialogue-ui-handler.ts b/src/ui/test-dialogue-ui-handler.ts index 17efd928180..9c639048e2d 100644 --- a/src/ui/test-dialogue-ui-handler.ts +++ b/src/ui/test-dialogue-ui-handler.ts @@ -1,4 +1,4 @@ -import { FormModalUiHandler } from "./form-modal-ui-handler"; +import { FormModalUiHandler, InputFieldConfigs } from "./form-modal-ui-handler"; import { ModalConfig } from "./modal-ui-handler"; import i18next from "i18next"; import { PlayerPokemon } from "#app/field/pokemon"; @@ -68,11 +68,22 @@ export default class TestDialogueUiHandler extends FormModalUiHandler { return super.getReadableErrorMessage(error); } + override getInputFieldConfigs(): InputFieldConfigs[] { + const inputFieldConfigs: InputFieldConfigs[] = []; + const fields = this.getFields(); + fields.forEach((field, i) => { + inputFieldConfigs.push({ + label: field + }); + }); + return inputFieldConfigs; + } + show(args: any[]): boolean { const ui = this.getUi(); - const fields = this.getFields(); + //const fields = this.getFields(); const hasTitle = !!this.getModalTitle(); - this.updateFields(fields, hasTitle); + this.updateFields(this.getInputFieldConfigs(), hasTitle); this.updateContainer(args[0] as ModalConfig); const input = this.inputs[0]; input.setMaxLength(255);