Revert dev related code and clean up dev comments

This commit is contained in:
Opaque02 2024-10-15 15:52:22 +10:00
parent 77b754a7bb
commit f9849db78a
4 changed files with 26 additions and 31 deletions

View File

@ -1,6 +1,6 @@
VITE_BYPASS_LOGIN=0 VITE_BYPASS_LOGIN=1
VITE_BYPASS_TUTORIAL=0 VITE_BYPASS_TUTORIAL=0
VITE_SERVER_URL=http://192.168.1.101:8001 VITE_SERVER_URL=http://localhost:8001
VITE_DISCORD_CLIENT_ID=1234567890 VITE_DISCORD_CLIENT_ID=1234567890
VITE_GOOGLE_CLIENT_ID=1234567890 VITE_GOOGLE_CLIENT_ID=1234567890
VITE_I18N_DEBUG=0 VITE_I18N_DEBUG=0

View File

@ -74,10 +74,10 @@ export default class AdminUiHandler extends FormModalUiHandler {
override getInputFieldConfigs(adminResult: AdminSearchInfo): InputFieldConfigs[] { override getInputFieldConfigs(adminResult: AdminSearchInfo): InputFieldConfigs[] {
const inputFieldConfigs: InputFieldConfigs[] = []; const inputFieldConfigs: InputFieldConfigs[] = [];
adminResult = adminResult ?? { username: "", discordId: "", googleId: "", lastLoggedIn: "", registered: "" }; adminResult = adminResult ?? { username: "", discordId: "", googleId: "", lastLoggedIn: "", registered: "" }; // we use this to check what fields we need to be locking, if any
const adminKeys = Object.keys(adminResult); const adminKeys = Object.keys(adminResult);
const fields = this.getFields(); const fields = this.getFields();
const lockedFields: string[] = [ "username", "lastLoggedIn", "registered" ]; const lockedFields: string[] = [ "username", "lastLoggedIn", "registered" ]; // this is the list of fields that will always be locked when this.adminMode === AdminMode.ADMIN
fields.forEach((field, i) => { fields.forEach((field, i) => {
const readOnly = (this.adminMode === AdminMode.ADMIN && (lockedFields.includes(adminKeys[i]) || adminResult[adminKeys[i]] !== "")); const readOnly = (this.adminMode === AdminMode.ADMIN && (lockedFields.includes(adminKeys[i]) || adminResult[adminKeys[i]] !== ""));
inputFieldConfigs.push({ inputFieldConfigs.push({
@ -98,10 +98,10 @@ export default class AdminUiHandler extends FormModalUiHandler {
} }
show(args: any[]): boolean { show(args: any[]): boolean {
this.config = args[0] as ModalConfig; this.config = args[0] as ModalConfig; // config
this.adminMode = args[1] as AdminMode; this.adminMode = args[1] as AdminMode; // admin mode
this.adminResult = args[2] ?? { username: "", discordId: "", googleId: "", lastLoggedIn: "", registered: "" }; this.adminResult = args[2] ?? { username: "", discordId: "", googleId: "", lastLoggedIn: "", registered: "" }; // admin result, if any
const isMessageError = args[3]; const isMessageError = args[3]; // is the message shown a success or error
const fields = this.getFields(); const fields = this.getFields();
const hasTitle = !!this.getModalTitle(); const hasTitle = !!this.getModalTitle();
@ -111,10 +111,10 @@ export default class AdminUiHandler extends FormModalUiHandler {
const labels = this.getButtonLabels(); const labels = this.getButtonLabels();
for (let i = 0; i < labels.length; i++) { for (let i = 0; i < labels.length; i++) {
this.buttonLabels[i].setText(labels[i]); this.buttonLabels[i].setText(labels[i]); // sets the label text
} }
this.errorMessage.setPosition(10, (hasTitle ? 31 : 5) + 20 * (fields.length - 1) + 16 + this.getButtonTopMargin()); this.errorMessage.setPosition(10, (hasTitle ? 31 : 5) + 20 * (fields.length - 1) + 16 + this.getButtonTopMargin()); // sets the position of the message dynamically
if (isMessageError) { if (isMessageError) {
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));
@ -136,21 +136,21 @@ export default class AdminUiHandler extends FormModalUiHandler {
} }
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") // calls server to link discord
.then(response => { .then(response => {
if (response.error) { if (response.error) {
return this.showMessage(response.errorType, adminSearchResult, true); return this.showMessage(response.errorType, adminSearchResult, true); // error or some kind
} else { } else {
return this.showMessage(this.SUCCESS_SERVICE_MODE("discord", "link"), adminSearchResult, false); return this.showMessage(this.SUCCESS_SERVICE_MODE("discord", "link"), adminSearchResult, false); // success
} }
}); });
} else if (this.adminMode === AdminMode.SEARCH) { } else if (this.adminMode === AdminMode.SEARCH) {
this.adminSearch(adminSearchResult) this.adminSearch(adminSearchResult) // admin search for username
.then(response => { .then(response => {
if (response.error) { if (response.error) {
return this.showMessage(response.errorType, adminSearchResult, true); return this.showMessage(response.errorType, adminSearchResult, true); // failure
} }
this.updateAdminPanelInfo(response.adminSearchResult ?? adminSearchResult); this.updateAdminPanelInfo(response.adminSearchResult ?? adminSearchResult); // success
}); });
} else if (this.adminMode === AdminMode.ADMIN) { } else if (this.adminMode === AdminMode.ADMIN) {
this.updateAdminPanelInfo(adminSearchResult, AdminMode.SEARCH); this.updateAdminPanelInfo(adminSearchResult, AdminMode.SEARCH);
@ -167,6 +167,7 @@ export default class AdminUiHandler extends FormModalUiHandler {
this.scene.ui.playError(); this.scene.ui.playError();
} }
// this is used to update the fields' text when loading a new admin ui handler. It uses the adminResult to update the input text fields depending on the adminMode
populateFields(adminMode: AdminMode, adminResult: AdminSearchInfo) { populateFields(adminMode: AdminMode, adminResult: AdminSearchInfo) {
switch (adminMode) { switch (adminMode) {
case AdminMode.LINK: case AdminMode.LINK:
@ -179,12 +180,11 @@ export default class AdminUiHandler extends FormModalUiHandler {
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") { 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.setScale(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
@ -194,10 +194,10 @@ export default class AdminUiHandler extends FormModalUiHandler {
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 => { // attempts to link/unlink depending on the service
if (response.error) { if (response.error) {
return this.showMessage(response.errorType, adminResult, true); return this.showMessage(response.errorType, adminResult, true); // fail
} else { } else { // success, reload panel with new results
this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); this.scene.ui.setMode(Mode.LOADING, { buttonActions: []});
this.adminSearch(adminResult) this.adminSearch(adminResult)
.then(response => { .then(response => {
@ -329,7 +329,7 @@ export default class AdminUiHandler extends FormModalUiHandler {
/* This code looks for a few things before destroying the specific field; first it looks to see if the name of the element is %like% the itemsToRemove labels /* This code looks for a few things before destroying the specific field; first it looks to see if the name of the element is %like% the itemsToRemove labels
* this means that anything with, for example, "formLabel", will be true. * this means that anything with, for example, "formLabel", will be true.
* 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] as Phaser.GameObjects.Container).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]);
@ -337,12 +337,7 @@ export default class AdminUiHandler extends FormModalUiHandler {
} }
while (removeArray.length > 0) { while (removeArray.length > 0) {
const removedElement = removeArray.pop(); this.modalContainer.remove(removeArray.pop(), true);
//if (removedElement.type === "Container") {
// this.inputContainers = this.inputContainers.filter(iC => iC !== removedElement);
// this.inputs = this.inputs.filter(i => i !== removedElement.list.find(rE => rE.type === "rexInputText"));
//}
this.modalContainer.remove(removedElement, true);
} }
} }
} }

View File

@ -31,6 +31,9 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
abstract getFields(): string[]; abstract getFields(): string[];
// this function takes any args and uses it to make an array of InputFieldConfigs, which has extra support for the input text field
// It currently has support for a field's label, whether it's a password field, and whether the field should be read only, but by expanding the InputFieldConfig interface
// any extra details can be passed on to the field during creation
abstract getInputFieldConfigs(args?: any): InputFieldConfigs[]; abstract getInputFieldConfigs(args?: any): InputFieldConfigs[];
getHeight(config?: ModalConfig): number { getHeight(config?: ModalConfig): number {
@ -48,7 +51,6 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
setup(): void { setup(): void {
super.setup(); super.setup();
//const fields = this.getFields();
const config = this.getInputFieldConfigs(); const config = this.getInputFieldConfigs();
const hasTitle = !!this.getModalTitle(); const hasTitle = !!this.getModalTitle();
@ -64,7 +66,6 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
this.modalContainer.add(this.errorMessage); this.modalContainer.add(this.errorMessage);
} }
//updateFields(fields: string[], hasTitle: boolean) {
updateFields(fieldsConfig: InputFieldConfigs[], hasTitle: boolean) { updateFields(fieldsConfig: InputFieldConfigs[], hasTitle: boolean) {
this.inputContainers = []; this.inputContainers = [];
this.inputs = []; this.inputs = [];

View File

@ -81,7 +81,6 @@ export default class TestDialogueUiHandler extends FormModalUiHandler {
show(args: any[]): boolean { show(args: any[]): boolean {
const ui = this.getUi(); const ui = this.getUi();
//const fields = this.getFields();
const hasTitle = !!this.getModalTitle(); const hasTitle = !!this.getModalTitle();
this.updateFields(this.getInputFieldConfigs(), hasTitle); this.updateFields(this.getInputFieldConfigs(), hasTitle);
this.updateContainer(args[0] as ModalConfig); this.updateContainer(args[0] as ModalConfig);