Updated code with the current repo + mode localization
This commit is contained in:
parent
c53818205a
commit
4ca48c6bc6
|
@ -945,31 +945,26 @@ export class GameData {
|
|||
}
|
||||
|
||||
async public getRunHistoryData(scene: BattleScene): Promise<Object> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue