Switch some typeof to hasOWnProperty checks
Switch some typeof to hasOWnProperty checks
diff --git a/js/game.js b/js/game.js
index 9aa62fe..a34c312 100644
--- a/js/game.js
+++ b/js/game.js
@@ -532,7 +532,7 @@ class Location
for (const content_area of content_areas) {
let content = elt(content_area);
if (content_area == 'main-nav') {
- if (typeof (content.originalHTML) === 'undefined') {
+ if (!content.hasOwnProperty("originalHTML")) {
content.originalHTML = content.innerHTML;
}
content.innerHTML = interpolateVariables(content.originalHTML);
@@ -693,6 +693,11 @@ class Game
* @type {number}
*/
tick = 0;
+ /**
+ * Whether this particular game has a nav bar
+ * @type {boolean}
+ */
+ hasNavBar;
/**
* The list of all Game Object's managed by the FRISE script. An object
* can be used to represent a thing such as a person, tool, piece of
@@ -759,7 +764,7 @@ class Game
* tag in the HTML file for the game. If this tag is not present, the
* game will not have a main navigation bar and menu.
*/
- initializesMainNavGameContentArea()
+ initializeMainNavGameContentArea()
{
let body_objs = tag("body");
if (body_objs[0] === undefined) {
@@ -775,8 +780,10 @@ class Game
let main_nav_objs = tag("x-main-nav");
if (typeof main_nav_objs[0] === "undefined") {
game_screen.innerHTML = `<div id="game-content"></div>`;
+ this.hasNavBar = false;
return;
}
+ this.hasNavBar = true;
let main_nav_obj = main_nav_objs[0];
let history_buttons;
if (is_right_to_left) {
@@ -854,11 +861,11 @@ class Game
this.locations = xtag("x-location");
for (const oid in this.objects) {
let object = this.objects[oid];
- if (typeof object.position !== 'undefined') {
+ if (object.hasOwnProperty("position")) {
let location_name = object.position;
- if (typeof this.locations[location_name] !== 'undefined') {
+ if (this.locations.hasOwnProperty(location_name)) {
let location = this.locations[location_name]
- if (typeof location.items == "undefined") {
+ if (!location.hasOwnProperty("items")) {
location.items = [];
}
location.items.push(object.id);
@@ -911,7 +918,7 @@ class Game
let old_objects = this.objects;
this.objects = game_state.objects;
for (const field in old_objects) {
- if (typeof this.objects[field] === 'undefined') {
+ if (!this.objects.hasOwnProperty(field)) {
/* we assume our game never deletes objects or locations, so
if we find an object in old_objects (presumably coming
from a more recently parse HTML file) that was not
@@ -919,9 +926,9 @@ class Game
*/
this.objects[field] = old_objects[field];
} else {
- if (typeof old_objects['action'] !== 'undefined') {
+ if (old_objects.hasOwnProperty('action')) {
this.objects['action'] = old_objects['action'];
- } else if (typeof this.objects['action'] !== 'undefined') {
+ } else if (this.objects.hasOwnProperty('action')) {
delete this.objects['action'];
}
}
@@ -931,7 +938,7 @@ class Game
let location;
this.locations = {};
for (const location_name in old_locations) {
- if (typeof locations[location_name] === 'undefined') {
+ if (!locations.hasOwnProperty(location_name)) {
location = old_locations[location_name];
} else {
let location_object = locations[location_name];
@@ -940,8 +947,8 @@ class Game
location[field] = location_object[field];
if (field == 'present' || field == 'action' ||
field == 'default-action') {
- if (typeof old_locations[location_name][field] ===
- 'undefined') {
+ if (!old_locations[
+ location_name].hasOwnProperty(field)) {
delete location[field];
} else {
location[field] =
@@ -1095,7 +1102,7 @@ class Game
{
let i = 1;
let saves_location = game.locations['saves'];
- while (typeof saves_location['filename' + i] !== 'undefined') {
+ while (saves_location.hasOwnProperty('filename' + i)) {
this.deleteSlot(i);
i++;
}
@@ -1167,12 +1174,14 @@ class Game
*/
takeTurn(hash)
{
- if (hash == "#previous") {
- this.previousHistory();
- return;
- } else if (hash == "#next") {
- this.nextHistory();
- return;
+ if (this.hasNavBar) {
+ if (hash == "#previous") {
+ this.previousHistory();
+ return;
+ } else if (hash == "#next") {
+ this.nextHistory();
+ return;
+ }
}
let new_game_state;
if (sessionStorage.current) {
@@ -1182,7 +1191,9 @@ class Game
return;
}
this.future_history = [];
- elt('next-history').disabled = true;
+ if (this.hasNavBar) {
+ elt('next-history').disabled = true;
+ }
if (sessionStorage.current) {
this.history.push(new_game_state);
}
@@ -1190,10 +1201,12 @@ class Game
this.evaluateDefaultActions(this.locations);
sessionStorage.current = this.captureState();
this.describeMainCharacterLocation();
- if (this.history.length == 0) {
- elt('previous-history').disabled = true;
- } else {
- elt('previous-history').disabled = false;
+ if (this.hasNavBar) {
+ if (this.history.length == 0) {
+ elt('previous-history').disabled = true;
+ } else {
+ elt('previous-history').disabled = false;
+ }
}
}
/**
@@ -1225,7 +1238,7 @@ class Game
if (!move_object || !this.locations[destination_id]) {
return false;
}
- if (typeof move_object.position !== 'undefined') {
+ if (move_object.hasOwnProperty("position")) {
let old_position = move_object.position;
let old_location = this.locations[old_position];
old_location.items.filter((value) => {