changeset 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
files index-rlg.html rlgterm.js
diffstat 2 files changed, 20 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/index-rlg.html	Sat Jun 09 15:22:56 2012 -0700
+++ b/index-rlg.html	Sat Jun 09 17:00:25 2012 -0700
@@ -86,22 +86,7 @@
 </div>
 </div>
 <div class="modal" id="startgame">
-<form id="startform" action="/play" method="post">
-<div>
-Choose game: <select name="game" id="input_game">
-  <option label="Rogue V3" value="rogue3">Rogue V3</option>
-  <option label="Rogue V4" value="rogue4">Rogue V4</option>
-  <option label="Rogue V5" value="rogue5">Rogue V5</option>
-  <option label="Super-Rogue" value="srogue">Super-Rogue</option>
-</select>
-</div>
-<div>
-<input type="submit" value="Play" onclick="startgame(event)">
-</div>
-</form>
-<div id="opttable">
-  <div><div>Game</div><div>Actions</div></div>
-</div>
+<div id="opttable"><div><div>Game</div><div>Actions</div></div></div>
 </div>
 <div class="modal" id="login">
 <form id="loginform" action="/login" method="post">
--- 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();