From 4ca48c6bc6fdd82ecae6761469a98384317e440f Mon Sep 17 00:00:00 2001 From: Frutescens Date: Sun, 16 Jun 2024 12:35:02 -0700 Subject: [PATCH] Updated code with the current repo + mode localization --- src/system/game-data.ts | 49 +++++++++++++++----------------- src/ui/run-history-ui-handler.ts | 24 ++++++++++++---- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/system/game-data.ts b/src/system/game-data.ts index d7c796ab339..a6b71c5ed0b 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -945,31 +945,26 @@ export class GameData { } async public getRunHistoryData(scene: BattleScene): Promise { - try { + if (!Utils.isLocal) { const response = await Utils.apiFetch("savedata/runHistory", true); const data = await response.json(); - console.log(data); - if (!data) { - throw new Error("No data"); - } else { - var cachedResponse = localStorage.getItem(`runHistoryData_${loggedInUser.username}`, true); - if (cachedResponse) { - cachedResponse = JSON.parse(decrypt(cachedResponse, true)); - } - const cachedRHData = cachedResponse ?? {}; - //check to see whether cachedData or serverData is more up-to-date - if ( Object.keys(cachedRHData).length >= Object.keys(data).length ) { - return cachedRHData; - } - return data; - } - } catch (err) { - console.log("Something went wrong: ", err); - var cachedResponse = localStorage.getItem(`runHistoryData_${loggedInUser.username}`, true); + const cachedResponse = localStorage.getItem(`runHistoryData_${loggedInUser.username}`, true); if (cachedResponse) { cachedResponse = JSON.parse(decrypt(cachedResponse, true)); } - return cachedResponse ?? {}; + const cachedRHData = cachedResponse ?? {}; + //check to see whether cachedData or serverData is more up-to-date + if ( Object.keys(cachedRHData).length >= Object.keys(data).length ) { + return cachedRHData; + } + return data; + } else { + const cachedResponse = localStorage.getItem(`runHistoryData_${loggedInUser.username}`, true); + if (cachedResponse) { + cachedResponse = JSON.parse(decrypt(cachedResponse, true)); + } + const cachedRHData = cachedResponse ?? {}; + return cachedRHData; } } @@ -990,12 +985,14 @@ export class GameData { localStorage.setItem(`runHistoryData_${loggedInUser.username}`, encrypt(JSON.stringify(runHistoryData), true)); - try { - const response = Utils.apiPost("savedata/runHistory", JSON.stringify(runHistoryData), undefined, true); - return true; - } catch (err) { - console.log("savedata/runHistory POST failed : ", err); - return false; + if (!Utils.local) { + try { + const response = Utils.apiPost("savedata/runHistory", JSON.stringify(runHistoryData), undefined, true); + return true; + } catch (err) { + console.log("savedata/runHistory POST failed : ", err); + return false; + } } } diff --git a/src/ui/run-history-ui-handler.ts b/src/ui/run-history-ui-handler.ts index 05f53c9bf1c..9f773c97c7b 100644 --- a/src/ui/run-history-ui-handler.ts +++ b/src/ui/run-history-ui-handler.ts @@ -1,5 +1,5 @@ import BattleScene from "../battle-scene"; -import { gameModes, GameModes } from "../game-mode"; +import { GameModes } from "../game-mode"; import { SessionSaveData, parseSessionData, getRunHistoryData, RunHistoryData, RunEntries, decrypt } from "../system/game-data"; import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; @@ -13,7 +13,7 @@ import MessageUiHandler from "./message-ui-handler"; import i18next from "i18next"; import {Button} from "../enums/buttons"; import { BattleType } from "../battle"; -import {TrainerType} from "../data/enums/trainer-type"; +import { TrainerType } from "../enums/trainer-type"; import { TrainerVariant } from "../field/trainer"; import { getPartyLuckValue, getLuckString, getLuckTextTint } from "../modifier/modifier-type"; @@ -134,7 +134,6 @@ export default class RunHistoryUiHandler extends MessageUiHandler { async populateruns(scene: BattleScene) { const response = await this.scene.gameData.getRunHistoryData(this.scene); - console.log(response); const timestamps = Object.keys(response); if (timestamps.length > 1) { timestamps.sort((a, b) => a - b); @@ -278,9 +277,24 @@ class RunEntry extends Phaser.GameObjects.Container { } } - const gameModeLabel = addTextObject(this.scene, 8, 19, `${gameModes[data.gameMode]?.getName() || "Unknown"} - Wave ${data.waveIndex}`, TextStyle.WINDOW); - this.add(gameModeLabel); + switch (data.gameMode) { + case GameModes.DAILY: + const dailyModeLabel = addTextObject(this.scene, 8, 19, `${i18next.t('gameMode:dailyRun') || "Unknown"} - Wave ${data.waveIndex}`, TextStyle.WINDOW); + this.add(dailyModeLabel); + break; + case GameModes.SPLICED_ENDLESS: + const endlessSplicedLabel = addTextObject(this.scene, 8, 19, `${i18next.t('gameMode:endlessSpliced') || "Unknown"} - Wave ${data.waveIndex}`, TextStyle.WINDOW); + this.add(endlessSplicedLabel); + break; + case GameModes.ENDLESS: + case GameModes.CLASSIC: + case GameModes.CHALLENGE: + const gameModeLabel = addTextObject(this.scene, 8, 19, `${i18next.t('gameMode:'+GameModes[data.gameMode].toLowerCase()) || "Unknown"} - Wave ${data.waveIndex}`, TextStyle.WINDOW); + this.add(gameModeLabel); + break; + } + const date = new Date(data.timestamp); const timestampLabel = addTextObject(this.scene, 8, 33, new Date(data.timestamp).toLocaleString(), TextStyle.WINDOW);