diff rlgterm.js @ 46:59ecd99845eb

rlgterm.js: make the options table functional. Enable launching games from the options table, and replace the old select dialog.
author John "Elwin" Edwards <elwin@sdf.org>
date Sat, 09 Jun 2012 17:00:25 -0700
parents 1bbd0e76ba92
children 27b7f0c8b9f0
line wrap: on
line diff
--- a/rlgterm.js	Sat Jun 09 15:22:56 2012 -0700
+++ b/rlgterm.js	Sat Jun 09 17:00:25 2012 -0700
@@ -440,6 +440,9 @@
       var button = document.createElement("span");
       button.appendChild(document.createTextNode(acttext));
       button.className = "ibutton";
+      if ("s0".indexOf(reply.stat[gname]) >= 0) {
+        button.onclick = makeStarter(gname);
+      }
       var actdiv = document.createElement("div");
       actdiv.appendChild(button);
       var gamediv = document.createElement("div");
@@ -455,13 +458,26 @@
   return;
 }
 
-function startgame(ev) {
-  ev.preventDefault();
+/* This can't be in the loop in getchoices(), or the closure's scope will
+ * get overwritten on the next iteration, and then all the games end up 
+ * being Super-Rogue.
+ */
+function makeStarter(gname) {
+  if (!(gname in games))
+    return null;
+  var game = games[gname];
+  function starter(ev) {
+    startgame(game);
+  }
+  return starter;
+}
+
+function startgame(game) {
   if (termemu.sessid != null || !lcred)
     return;
   var smsg = {};
   smsg["key"] = lcred;
-  smsg["game"] = document.getElementById("input_game").value;
+  smsg["game"] = game.uname;
   smsg["h"] = 24;
   smsg["w"] = 80;
   var req = new XMLHttpRequest();