diff --git a/js/game.js b/js/game.js
index 50d7911..4ee8960 100644
--- a/js/game.js
+++ b/js/game.js
@@ -144,14 +144,14 @@ function sleep(time) {
* of the current location.
* @return {Promise} which will be resolved which the link is clicked.
*/
-function proceedClick(message)
+function clickProceed(message)
{
let game_content = elt("game-content");
game.tick++;
game_content.innerHTML +=
- `<a id='proceed-click${game.tick}' href=''>${message}</a>`;
+ `<a id='click-proceed${game.tick}' href=''>${message}</a>`;
return new Promise(resolve =>
- elt(`proceed-click${game.tick}`).addEventListener("click", resolve));
+ elt(`click-proceed${game.tick}`).addEventListener("click", resolve));
}
/**
* Creates from an HTMLCollection or Nodelist of x-object or x-location
@@ -381,7 +381,7 @@ function addListenersAnchors(anchors)
* game content area. The current place where this is used
* is at the start of rendering a location. A location
* might have several x-present tags, some of which could
- * be drawn after a proceedClick, or a delay. As these
+ * be drawn after a clickProceed, or a delay. As these
* steps in rendering are not good "save places", at the
* start of rendering a location all save are disabled.
* Only after the last drawable x-present for a location
@@ -419,10 +419,7 @@ function enableSavesAndInventory()
/**
* Given a string which may contain Javascript string interpolation expressions,
* i.e., ${some_expression}, produces a string where those expressions have
- * been replaces with their values. This method performs a replacement for
- * loc(location_id) and obj(object_id) with the action Javascript objects
- * game.locations['location_id'] and game.objects['object_id'] before evaluating
- * expression.
+ * been replaces with their values.
*
* @param {string} text to have Javascript interpolation expressions replaced
* values
@@ -430,14 +427,6 @@ function enableSavesAndInventory()
*/
function interpolateVariables(text)
{
- let old_text = "";
- while (old_text != text) {
- old_text = text;
- text = text.replace(/obj(?:ect)?\(([^)]+)\);?/,
- "game.objects['$1']");
- text = text.replace(/loc(?:ation)?\(([^)]+)\);?/,
- "game.locations['$1']");
- }
old_text = "";
while (old_text != text) {
old_text = text;
@@ -457,6 +446,24 @@ function interpolateVariables(text)
}
return text;
}
+/**
+ * Returns the game object with the provided id.
+ * @param {string} object_id to get game object for
+ * @return {object} game object associated with object_id if it exists
+ */
+function obj(object_id)
+{
+ return game.objects[object_id];
+}
+/**
+* Returns the game location with the provided id.
+* @param {string} object_id to get game Location for
+* @return {Location} game location associated with object_id if it exists
+ */
+function loc(location_id)
+{
+ return game.locations[location_id];
+}
/**
* Encapsulates one place that objects can be in a Game.
*/
@@ -499,7 +506,7 @@ class Location
if (check_result) {
if (proceed) {
let old_inner_html = game_content.innerHTML;
- event = await proceedClick(proceed);
+ event = await clickProceed(proceed);
event.preventDefault();
game_content.innerHTML = old_inner_html;
} else if (pause) {
@@ -573,12 +580,12 @@ class Location
*
* @param {string} condition contents from a ck attribute.
* Conditions can be boolean conditions on game variable, delay conditions,
- * or proceedClick condition.
+ * or clickProceed condition.
* @return {Array} [check_result, proceed, pause] if the condition involved
* a boolean expression, then check_result will hold the result of
* the expression (so the caller then could prevent the the display of
* an x-present tag if false), proceed is the link text (if any) for a
- * link if the condition involved a proceedClick (which is supposed to
+ * link if the condition involved a clickProceed (which is supposed to
* delay the presentation of the x-present tag until after the user
* clicks the link), pause (if non zero) is the number of miliseconds
* to sleep before presenting the x-pressent tag according to the condition
@@ -595,19 +602,15 @@ class Location
let old_check = "";
while (old_check != check) {
old_check = check;
- check = check.replace(/obj(?:ect)?\(([^)]+)\);?/,
- "game.objects['$1']");
- check = check.replace(/loc(?:ation)?\(([^)]+)\);?/,
- "game.locations['$1']");
let click_pattern =
- /(?:clickProceed|waitClick)\(([^)]+)\);?/;
+ /clickProceed\([\'\"]([^)]+)[\'\"]\);?/;
let click_match = check.match(click_pattern);
if (click_match) {
proceed = click_match[1];
check = "";
break;
}
- let pause_pattern = /(?:sleep|delay|pause)\(([^)]+)\);?/;
+ let pause_pattern = /sleep\(([^)]+)\);?/;
let pause_match = check.match(pause_pattern);
if (pause_match) {
pause += parseInt(pause_match[1]);
@@ -691,7 +694,7 @@ class Game
timestamp;
/**
* A counter that is incremented each time Javascript draws a new
- * proceedClick a tag. Each such tag is given a id, tick is ensure these
+ * clickProceed a tag. Each such tag is given a id, tick is ensure these
* id's are unique.
* @type {number}
*/
@@ -1310,13 +1313,11 @@ class Game
}
/**
* Given a string holding pre-Javascript code from an x-action tag,
- * converts any loc(id) or obj(id) subtrings into game.location['id'],
- * game.object['id'] then evaluates the code. If this function
- * is passed additional arguments then an args array is set up
- * that can be used as closure variable for this eval call.
+ * evaluates the code. If this function is passed additional arguments
+ * then an args array is set up that can be used as closure variable for
+ * this eval call.
*
- * @param {string} code pre-Javascript code, after the loc(id), and
- * obj(id) replacements mentioned above should be valid Javascript.
+ * @param {string} Javascript code.
*/
evaluateAction(code)
{
@@ -1326,14 +1327,6 @@ class Game
args = arguments[1];
}
}
- let old_code = "";
- while (old_code != code) {
- old_code = code;
- code = code.replace(/obj(?:ect)?\(([^)]+)\);?/,
- "game.objects['$1']");
- code = code.replace(/loc(?:ation)?\(([^)]+)\);?/,
- "game.locations['$1']");
- }
eval(code);
}
/**