Adds helper functions mc(), here(), isHere(). Adds Location.visited which counts number of times main-character visited a location. Fixes bug in display of select tags

Chris Pollett [2023-03-18 17:Mar:th]
Adds helper functions mc(), here(), isHere(). Adds Location.visited which counts number of times main-character visited a location. Fixes bug in display of select tags
Filename
css/game.css
js/game.js
diff --git a/css/game.css b/css/game.css
index dae38e0..102b4b9 100644
--- a/css/game.css
+++ b/css/game.css
@@ -300,6 +300,12 @@ input
     font-size: 18pt;
     padding: 2px;
 }
+a.disabled
+{
+    color: gray;
+    cursor: default;
+    pointer-events: none;
+}
 x-button
 {
     background-color: #F0F0F6;
diff --git a/js/game.js b/js/game.js
index ba64950..4947f8c 100644
--- a/js/game.js
+++ b/js/game.js
@@ -495,6 +495,34 @@ function loc(location_id)
 {
     return game.locations[location_id];
 }
+/**
+ * Returns the game object associated with the main-character. This
+ * function is just an abbreviation for obj('main-character')
+ * @return {object} game object associated with main-character
+ */
+function mc()
+{
+    return game.objects['main-character'];
+}
+/**
+ * Returns the location object associated with the main-character current
+ * position.
+ * @return {Location} associated with main-character position
+ */
+function here()
+{
+    return game.locations[game.objects['main-character'].position];
+}
+/**
+ * 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
+ * @return {boolean} where the main-character is in the room of the current
+ *  default action
+ */
+function isHere()
+{
+    return game.is_here;
+}
 /**
  * Encapsulates one place that objects can be in a Game.
  */
@@ -506,6 +534,11 @@ class Location
      * @type {Array}
      */
     present = [];
+    /**
+     * Number of times main-character has visited a location
+     * @type {int}
+     */
+    visited = 0;
     /**
      * Used to display a description of a location to the game content
      * area. This description is based on the x-present tags that were
@@ -609,7 +642,11 @@ class Location
                                         control_field.value =
                                             target_object[target_field];
                                     }
-                                } else {
+                                } else if (target_object[target_field]) {
+                                    /* if don't check
+                                       target_object[target_field] not empty
+                                       then select tags get extra blank option
+                                     */
                                     control_field.value =
                                         target_object[target_field];
                                 }
@@ -1386,6 +1423,12 @@ class Game
     {
         for (const object_name in x_entities) {
             let game_entity = x_entities[object_name];
+            if (mc().position == object_name && game_entity
+                instanceof Location) {
+                game['is-here'] = true;
+            } else {
+                game['is-here'] = false;
+            }
             if (game_entity && game_entity['default-action']) {
                 this.evaluateAction(game_entity['default-action']);
             }
@@ -1467,6 +1510,7 @@ class Game
             mc.old_position = mc.position;
         }
         this.moveObject('main-character', destination);
+        this.locations[mc.position].visited++;
         return true;
     }
     /**
ViewGit