viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

Adds Game.debug method

Chris Pollett [2023-02-24 04:Feb:th]
Adds Game.debug method
Filename
js/game.js
diff --git a/js/game.js b/js/game.js
index 7014a6e..fac2b2a 100644
--- a/js/game.js
+++ b/js/game.js
@@ -249,6 +249,8 @@ function makeGameObject(dom_object)
         game_object.id = "oid" + object_counter;
         object_counter++;
     }
+    let has_present = false;
+    let has_position = false;
     for (const child of dom_object.children) {
         let tag_name = child.tagName;
         if (tag_name == 'SCRIPT') {
@@ -266,6 +268,7 @@ function makeGameObject(dom_object)
         if (attribute_name) {
             attribute_name = attribute_name.toLowerCase()
             if (attribute_name == 'present') {
+                has_present = true;
                 if (!game_object[attribute_name]) {
                     game_object[attribute_name] = [];
                 }
@@ -283,11 +286,19 @@ function makeGameObject(dom_object)
                 game_object[attribute_name].push([check, stage,
                 child.innerHTML]);
             } else {
+                if (attribute_name == 'position') {
+                    has_position = true;
+                }
                 game_object[attribute_name] = child.innerHTML;
             }
         }
     }
     game_object.type = type;
+    if (type == 'Location') {
+        game_object.has_present = has_present;
+    } else if (type == 'Object') {
+        game_object.has_position = has_position;
+    }
     return game_object;
 }
 /**
@@ -847,6 +858,36 @@ class Game
         this.initializeObjectsLocations();
         this.clearHistory();
     }
+    /**
+     * Writes to console information about which objects and locations
+     * might not be properly defined.
+     */
+    debug()
+    {
+        let none = "none";
+        console.log("Game objects without position:");
+        for (let obj of Object.values(this.objects)) {
+            if (!obj.has_position) {
+                console.log("  " + obj.id);
+                none = "";
+            }
+        }
+        if (none) {
+            console.log("  " + none);
+        }
+        none = "none";
+        console.log("Game locations without x-present:");
+        for (loc of  Object.values(this.locations)) {
+            if (!loc.has_present) {
+                console.log("  " +loc.id);
+                none = "";
+            }
+        }
+        if (none) {
+            console.log("  " + none);
+        }
+        return true;
+    }
     /**
      * Used to reset the game to the condition at the start of a game
      */
ViewGit