Fixed linting and doc errors

This commit is contained in:
Opaque02 2024-10-15 13:27:13 +10:00
parent 4999b34de2
commit 77b754a7bb
6 changed files with 108 additions and 41 deletions

View File

@ -2,7 +2,7 @@ import BattleScene from "#app/battle-scene";
import { ModalConfig } from "./modal-ui-handler"; import { ModalConfig } from "./modal-ui-handler";
import { Mode } from "./ui"; import { Mode } from "./ui";
import * as Utils from "../utils"; 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 { Button } from "#app/enums/buttons";
import { TextStyle } from "./text"; import { TextStyle } from "./text";
@ -41,13 +41,13 @@ export default class AdminUiHandler extends FormModalUiHandler {
getFields(config?: ModalConfig): string[] { getFields(config?: ModalConfig): string[] {
switch (this.adminMode) { switch (this.adminMode) {
case AdminMode.LINK: case AdminMode.LINK:
return ["Username", "Discord ID"]; return [ "Username", "Discord ID" ];
case AdminMode.SEARCH: case AdminMode.SEARCH:
return ["Username"]; return [ "Username" ];
case AdminMode.ADMIN: case AdminMode.ADMIN:
return ["Username", "Discord ID", "Google ID", "Last played", "Registered"]; return [ "Username", "Discord ID", "Google ID", "Last played", "Registered" ];
default: default:
return [""]; return [ "" ];
} }
} }
@ -56,22 +56,38 @@ export default class AdminUiHandler extends FormModalUiHandler {
} }
getMargin(config?: ModalConfig): [number, number, number, number] { getMargin(config?: ModalConfig): [number, number, number, number] {
return [0, 0, 0, 0]; return [ 0, 0, 0, 0 ];
} }
getButtonLabels(config?: ModalConfig): string[] { getButtonLabels(config?: ModalConfig): string[] {
switch (this.adminMode) { switch (this.adminMode) {
case AdminMode.LINK: case AdminMode.LINK:
return ["Link Account", "Cancel"]; return [ "Link Account", "Cancel" ];
case AdminMode.SEARCH: case AdminMode.SEARCH:
return ["Find account", "Cancel"]; return [ "Find account", "Cancel" ];
case AdminMode.ADMIN: case AdminMode.ADMIN:
return ["Back to search", "Cancel"]; return [ "Back to search", "Cancel" ];
default: 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 { processInput(button: Button): boolean {
if (button === Button.SUBMIT && this.submitAction) { if (button === Button.SUBMIT && this.submitAction) {
this.submitAction(); this.submitAction();
@ -89,7 +105,8 @@ export default class AdminUiHandler extends FormModalUiHandler {
const fields = this.getFields(); const fields = this.getFields();
const hasTitle = !!this.getModalTitle(); const hasTitle = !!this.getModalTitle();
this.updateFields(fields, hasTitle);
this.updateFields(this.getInputFieldConfigs(this.adminResult), hasTitle);
this.updateContainer(this.config); this.updateContainer(this.config);
const labels = this.getButtonLabels(); 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 adminSearchResult: AdminSearchInfo = this.convertInputsToAdmin(); // this converts the input texts into a single object for use later
const validFields = this.areFieldsValid(this.adminMode); const validFields = this.areFieldsValid(this.adminMode);
if (validFields.error) { 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); 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) { if (this.adminMode === AdminMode.LINK) {
this.adminLinkUnlink(adminSearchResult, "discord", "link") this.adminLinkUnlink(adminSearchResult, "discord", "link")
.then(response => { .then(response => {
@ -160,12 +177,11 @@ export default class AdminUiHandler extends FormModalUiHandler {
this.inputs[0].setText(adminResult.username); this.inputs[0].setText(adminResult.username);
break; break;
case AdminMode.ADMIN: case AdminMode.ADMIN:
const lockedFields: string[] = ["username", "lastLoggedIn", "registered"];
Object.keys(adminResult).forEach((aR, i) => { Object.keys(adminResult).forEach((aR, i) => {
this.inputs[i].setText(adminResult[aR]); this.inputs[i].setText(adminResult[aR]);
if (aR === "discordId" || aR === "googleId") { if (aR === "discordId" || aR === "googleId") {
const nineSlice = this.inputContainers[i].list.find(iC => iC.type === "NineSlice"); 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.setName(`adminBtn_${aR}`);
img.setOrigin(0.5, 0.5); img.setOrigin(0.5, 0.5);
//img.setScale(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 mode = adminResult[aR] === "" ? "link" : "unlink"; // this figures out if we're linking or unlinking a service
const validFields = this.areFieldsValid(this.adminMode, service); const validFields = this.areFieldsValid(this.adminMode, service);
if (validFields.error) { 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); return this.showMessage(validFields.errorMessage ?? "", adminResult, true);
} }
this.adminLinkUnlink(this.convertInputsToAdmin(), service, mode).then(response => { this.adminLinkUnlink(this.convertInputsToAdmin(), service, mode).then(response => {
if (response.error) { if (response.error) {
return this.showMessage(response.errorType, adminResult, true); return this.showMessage(response.errorType, adminResult, true);
} else { } else {
this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); this.scene.ui.setMode(Mode.LOADING, { buttonActions: []});
this.adminSearch(adminResult) this.adminSearch(adminResult)
.then(response => { .then(response => {
if (response.error) { if (response.error) {
@ -196,11 +212,6 @@ export default class AdminUiHandler extends FormModalUiHandler {
this.addInteractionHoverEffect(img); this.addInteractionHoverEffect(img);
this.modalContainer.add(img); this.modalContainer.add(img);
} }
if (lockedFields.includes(aR) || adminResult[aR] !== "") {
this.inputs[i].setReadOnly(true);
} else {
this.inputs[i].setReadOnly(false);
}
}); });
break; 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 // 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 removeArray: any[] = [];
const mC = this.modalContainer.list; const mC = this.modalContainer.list;
for (let i = mC.length - 1; i >= 0; i--) { 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 * 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 * 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]); removeArray.push(mC[i]);
} }
} }

View File

@ -5,7 +5,6 @@ import { TextStyle, addTextInputObject, addTextObject } from "./text";
import { WindowVariant, addWindow } from "./ui-theme"; import { WindowVariant, addWindow } from "./ui-theme";
import InputText from "phaser3-rex-plugins/plugins/inputtext"; import InputText from "phaser3-rex-plugins/plugins/inputtext";
import * as Utils from "../utils"; import * as Utils from "../utils";
import i18next from "i18next";
import { Button } from "#enums/buttons"; import { Button } from "#enums/buttons";
export interface FormModalConfig extends ModalConfig { export interface FormModalConfig extends ModalConfig {
@ -32,6 +31,8 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
abstract getFields(): string[]; abstract getFields(): string[];
abstract getInputFieldConfigs(args?: any): InputFieldConfigs[];
getHeight(config?: ModalConfig): number { getHeight(config?: ModalConfig): number {
return 20 * this.getFields().length + (this.getModalTitle() ? 26 : 0) + ((config as FormModalConfig)?.errorMessage ? 12 : 0) + this.getButtonTopMargin() + 28; 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 { setup(): void {
super.setup(); super.setup();
const fields = this.getFields(); //const fields = this.getFields();
const config = this.getInputFieldConfigs();
const hasTitle = !!this.getModalTitle(); const hasTitle = !!this.getModalTitle();
if (fields.length > 1 && fields[0]!=="") { if (config.length >= 1) {
this.updateFields(fields, hasTitle); 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.setColor(this.getTextColor(TextStyle.SUMMARY_PINK));
this.errorMessage.setShadowColor(this.getTextColor(TextStyle.SUMMARY_PINK, true)); this.errorMessage.setShadowColor(this.getTextColor(TextStyle.SUMMARY_PINK, true));
this.errorMessage.setVisible(false); this.errorMessage.setVisible(false);
this.modalContainer.add(this.errorMessage); this.modalContainer.add(this.errorMessage);
} }
updateFields(fields: string[], hasTitle: boolean) { //updateFields(fields: string[], hasTitle: boolean) {
updateFields(fieldsConfig: InputFieldConfigs[], hasTitle: boolean) {
this.inputContainers = []; this.inputContainers = [];
this.inputs = []; this.inputs = [];
this.formLabels= []; this.formLabels = [];
fields.forEach((field, f) => { fieldsConfig.forEach((config, f) => {
const label = addTextObject(this.scene, 10, (hasTitle ? 31 : 5) + 20 * f, field, TextStyle.TOOLTIP_CONTENT); const label = addTextObject(this.scene, 10, (hasTitle ? 31 : 5) + 20 * f, config.label, TextStyle.TOOLTIP_CONTENT);
label.name = "formLabel" + f; label.name = "formLabel" + f;
this.formLabels.push(label); 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 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 isPassword = config?.isPassword;
const input = addTextInputObject(this.scene, 4, -2, 440, 116, TextStyle.TOOLTIP_CONTENT, { type: isPassword ? "password" : "text", maxLength: isPassword ? 64 : 20 }); 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); input.setOrigin(0, 0);
inputContainer.add(inputBg); inputContainer.add(inputBg);
@ -163,3 +167,9 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
} }
} }
} }
export interface InputFieldConfigs {
label: string,
isPassword?: boolean,
isReadOnly?: boolean
}

View File

@ -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 { ModalConfig } from "./modal-ui-handler";
import * as Utils from "../utils"; import * as Utils from "../utils";
import { Mode } from "./ui"; import { Mode } from "./ui";
@ -114,6 +114,18 @@ export default class LoginFormUiHandler extends FormModalUiHandler {
return super.getReadableErrorMessage(error); 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 { override show(args: any[]): boolean {
if (super.show(args)) { if (super.show(args)) {

View File

@ -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 { ModalConfig } from "./modal-ui-handler";
import * as Utils from "../utils"; import * as Utils from "../utils";
import { Mode } from "./ui"; import { Mode } from "./ui";
@ -61,6 +61,18 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {
return super.getReadableErrorMessage(error); 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 { setup(): void {
super.setup(); super.setup();

View File

@ -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 { ModalConfig } from "./modal-ui-handler";
import i18next from "i18next"; import i18next from "i18next";
import { PlayerPokemon } from "#app/field/pokemon"; import { PlayerPokemon } from "#app/field/pokemon";
@ -33,6 +33,17 @@ export default class RenameFormUiHandler extends FormModalUiHandler {
return super.getReadableErrorMessage(error); 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 { show(args: any[]): boolean {
if (super.show(args)) { if (super.show(args)) {
const config = args[0] as ModalConfig; const config = args[0] as ModalConfig;

View File

@ -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 { ModalConfig } from "./modal-ui-handler";
import i18next from "i18next"; import i18next from "i18next";
import { PlayerPokemon } from "#app/field/pokemon"; import { PlayerPokemon } from "#app/field/pokemon";
@ -68,11 +68,22 @@ export default class TestDialogueUiHandler extends FormModalUiHandler {
return super.getReadableErrorMessage(error); 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 { show(args: any[]): boolean {
const ui = this.getUi(); const ui = this.getUi();
const fields = this.getFields(); //const fields = this.getFields();
const hasTitle = !!this.getModalTitle(); const hasTitle = !!this.getModalTitle();
this.updateFields(fields, hasTitle); this.updateFields(this.getInputFieldConfigs(), hasTitle);
this.updateContainer(args[0] as ModalConfig); this.updateContainer(args[0] as ModalConfig);
const input = this.inputs[0]; const input = this.inputs[0];
input.setMaxLength(255); input.setMaxLength(255);