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.js115
1 files changed, 67 insertions, 48 deletions
diff --git a/resources/js/memory.js b/resources/js/memory.js
index 972dac7..f8d8a82 100644
--- a/resources/js/memory.js
+++ b/resources/js/memory.js
@@ -187,57 +187,76 @@ const Memory = {
*/
const loadedState = saveData;
- Memory.state.Settings.name = loadedState.Settings.name;
- Memory.state.Settings.language = loadedState.Settings.language;
- await fetchTranslation(Memory.state.Settings.language);
- applyTranslation();
- Memory.state.Settings.currency = loadedState.Settings.currency;
- Memory.state.Settings.logMaxLength = loadedState.Settings.logMaxLength;
-
- if (loadedState.Game) { // backwards compat: TODO: remove check later
- Memory.state.Game.isInBattle = loadedState.Game.isInBattle;
- }
+ const loadActions = [
+ async () => Memory.state.Settings.name = loadedState.Settings.name,
+ async () => Memory.state.Settings.language = loadedState.Settings.language,
+ async () => {
+ await fetchTranslation(Memory.state.Settings.language);
+ applyTranslation();
+ },
+ async () => Memory.state.Settings.currency = loadedState.Settings.currency,
+ async () => Memory.state.Settings.logMaxLength = loadedState.Settings.logMaxLength,
+
+
+ async () => {
+ if (loadedState.Game) { // backwards compat: TODO: remove check later
+ Memory.state.Game.isInBattle = loadedState.Game.isInBattle;
+ }
+ },
+
+
+ ...Object.keys(loadedState.areaProgress).map((areaSlug) => async () => {
+ const areaData = loadedState.areaProgress[areaSlug];
+ Memory.state.areaProgress[areaSlug] = await loadArea(areaData);
+ }),
+ async () => Memory.state.currentArea = await loadArea(loadedState.currentArea),
+ async () => Memory.state.lastVisitedTown = loadedState.lastVisitedTown,
+ async () => Memory.state.storyProgress = loadedState.storyProgress || {}, // backwards compat: TODO: remove check later
+ async () => Memory.state.currentStory = loadedState.currentStory || '', // backwards compat: TODO: remove check later
+
+
+ async () => Memory.state.turn = loadedState.turn,
+ async () => Memory.state.money = loadedState.money,
+
+
+ async () => Memory.state.monsters = [],
+ ...loadedState.monsters.map((monsterData) => async () => Memory.state.monsters.push(await loadMonster(monsterData))),
+ async () => Memory.state.player = await loadTrainer(loadedState.player),
+ ...loadedState.player.monsters.map((monsterData) => async () => Memory.state.player.monsters.push(await loadMonster(monsterData))),
+ ...loadedState.player.inventory.map((itemData) => async () => Memory.state.player.inventory.push(await loadInventoryItem(itemData))),
+ async () => Memory.state.player.activeMonster = Memory.state.player.monsters[loadedState.player.activeMonsterIdx],
+ async () => Memory.state.opponent = await loadTrainer(loadedState.opponent),
+ ...loadedState.opponent.monsters.map((monsterData) => async () => Memory.state.opponent.monsters.push(await loadMonster(monsterData))),
+ ...loadedState.opponent.inventory.map((itemData) => async () => Memory.state.opponent.inventory.push(await loadInventoryItem(itemData))),
+ async () => Memory.state.opponent.activeMonster = Memory.state.opponent.monsters[loadedState.opponent.activeMonsterIdx],
+ async () => Memory.state.rivalMonster = loadedState.rivalMonster,
+ async () => Memory.state.activeTechnique = await loadTechnique(loadedState.activeTechnique),
+
+ async () => {
+ if (typeof loadedState.activeBall === 'string') { // backwards compat: TODO: remove check later
+ Memory.state.activeBall = loadedState.activeBall;
+ } else {
+ Memory.state.activeBall = loadedState.activeBall && loadedState.activeBall.slug;
+ }
+ },
- 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.lastVisitedTown = loadedState.lastVisitedTown;
- Memory.state.storyProgress = loadedState.storyProgress || {}; // backwards compat: TODO: remove check later
- Memory.state.currentStory = loadedState.currentStory || ''; // backwards compat: TODO: remove check later
-
- 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);
-
- if (typeof loadedState.activeBall === 'string') { // backwards compat: TODO: remove check later
- Memory.state.activeBall = loadedState.activeBall;
- } else {
- Memory.state.activeBall = loadedState.activeBall && loadedState.activeBall.slug;
- }
- // draw game
- if (!Game.isTown(Memory.state.currentArea)) {
- UI.drawOpponentMonster();
- UI.drawActiveMonster();
- UI.drawActiveTechniques();
- }
- UI.drawArea();
- UI.drawStatus();
- UI.closeAllPopups();
+ // draw game
+ async () => {
+ if (!Game.isTown(Memory.state.currentArea)) {
+ UI.drawOpponentMonster();
+ UI.drawActiveMonster();
+ UI.drawActiveTechniques();
+ }
+ UI.drawArea();
+ UI.drawStatus();
+ },
+
+
+ async () => Story.progress(Memory.state.currentStory),
+ ];
- Story.progress(Memory.state.currentStory);
+ await UI.showLoading(loadActions);
},
/**