summaryrefslogtreecommitdiff
path: root/resources/js/memory.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/memory.js')
-rw-r--r--resources/js/memory.js38
1 files changed, 37 insertions, 1 deletions
diff --git a/resources/js/memory.js b/resources/js/memory.js
index 550ea55..47cde88 100644
--- a/resources/js/memory.js
+++ b/resources/js/memory.js
@@ -53,6 +53,19 @@ const Memory = {
*/
async load (saveData) {
/**
+ * @param {Area} areaData
+ */
+ const loadArea = async (areaData) => {
+ const area = await fetchArea(areaData.slug);
+
+ area.monsterProgress = areaData.monsterProgress;
+ area.trainerProgress = areaData.trainerProgress;
+ area.isCompleted = areaData.isCompleted;
+
+ return area;
+ };
+
+ /**
* @param {Monster} monsterData
*/
const loadMonster = async (monsterData) => {
@@ -116,6 +129,15 @@ const Memory = {
};
/**
+ * @param {Trainer} trainerData
+ */
+ const loadTrainer = async (trainerData) => {
+ const trainer = new Trainer(trainerData);
+
+ return trainer;
+ };
+
+ /**
* @param {Technique} techniqueData
*/
const loadTechnique = async (techniqueData) => {
@@ -131,20 +153,34 @@ const Memory = {
*/
const loadedState = JSON.parse(atob(saveData));
- Memory.state.Settings.language = loadedState.language;
+ Memory.state.Settings.language = loadedState.Settings.language;
await fetchTranslation(Memory.state.Settings.language);
+ Memory.state.Settings.currency = loadedState.Settings.currency;
+ Memory.state.Settings.logMaxLength = loadedState.Settings.logMaxLength;
+
+ for (const areaSlug of Object.keys(loadedState.areaProgress)) {
+ const areaData = loadedState.areaProgress[areaSlug];
+ Memory.state.areaProgress[areaSlug] = await loadArea(areaData);
+ }
+ Memory.state.currentArea = await loadArea(loadedState.currentArea);
Memory.state.turn = loadedState.turn;
Memory.state.money = loadedState.money;
Memory.state.monsters = await Promise.all(loadedState.monsters.map(async (monsterData) => await loadMonster(monsterData)));
+ Memory.state.player = await loadTrainer(loadedState.player);
Memory.state.player.monsters = await Promise.all(loadedState.player.monsters.map(async (monsterData) => await loadMonster(monsterData)));
Memory.state.player.inventory = await Promise.all(loadedState.player.inventory.map(async (itemData) => await loadInventoryItem(itemData)));
Memory.state.player.activeMonster = Memory.state.player.monsters[loadedState.player.activeMonsterIdx];
+ Memory.state.opponent = await loadTrainer(loadedState.opponent);
Memory.state.opponent.monsters = await Promise.all(loadedState.opponent.monsters.map(async (monsterData) => await loadMonster(monsterData)));
Memory.state.opponent.inventory = await Promise.all(loadedState.opponent.inventory.map(async (itemData) => await loadInventoryItem(itemData)));
Memory.state.opponent.activeMonster = Memory.state.opponent.monsters[loadedState.opponent.activeMonsterIdx];
+ Memory.state.rivalMonster = loadedState.rivalMonster;
Memory.state.activeTechnique = await loadTechnique(loadedState.activeTechnique);
+ Memory.state.activeBall = await loadInventoryItem(loadedState.activeBall);
+ UI.drawArea(Memory.state.currentArea);
+ UI.drawStatus();
UI.drawOpponentMonster();
UI.drawActiveMonster();
UI.drawActiveTechniques();