don't save possibly heavy adventurer portraits and load them from global data

This commit is contained in:
2023-07-26 00:01:24 +02:00
parent 28fe055f32
commit 13cb2c5a55
2 changed files with 23 additions and 2 deletions
+14 -1
View File
@@ -97,6 +97,7 @@ export default defineComponent({
lastRecruitHandled: null as null | number, lastRecruitHandled: null as null | number,
adventurerForHire: null as Adventurer | null, adventurerForHire: null as Adventurer | null,
adventurersDatabase: {} as Array<Adventurer>, adventurersDatabase: {} as Array<Adventurer>,
allAdventurers: {} as { [key: string]: Adventurer },
adventurers: {} as { [key: string]: Adventurer }, adventurers: {} as { [key: string]: Adventurer },
quests: {} as { [key: string]: { [key: string]: Quest } }, quests: {} as { [key: string]: { [key: string]: Quest } },
missives: { missives: {
@@ -214,11 +215,18 @@ export default defineComponent({
for (const id in saveData.adventurers) { for (const id in saveData.adventurers) {
const data = saveData.adventurers[id]; const data = saveData.adventurers[id];
let portrait: string = "";
const adventurer = this.allAdventurers[data.id];
if (adventurer) {
portrait = adventurer.portrait;
}
try { try {
const adventurer = new Adventurer( const adventurer = new Adventurer(
data.id, data.id,
data.name, data.name,
data.portrait, portrait,
data.attackExponent ?? 1.1, data.attackExponent ?? 1.1,
data.level ?? 1, data.level ?? 1,
data.exp ?? 0, data.exp ?? 0,
@@ -293,6 +301,11 @@ export default defineComponent({
this.quests = promises[0] as { [key: string]: { [key: string]: Quest } }; this.quests = promises[0] as { [key: string]: { [key: string]: Quest } };
this.adventurersDatabase = promises[1] as Array<Adventurer>; this.adventurersDatabase = promises[1] as Array<Adventurer>;
for (const adventurerId in this.adventurersDatabase) {
const adventurer = this.adventurersDatabase[adventurerId];
this.allAdventurers[adventurer.id] = new Adventurer(adventurer.id, adventurer.name, adventurer.portrait, adventurer.attackExponent, adventurer.level, adventurer.exp, adventurer.prestige);
}
console.debug("Game data loaded!") console.debug("Game data loaded!")
this.loadGame(); this.loadGame();
this.adventurersDatabase = removeAlreadyHiredAdventurers(this.adventurersDatabase, this.adventurers); this.adventurersDatabase = removeAlreadyHiredAdventurers(this.adventurersDatabase, this.adventurers);
+9 -1
View File
@@ -31,9 +31,17 @@ export function saveGame(
data: GameData data: GameData
): void { ): void {
console.debug("Saving game..."); console.debug("Saving game...");
const adventurers = {} as { [key: string]: any };
for (const adventurerId in data.adventurers) {
const adventurer: {[key: string]: any} = JSON.parse(JSON.stringify(data.adventurers[adventurerId]));
delete adventurer.portrait;
adventurers[adventurerId] = adventurer;
}
window.localStorage.setItem("savedGame", JSON.stringify({ window.localStorage.setItem("savedGame", JSON.stringify({
guild: data.guild, guild: data.guild,
adventurers: data.adventurers, adventurers: adventurers,
missives: data.missives, missives: data.missives,
lastQuestGot: data.lastQuestGot, lastQuestGot: data.lastQuestGot,
lastRecruitAction: data.lastRecruitAction, lastRecruitAction: data.lastRecruitAction,