Fix restore state on game reload
Fix restore state on game reload
diff --git a/js/game.js b/js/game.js
index afb5418..6ff7760 100644
--- a/js/game.js
+++ b/js/game.js
@@ -749,6 +749,11 @@ class Game
* @type {string}
*/
id;
+ /**
+ * Whether game page was just reloaded
+ * @type {bool}
+ */
+ reload;
/**
* Current date followed by a space followed by the current time of
* the most recent game capture. Used in providing a description of
@@ -819,6 +824,7 @@ class Game
constructor()
{
let game_elt = tag('x-game')[0];
+ this.reload = false; //current
let doc_length = 0;
let middle_five = "";
if (game_elt) {
@@ -830,7 +836,9 @@ class Game
}
// a semi-unique code for this particular game
this.id = encodeURI(middle_five + doc_length);
- this.reset();
+ this.initializeMainNavGameContentArea();
+ this.initializeObjectsLocations();
+ this.clearHistory();
}
/**
* Used to reset the game to the condition at the start of a game
@@ -1310,6 +1318,7 @@ class Game
this.evaluateDefaultActions(this.locations);
sessionStorage["current" + game.id] = this.captureState();
this.describeMainCharacterLocation();
+ game.reload = false;
if (this.has_nav_bar) {
if (this.history.length == 0) {
elt('previous-history').disabled = true;
@@ -1451,6 +1460,7 @@ async function initGame()
if (sessionStorage["current" + game.id]) {
use_session = true;
game.restoreState(sessionStorage["current" + game.id]);
+ game.reload = true;
}
game.takeTurn("");
game.clearHistory();