Mercurial > hg > rlgwebd
comparison 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 |
comparison
equal
deleted
inserted
replaced
45:1bbd0e76ba92 | 46:59ecd99845eb |
---|---|
438 else | 438 else |
439 continue; | 439 continue; |
440 var button = document.createElement("span"); | 440 var button = document.createElement("span"); |
441 button.appendChild(document.createTextNode(acttext)); | 441 button.appendChild(document.createTextNode(acttext)); |
442 button.className = "ibutton"; | 442 button.className = "ibutton"; |
443 if ("s0".indexOf(reply.stat[gname]) >= 0) { | |
444 button.onclick = makeStarter(gname); | |
445 } | |
443 var actdiv = document.createElement("div"); | 446 var actdiv = document.createElement("div"); |
444 actdiv.appendChild(button); | 447 actdiv.appendChild(button); |
445 var gamediv = document.createElement("div"); | 448 var gamediv = document.createElement("div"); |
446 gamediv.appendChild(document.createTextNode(games[gname].name)); | 449 gamediv.appendChild(document.createTextNode(games[gname].name)); |
447 var rowdiv = document.createElement("div"); | 450 var rowdiv = document.createElement("div"); |
453 req.open('GET', '/pstatus/' + lname, true); | 456 req.open('GET', '/pstatus/' + lname, true); |
454 req.send(); | 457 req.send(); |
455 return; | 458 return; |
456 } | 459 } |
457 | 460 |
458 function startgame(ev) { | 461 /* This can't be in the loop in getchoices(), or the closure's scope will |
459 ev.preventDefault(); | 462 * get overwritten on the next iteration, and then all the games end up |
463 * being Super-Rogue. | |
464 */ | |
465 function makeStarter(gname) { | |
466 if (!(gname in games)) | |
467 return null; | |
468 var game = games[gname]; | |
469 function starter(ev) { | |
470 startgame(game); | |
471 } | |
472 return starter; | |
473 } | |
474 | |
475 function startgame(game) { | |
460 if (termemu.sessid != null || !lcred) | 476 if (termemu.sessid != null || !lcred) |
461 return; | 477 return; |
462 var smsg = {}; | 478 var smsg = {}; |
463 smsg["key"] = lcred; | 479 smsg["key"] = lcred; |
464 smsg["game"] = document.getElementById("input_game").value; | 480 smsg["game"] = game.uname; |
465 smsg["h"] = 24; | 481 smsg["h"] = 24; |
466 smsg["w"] = 80; | 482 smsg["w"] = 80; |
467 var req = new XMLHttpRequest(); | 483 var req = new XMLHttpRequest(); |
468 req.onreadystatechange = function () { | 484 req.onreadystatechange = function () { |
469 if (req.readyState != 4 || req.status != 200) | 485 if (req.readyState != 4 || req.status != 200) |