Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

doClick and localization default #12

Closed
wants to merge 2 commits into from

2 participants

@juhana

Here's the wrapper for processClick(). It's hard to explain the difference between that and doLink, so feel free to improve what I scribbled in the documentation.

Also, there was an issue where the script would halt if the HTML document didn't have the lang attribute, so I made it default to en if nothing else is specified.

@idmillington

Thanks again. This is great. Fixes #11 and #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 14, 2011
  1. @juhana
Commits on Sep 25, 2011
  1. @juhana
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 0 deletions.
  1. +10 −0 docs/src/API.md
  2. +13 −0 games/media/js/undum.js
View
10 docs/src/API.md
@@ -576,6 +576,16 @@ Carries out the action associated with the given URL, as if it had
been the `href` of a HTML link that the user clicked. This allows you
to procedurally change situation and carry out actions from your code.
+#### `doClick(URL)`
+
+Carries out an action just like `doLink`, but the click is saved
+to the turn sequence so that the action will be replayed when loading
+the game. `doClick` should be used only as a direct response to an
+event, for example the player clicking on a button in the user
+interface. `doLink` should be used instead when the action is a
+continuation of another action initiated by clicking on a normal link
+to avoid the action being executed twice when loading the game.
+
#### `rnd`
This holds a general purpose random number generator. It is an object
View
13 games/media/js/undum.js
@@ -441,6 +441,14 @@
System.prototype.doLink = function(code) {
processLink(code);
};
+
+ /* The same as doLink(), but the link is saved to the progress sequence
+ * so it will be "re-clicked" when the game is loaded. This should
+ * be used when the action is coming from an outside event like a timer
+ * or clicking on a button in the user interface. */
+ System.prototype.doClick = function(code) {
+ processClick(code);
+ };
/* Turns any links that target the given href into plain
* text. This can be used to remove action options when an action
@@ -1508,6 +1516,11 @@
String.prototype.l = function(args) {
// Get lang attribute from html tag.
var lang = $("html").attr("lang");
+
+ // Fall back to en if the lang attribute isn't set
+ if( typeof lang === 'undefined' ) {
+ lang = 'en';
+ }
// Find the localized form.
var localized = localize(lang, this);
Something went wrong with that request. Please try again.