changeset 186:674e8899703b

Client: improve messages at the end of watching a game. The messages differentiate between the user stopping watching and the watched game coming to an end.
author John "Elwin" Edwards
date Tue, 20 Jan 2015 16:06:12 -0500
parents bbfda4a4eb7f
children 12a733792e0b
files rlgterm.js
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/rlgterm.js	Tue Jan 20 10:17:05 2015 -0500
+++ b/rlgterm.js	Tue Jan 20 16:06:12 2015 -0500
@@ -30,6 +30,10 @@
   /* Login name and key are now in sessionStorage. */
   /* Whether the game is being played or just watched. */
   playing: false,
+  /* If watching, the name of the player. */
+  playername: null,
+  /* Whether the Stop button was pushed. */
+  leaving: false,
   /* WebSocket for communication */
   sock: null
 };
@@ -656,6 +660,7 @@
       termemu.toAltBuf();
       var pname = msgObject.p;
       var gname = games[msgObject.g].name;
+      session.playername = pname;
       message("You are now watching " + pname + " play " + gname + ".");
     }
     else if (msgObject.t == 'd') {
@@ -725,12 +730,23 @@
   if (!session.connect)
     return;
   /* TODO IFACE2 If the end was unexpected, tell player the game was saved. */
-  if (session.playing)
+  if (session.playing) {
     message("Finished playing.");
-  else
-    message("Finished watching.");
+  }
+  else {
+    if (session.leaving) {
+      /* Client-initiated: the user stopped watching. */
+      message("Finished watching " + session.playername + ".");
+    }
+    else {
+      /* Server-initiated: end of game. */
+      message(session.playername + " has finished playing.");
+    }
+    session.playername = null;
+  }
   session.connect = false;
   session.playing = false;
+  session.leaving = false;
   termemu.toNormBuf();
   if ("lcred" in sessionStorage)
     setmode("choose");
@@ -745,11 +761,11 @@
   setmode("login");
 }
 
-/* TODO determine whether this is needed */
 function stop() {
   if (!session.connect)
     return;
   if (session.sock) {
+    session.leaving = true;
     session.sock.close();
     return;
   }