Add UI to rename files

This commit is contained in:
RedstonewolfX 2024-07-12 16:57:44 -04:00
parent bfdce2b1f8
commit d464e46150
3 changed files with 84 additions and 22 deletions

View File

@ -11,7 +11,7 @@ import Battle from "./battle";
import { getBiomeName, PokemonPools, SpeciesTree } from "./data/biomes"; import { getBiomeName, PokemonPools, SpeciesTree } from "./data/biomes";
import { trainerConfigs } from "./data/trainer-config"; import { trainerConfigs } from "./data/trainer-config";
import { Mode } from "./ui/ui"; import { Mode } from "./ui/ui";
import { TitlePhase } from "./phases"; import { LoginPhase, TitlePhase } from "./phases";
import { Item } from "pokenode-ts"; import { Item } from "pokenode-ts";
import Trainer from "./field/trainer"; import Trainer from "./field/trainer";
import { Species } from "./enums/species"; import { Species } from "./enums/species";
@ -117,7 +117,7 @@ export function enemyPokeName(scene: BattleScene, index: integer | Pokemon | Ene
// LoggerTools.logActions(this.scene, this.scene.currentBattle.waveIndex, "") // LoggerTools.logActions(this.scene, this.scene.currentBattle.waveIndex, "")
export const rarities = [] export const rarities = []
export const rarityslot = [0] export const rarityslot = [0, ""]
export const isPreSwitch: Utils.BooleanHolder = new Utils.BooleanHolder(false); export const isPreSwitch: Utils.BooleanHolder = new Utils.BooleanHolder(false);
@ -376,6 +376,47 @@ export function generateOption(i: integer, saves: any): OptionSelectItem {
} }
return op; return op;
} }
/**
* Generates a UI option to save a log to your device.
* @param i The slot number. Corresponds to an index in `logs`.
* @param saves Your session data. Used to label logs if they match one of your save slots.
* @returns A UI option.
*/
export function generateEditOption(scene: BattleScene, i: integer, saves: any, phase: TitlePhase): OptionSelectItem {
var filename: string = (JSON.parse(localStorage.getItem(logs[i][1])) as DRPD).title
var op: OptionSelectItem = {
label: `Export ${filename} (${getSize(printDRPD("", "", JSON.parse(localStorage.getItem(logs[i][1])) as DRPD))})`,
handler: () => {
rarityslot[1] = logs[i][1]
//scene.phaseQueue[0].end()
scene.ui.setMode(Mode.NAME_LOG, {
autofillfields: [
(JSON.parse(localStorage.getItem(logs[i][1])) as DRPD).title,
(JSON.parse(localStorage.getItem(logs[i][1])) as DRPD).authors.join(", ")
],
buttonActions: [
() => {
scene.ui.playSelect();
console.log("Ending UI phase thingy");
phase.callEnd()
}
]
});
return false;
}
}
for (var j = 0; j < saves.length; j++) {
console.log(saves[j].seed, logs[i][2], saves[j].seed == logs[i][2])
if (saves[j].seed == logs[i][2]) {
op.label = "[Slot " + (saves[j].slot + 1) + "]" + op.label.substring(6)
}
}
if (logs[i][4] != "") {
op.label = " " + op.label
op.item = logs[i][4]
}
return op;
}
/** /**
* Generates an option to create a new log. * Generates an option to create a new log.
* *
@ -424,6 +465,27 @@ export function appendLog(keyword: string, data: string) {
export function clearLog(keyword: string) { export function clearLog(keyword: string) {
localStorage.setItem(logs[logKeys.indexOf(keyword)][1], "---- " + logs[logKeys.indexOf(keyword)][3] + " ----" + logs[logKeys.indexOf(keyword)][5]) localStorage.setItem(logs[logKeys.indexOf(keyword)][1], "---- " + logs[logKeys.indexOf(keyword)][3] + " ----" + logs[logKeys.indexOf(keyword)][5])
} }
export function setFileInfo(title: string, authors: string[]) {
var fileID = rarityslot[1] as string
var drpd = JSON.parse(localStorage.getItem(fileID)) as DRPD;
drpd.title = title;
for (var i = 0; i < authors.length; i++) {
while (authors[i][0] == " ") {
authors[i] = authors[i].substring(1)
}
while (authors[i][authors[i].length - 1] == " ") {
authors[i] = authors[i].substring(0, authors[i].length - 1)
}
}
for (var i = 0; i < authors.length; i++) {
if (authors[i] == "") {
authors.splice(i, 1)
i--;
}
}
drpd.authors = authors;
localStorage.setItem(fileID, JSON.stringify(drpd))
}
/** /**
* Saves a log to your device. * Saves a log to your device.
* @param keyword The identifier key for the log you want to save. * @param keyword The identifier key for the log you want to save.

View File

@ -3,6 +3,8 @@ import { ModalConfig } from "./modal-ui-handler";
import * as Utils from "../utils"; import * as Utils from "../utils";
import { Mode } from "./ui"; import { Mode } from "./ui";
import i18next from "i18next"; import i18next from "i18next";
import * as LoggerTools from "../logger";
import { addTextObject, TextStyle } from "./text";
export default class LogNameFormUiHandler extends FormModalUiHandler { export default class LogNameFormUiHandler extends FormModalUiHandler {
getModalTitle(config?: ModalConfig): string { getModalTitle(config?: ModalConfig): string {
@ -44,38 +46,36 @@ export default class LogNameFormUiHandler extends FormModalUiHandler {
return super.getReadableErrorMessage(error); return super.getReadableErrorMessage(error);
} }
setup(): void {
super.setup();
//const label = addTextObject(this.scene, 10, 87, "Text", TextStyle.TOOLTIP_CONTENT, { fontSize: "42px" });
//this.modalContainer.add(label);
}
show(args: any[]): boolean { show(args: any[]): boolean {
console.error("Shown")
if (super.show(args)) { if (super.show(args)) {
const config = args[0] as ModalConfig; const config = args[0] as ModalConfig;
const originalLoginAction = this.submitAction; const originalLoginAction = this.submitAction;
this.inputs[0].setText(args[0].autofillfields[0])
this.inputs[1].setText(args[0].autofillfields[1])
this.submitAction = (_) => { this.submitAction = (_) => {
// Prevent overlapping overrides on action modification // Prevent overlapping overrides on action modification
this.submitAction = originalLoginAction; this.submitAction = originalLoginAction;
this.sanitizeInputs(); this.sanitizeInputs();
this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] });
const onFail = error => { const onFail = error => {
this.scene.ui.setMode(Mode.LOGIN_FORM, Object.assign(config, { errorMessage: error?.trim() })); this.scene.ui.setMode(Mode.NAME_LOG, Object.assign(config, { errorMessage: error?.trim() }));
this.scene.ui.playError(); this.scene.ui.playError();
}; };
if (!this.inputs[0].text) { if (!this.inputs[0].text) {
return onFail(i18next.t("menu:emptyUsername")); //return onFail(i18next.t("menu:emptyUsername"));
} }
Utils.apiPost("account/login", `username=${encodeURIComponent(this.inputs[0].text)}&password=${encodeURIComponent(this.inputs[1].text)}`, "application/x-www-form-urlencoded") LoggerTools.setFileInfo(this.inputs[0].text, this.inputs[1].text.split(","))
.then(response => { originalLoginAction()
if (!response.ok) {
return response.text();
}
return response.json();
})
.then(response => {
if (response.hasOwnProperty("token")) {
Utils.setCookie(Utils.sessionIdKey, response.token);
originalLoginAction();
} else {
onFail(response);
}
});
}; };
return true; return true;

View File

@ -97,7 +97,8 @@ const transitionModes = [
Mode.EGG_HATCH_SCENE, Mode.EGG_HATCH_SCENE,
Mode.EGG_LIST, Mode.EGG_LIST,
Mode.EGG_GACHA, Mode.EGG_GACHA,
Mode.CHALLENGE_SELECT Mode.CHALLENGE_SELECT,
Mode.NAME_LOG
]; ];
const noTransitionModes = [ const noTransitionModes = [
@ -121,8 +122,7 @@ const noTransitionModes = [
Mode.LOADING, Mode.LOADING,
Mode.SESSION_RELOAD, Mode.SESSION_RELOAD,
Mode.UNAVAILABLE, Mode.UNAVAILABLE,
Mode.OUTDATED, Mode.OUTDATED
Mode.NAME_LOG
]; ];
export default class UI extends Phaser.GameObjects.Container { export default class UI extends Phaser.GameObjects.Container {