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 { 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";
@ -72,6 +72,22 @@ export default class AdminUiHandler extends FormModalUiHandler {
}
}
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();
@ -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);
@ -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;
}
@ -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]);
}
}

View File

@ -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);
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
}

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 * 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)) {

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 * 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();

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 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;

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 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);