Fixes a bug with isHere adds baseLoc
Fixes a bug with isHere adds baseLoc
diff --git a/js/game.js b/js/game.js
index 4947f8c..e5faacb 100644
--- a/js/game.js
+++ b/js/game.js
@@ -513,6 +513,13 @@ function here()
{
return game.locations[game.objects['main-character'].position];
}
+/**
+ * Returns the Location object the player begins the game at
+ */
+function baseLoc()
+{
+ return game.locations[game.base_location];
+}
/**
* For use in default actions only!!! Returns whether the main-character is
* in the Location of the default action. In all other cases returns false
@@ -521,7 +528,7 @@ function here()
*/
function isHere()
{
- return game.is_here;
+ return game['is_here'];
}
/**
* Encapsulates one place that objects can be in a Game.
@@ -868,6 +875,17 @@ class Game
* @type {Array}
*/
future_history;
+ /**
+ * Id of first room main-character is in;
+ * @type {String}
+ */
+ base_location;
+ /**
+ * Is set to true just before a default action for a location the
+ * main character is at is executed; otherwise, false
+ * @type {Boolean}
+ */
+ is_here;
/**
* Sets up a game object with empty history, an initialized main navigation,
* and with objects and locations parsed out of the current HTML file
@@ -1078,6 +1096,7 @@ class Game
game.timestamp = date + " " + time;
return JSON.stringify({
timestamp: game.timestamp,
+ base_location: game.base_location,
objects: this.objects,
locations: this.locations
});
@@ -1098,6 +1117,7 @@ class Game
return false;
}
this.timestamp = game_state.timestamp;
+ this.base_location = game_state.base_location;
/*
during development, changing an object or location's text might
not be viewable on a reload unless we copy some fields of the
@@ -1425,9 +1445,9 @@ class Game
let game_entity = x_entities[object_name];
if (mc().position == object_name && game_entity
instanceof Location) {
- game['is-here'] = true;
+ game['is_here'] = true;
} else {
- game['is-here'] = false;
+ game['is_here'] = false;
}
if (game_entity && game_entity['default-action']) {
this.evaluateAction(game_entity['default-action']);
@@ -1557,6 +1577,8 @@ async function initGame()
use_session = true;
game.restoreState(sessionStorage["current" + game.id]);
game.reload = true;
+ } else {
+ game.base_location = game.objects['main-character'].position;
}
game.takeTurn("");
game.clearHistory();