eslint fixes

This commit is contained in:
Opaque02 2024-10-20 21:55:39 +10:00
parent 12eabfefe2
commit 7102335153
2 changed files with 120 additions and 120 deletions

View File

@ -47,36 +47,36 @@ export default class AdminUiHandler extends FormModalUiHandler {
override getButtonLabels(): string[] { override getButtonLabels(): 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(): InputFieldConfig[] { override getInputFieldConfigs(): InputFieldConfig[] {
const inputFieldConfigs: InputFieldConfig[] = []; const inputFieldConfigs: InputFieldConfig[] = [];
switch (this.adminMode) { switch (this.adminMode) {
case AdminMode.LINK: case AdminMode.LINK:
inputFieldConfigs.push( { label: "Username" }); inputFieldConfigs.push( { label: "Username" });
inputFieldConfigs.push( { label: "Discord ID" }); inputFieldConfigs.push( { label: "Discord ID" });
break; break;
case AdminMode.SEARCH: case AdminMode.SEARCH:
inputFieldConfigs.push( { label: "Username" }); inputFieldConfigs.push( { label: "Username" });
break; break;
case AdminMode.ADMIN: case AdminMode.ADMIN:
const adminResult = this.adminResult ?? { username: "", discordId: "", googleId: "", lastLoggedIn: "", registered: "" }; const adminResult = this.adminResult ?? { username: "", discordId: "", googleId: "", lastLoggedIn: "", registered: "" };
// Discord and Google ID fields that are not empty get locked, other fields are all locked // Discord and Google ID fields that are not empty get locked, other fields are all locked
inputFieldConfigs.push( { label: "Username", isReadOnly: true }); inputFieldConfigs.push( { label: "Username", isReadOnly: true });
inputFieldConfigs.push( { label: "Discord ID", isReadOnly: adminResult.discordId !== "" }); inputFieldConfigs.push( { label: "Discord ID", isReadOnly: adminResult.discordId !== "" });
inputFieldConfigs.push( { label: "Google ID", isReadOnly: adminResult.googleId !== "" }); inputFieldConfigs.push( { label: "Google ID", isReadOnly: adminResult.googleId !== "" });
inputFieldConfigs.push( { label: "Last played", isReadOnly: true }); inputFieldConfigs.push( { label: "Last played", isReadOnly: true });
inputFieldConfigs.push( { label: "Registered", isReadOnly: true }); inputFieldConfigs.push( { label: "Registered", isReadOnly: true });
break; break;
} }
return inputFieldConfigs; return inputFieldConfigs;
} }
@ -172,91 +172,91 @@ export default class AdminUiHandler extends FormModalUiHandler {
*/ */
private populateFields(adminMode: AdminMode, adminResult: AdminSearchInfo) { private populateFields(adminMode: AdminMode, adminResult: AdminSearchInfo) {
switch (adminMode) { switch (adminMode) {
case AdminMode.LINK: case AdminMode.LINK:
this.inputs[0].setText(adminResult.username); this.inputs[0].setText(adminResult.username);
this.inputs[1].setText(adminResult.discordId); this.inputs[1].setText(adminResult.discordId);
break; break;
case AdminMode.SEARCH: case AdminMode.SEARCH:
this.inputs[0].setText(adminResult.username); this.inputs[0].setText(adminResult.username);
break; break;
case AdminMode.ADMIN: case AdminMode.ADMIN:
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") { // this is here to add the icons for linking/unlinking of google/discord IDs if (aR === "discordId" || aR === "googleId") { // this is here to add the icons for linking/unlinking of google/discord IDs
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.setInteractive(); img.setInteractive();
img.on("pointerdown", () => { img.on("pointerdown", () => {
const service = aR.toLowerCase().replace("id", ""); // this takes our key (discordId or googleId) and removes the "Id" at the end to make it more url friendly const service = aR.toLowerCase().replace("id", ""); // this takes our key (discordId or googleId) and removes the "Id" at the end to make it more url friendly
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 => { // attempts to link/unlink depending on the service
if (response.error) {
return this.showMessage(response.errorType, adminResult, true); // fail
} else { // success, reload panel with new results
this.scene.ui.setMode(Mode.LOADING, { buttonActions: []});
this.adminSearch(adminResult)
.then(response => {
if (response.error) {
return this.showMessage(response.errorType, adminResult, true);
}
return this.showMessage(this.SUCCESS_SERVICE_MODE(service, mode), response.adminSearchResult ?? adminResult, false);
});
} }
this.adminLinkUnlink(this.convertInputsToAdmin(), service, mode).then(response => { // attempts to link/unlink depending on the service
if (response.error) {
return this.showMessage(response.errorType, adminResult, true); // fail
} else { // success, reload panel with new results
this.scene.ui.setMode(Mode.LOADING, { buttonActions: []});
this.adminSearch(adminResult)
.then(response => {
if (response.error) {
return this.showMessage(response.errorType, adminResult, true);
}
return this.showMessage(this.SUCCESS_SERVICE_MODE(service, mode), response.adminSearchResult ?? adminResult, false);
});
}
});
}); });
}); this.addInteractionHoverEffect(img);
this.addInteractionHoverEffect(img); this.modalContainer.add(img);
this.modalContainer.add(img); }
} });
}); break;
break;
} }
} }
private areFieldsValid(adminMode: AdminMode, service?: string): { error: boolean; errorMessage?: string; } { private areFieldsValid(adminMode: AdminMode, service?: string): { error: boolean; errorMessage?: string; } {
switch (adminMode) { switch (adminMode) {
case AdminMode.LINK: case AdminMode.LINK:
if (!this.inputs[0].text) { // username missing from link panel if (!this.inputs[0].text) { // username missing from link panel
return { return {
error: true, error: true,
errorMessage: this.ERR_REQUIRED_FIELD("username") errorMessage: this.ERR_REQUIRED_FIELD("username")
}; };
} }
if (!this.inputs[1].text) { // discordId missing from linking panel if (!this.inputs[1].text) { // discordId missing from linking panel
return { return {
error: true, error: true,
errorMessage: this.ERR_REQUIRED_FIELD("discord") errorMessage: this.ERR_REQUIRED_FIELD("discord")
}; };
} }
break; break;
case AdminMode.SEARCH: case AdminMode.SEARCH:
if (!this.inputs[0].text) { // username missing from search panel if (!this.inputs[0].text) { // username missing from search panel
return { return {
error: true, error: true,
errorMessage: this.ERR_REQUIRED_FIELD("username") errorMessage: this.ERR_REQUIRED_FIELD("username")
}; };
} }
break; break;
case AdminMode.ADMIN: case AdminMode.ADMIN:
if (!this.inputs[1].text && service === "discord") { // discordId missing from admin panel if (!this.inputs[1].text && service === "discord") { // discordId missing from admin panel
return { return {
error: true, error: true,
errorMessage: this.ERR_REQUIRED_FIELD(service) errorMessage: this.ERR_REQUIRED_FIELD(service)
}; };
} }
if (!this.inputs[2].text && service === "google") { // googleId missing from admin panel if (!this.inputs[2].text && service === "google") { // googleId missing from admin panel
return { return {
error: true, error: true,
errorMessage: this.ERR_REQUIRED_FIELD(service) errorMessage: this.ERR_REQUIRED_FIELD(service)
}; };
} }
break; break;
} }
return { return {
error: false error: false
@ -352,12 +352,12 @@ export enum AdminMode {
export function getAdminModeName(adminMode: AdminMode): string { export function getAdminModeName(adminMode: AdminMode): string {
switch (adminMode) { switch (adminMode) {
case AdminMode.LINK: case AdminMode.LINK:
return "Link"; return "Link";
case AdminMode.SEARCH: case AdminMode.SEARCH:
return "Search"; return "Search";
default: default:
return ""; return "";
} }
} }

View File

@ -93,18 +93,18 @@ export default class LoginFormUiHandler extends FormModalUiHandler {
error = error.slice(0, colonIndex); error = error.slice(0, colonIndex);
} }
switch (error) { switch (error) {
case this.ERR_USERNAME: case this.ERR_USERNAME:
return i18next.t("menu:invalidLoginUsername"); return i18next.t("menu:invalidLoginUsername");
case this.ERR_PASSWORD: case this.ERR_PASSWORD:
return i18next.t("menu:invalidLoginPassword"); return i18next.t("menu:invalidLoginPassword");
case this.ERR_ACCOUNT_EXIST: case this.ERR_ACCOUNT_EXIST:
return i18next.t("menu:accountNonExistent"); return i18next.t("menu:accountNonExistent");
case this.ERR_PASSWORD_MATCH: case this.ERR_PASSWORD_MATCH:
return i18next.t("menu:unmatchingPassword"); return i18next.t("menu:unmatchingPassword");
case this.ERR_NO_SAVES: case this.ERR_NO_SAVES:
return "P01: " + i18next.t("menu:noSaves"); return "P01: " + i18next.t("menu:noSaves");
case this.ERR_TOO_MANY_SAVES: case this.ERR_TOO_MANY_SAVES:
return "P02: " + i18next.t("menu:tooManySaves"); return "P02: " + i18next.t("menu:tooManySaves");
} }
return super.getReadableErrorMessage(error); return super.getReadableErrorMessage(error);