diff rlgterm.js @ 89:6145e1ea7ace

RLG-Web: add a new message framework. Add a message() function meant for UI messages, not debugging info.
author John "Elwin" Edwards <elwin@sdf.org>
date Tue, 10 Jul 2012 08:08:54 -0700
parents d644e7d46852
children 6c6a6e4f1e5b
line wrap: on
line diff
--- a/rlgterm.js	Mon Jul 09 12:51:12 2012 -0700
+++ b/rlgterm.js	Tue Jul 10 08:08:54 2012 -0700
@@ -261,7 +261,8 @@
 }
 
 function errHandler() {
-  debug(1, "Server unavailable?");
+  //debug(1, "Server unavailable?");
+  message("Unable to connect to the server.");
 }
 
 function sendback(str) {
@@ -445,11 +446,13 @@
       session.lcred = reply.k;
       session.lname = reply.u;
       setTitle("Logged in as " + reply.u);
-      debug(1, "Logged in as " + reply.u + " with id " + reply.k);
+      debug(0, "Logged in as " + reply.u + " with id " + reply.k);
+      message("You are now logged in as " + reply.u + ".");
       setmode("choose");
     }
     else if (reply.t == 'E') {
-      debug(1, "Could not log in: " + reply.s);
+      debug(0, "Could not log in: " + reply.s);
+      message("Logging in failed: " + reply.s);
       document.getElementById("input_name").value = "";
       document.getElementById("input_pw").value = "";
     }
@@ -622,11 +625,13 @@
       termemu.resize(reply.h, reply.w);
       setTitle("Playing as " + session.lname);
       debug(1, "Playing with id " + session.id);
+      message("Your game has started.");
       setmode("play");
       getData();
     }
     else if (reply.t == 'E') {
       debug(1, "Could not start game: " + reply.s);
+      message("Your game could not be started: " + reply.s);
       if (reply.c == 1) {
         logout();
       }
@@ -656,11 +661,13 @@
       termemu.toAltBuf();
       setTitle("Watching");
       debug(1, "Watching with id " + session.id);
+      message("You are now watching.");
       setmode("play");
       getData();
     }
     else if (reply.t == 'E') {
       debug(1, "Could not watch game " + gamenumber + ": " + reply.s);
+      message("The game could not be watched: " + reply.s);
       getcurrent();
     }
   };
@@ -693,14 +700,17 @@
     if (reply.t == 'r') {
       /* Success */
       debug(1, "Registered account: " + reply.u);
+      message("Welcome " + reply.u + ", you are now registered.");
       session.lcred = reply.k;
       session.lname = reply.u;
       setTitle("Logged in as " + session.lname);
       debug(1, "Logged in as " + session.lname + " with id " + session.lcred);
+      message("You are now logged in as " + reply.u + ".");
       setmode("choose");
     }
     else if (reply.t == 'E') {
       debug(1, "Could not register: " + reply.s);
+      message("Registration failed.");
       document.getElementById("regin_name").value = "";
       document.getElementById("regin_pw").value = "";
       document.getElementById("regin_email").value = "";
@@ -797,6 +807,14 @@
     element.style.display = "none";
 }
 
+function message(msg, type) {
+  var msgdiv = document.createElement("div");
+  var msgtext = document.createTextNode(msg);
+  msgdiv.appendChild(msgtext);
+  var msgcontainer = document.getElementById("messages");
+  msgcontainer.insertBefore(msgdiv, msgcontainer.firstChild);
+}
+
 function debug(level, msg) {
   if (level < debugSuppress)
     return;