comparison rlgterm.js @ 44:b848cb50cd69

rlgterm.js: present game options to the player. Use the new player-status interface to display the state of any ongoing games when the player logs in.
author John "Elwin" Edwards <elwin@sdf.org>
date Sat, 09 Jun 2012 14:13:07 -0700
parents ea3b7775009d
children 1bbd0e76ba92
comparison
equal deleted inserted replaced
43:c4efc7522e7b 44:b848cb50cd69
43 } 43 }
44 else { 44 else {
45 this.set(200); 45 this.set(200);
46 this.state = 0; 46 this.state = 0;
47 } 47 }
48 }
49 };
50
51 /* Data on the available games. */
52 var games = {
53 "rogue3": {
54 "name": "Rogue V3",
55 "uname": "rogue3"
56 },
57 "rogue4": {
58 "name": "Rogue V4",
59 "uname": "rogue4"
60 },
61 "rogue5": {
62 "name": "Rogue V5",
63 "uname": "rogue5"
64 },
65 "srogue": {
66 "name": "Super-Rogue",
67 "uname": "srogue"
48 } 68 }
49 }; 69 };
50 70
51 /* Login name and key */ 71 /* Login name and key */
52 var lname = null; 72 var lname = null;
380 document.getElementById("input_pw").value = ""; 400 document.getElementById("input_pw").value = "";
381 } 401 }
382 }; 402 };
383 req.open('POST', '/login', true); 403 req.open('POST', '/login', true);
384 req.send(JSON.stringify(loginmsg)); 404 req.send(JSON.stringify(loginmsg));
405 return;
406 }
407
408 function getchoices() {
409 if (termemu.sessid != null || !lcred)
410 return;
411 var req = new XMLHttpRequest();
412 req.onreadystatechange = function () {
413 if (req.readyState != 4 || req.status != 200)
414 return;
415 var reply;
416 try {
417 reply = JSON.parse(req.responseText);
418 } catch (e) {
419 if (e instanceof SyntaxError)
420 return;
421 }
422 if (!("name" in reply) || reply["name"] != lname || !("stat" in reply))
423 return;
424 var statdiv = document.createElement("div");
425 for (var gname in reply.stat) {
426 if (!(gname in games))
427 continue;
428 var stext;
429 if (reply.stat[gname] == "s")
430 stext = games[gname].name + ": Resume your game";
431 else if (reply.stat[gname] == "0")
432 stext = games[gname].name + ": Start a game";
433 else if (reply.stat[gname] == "p")
434 stext = games[gname].name + ": Game in progress";
435 else
436 continue;
437 var tnode = document.createTextNode(stext);
438 var gamediv = document.createElement("div");
439 gamediv.appendChild(tnode);
440 statdiv.appendChild(gamediv);
441 }
442 if (!statdiv.hasChildNodes()) {
443 statdiv.appendChild(document.createTextNode("No known games?"));
444 }
445 document.getElementById("startgame").appendChild(statdiv);
446 };
447 req.open('GET', '/pstatus/' + lname, true);
448 req.send();
385 return; 449 return;
386 } 450 }
387 451
388 function startgame(ev) { 452 function startgame(ev) {
389 ev.preventDefault(); 453 ev.preventDefault();
492 if (mode == "choose") { 556 if (mode == "choose") {
493 document.getElementById("keyboard").style.display = "none"; 557 document.getElementById("keyboard").style.display = "none";
494 document.getElementById("startgame").style.display = "block"; 558 document.getElementById("startgame").style.display = "block";
495 document.getElementById("login").style.display = "none"; 559 document.getElementById("login").style.display = "none";
496 document.getElementById("register").style.display = "none"; 560 document.getElementById("register").style.display = "none";
561 getchoices();
497 } 562 }
498 else if (mode == "login") { 563 else if (mode == "login") {
499 document.getElementById("keyboard").style.display = "none"; 564 document.getElementById("keyboard").style.display = "none";
500 document.getElementById("startgame").style.display = "none"; 565 document.getElementById("startgame").style.display = "none";
501 document.getElementById("login").style.display = "block"; 566 document.getElementById("login").style.display = "block";