diff rlgterm.js @ 176:bf518a00190b

Add client-side support for watching dgamelaunch games.
author John "Elwin" Edwards
date Wed, 14 Jan 2015 07:44:22 -0500
parents 0f6da35b27a0
children 674e8899703b
line wrap: on
line diff
--- a/rlgterm.js	Tue Jan 13 20:30:10 2015 -0500
+++ b/rlgterm.js	Wed Jan 14 07:44:22 2015 -0500
@@ -337,6 +337,7 @@
     var cell2 = document.createElement("div");
     var cell3 = document.createElement("div");
     var cell4 = document.createElement("div");
+    var cell5 = document.createElement("div");
     cell1.appendChild(document.createTextNode(gamelist[i].p));
     var uname = gamelist[i].g;
     if (uname in games)
@@ -344,16 +345,23 @@
     else {
       continue;
     }
-    cell3.appendChild(document.createTextNode(idlestr(gamelist[i].i)));
+    var srcstr = "VR";
+    if (gamelist[i].c == "rlg")
+      srcstr = "Web";
+    else if (gamelist[i].c == "dgl")
+      srcstr = "SSH";
+    cell3.appendChild(document.createTextNode(srcstr));
+    cell4.appendChild(document.createTextNode(idlestr(gamelist[i].i)));
     var button = document.createElement("span");
     button.appendChild(document.createTextNode("Watch"));
     button.onclick = makeWatcher(uname + "/" + gamelist[i].p);
     button.className = "ibutton";
-    cell4.appendChild(button);
+    cell5.appendChild(button);
     row.appendChild(cell1);
     row.appendChild(cell2);
     row.appendChild(cell3);
     row.appendChild(cell4);
+    row.appendChild(cell5);
     gamediv.appendChild(row);
   }
 }
@@ -413,6 +421,7 @@
       var justbegun = {};
       justbegun.g = msg.g;
       justbegun.p = msg.p;
+      justbegun.c = msg.c;
       justbegun.i = 0;
       currentList.push(justbegun);
       tableCurrent(currentList);
@@ -873,19 +882,20 @@
 }
 
 function idlestr(ms) {
+  /* Minute accuracy is good enough. */
   if (typeof(ms) != "number")
     return "?";
-  var seconds = Math.round(ms / 1000);
-  var ss = String(seconds % 60);
-  if (ss.length < 2)
-    ss = "0" + ss;
-  var mm = String(Math.floor((seconds % 3600) / 60));
-  if (mm.length < 2)
-    mm = "0" + mm;
-  var hh = String(Math.floor(seconds / 3600));
-  if (hh.length < 2)
-    hh = "0" + hh;
-  return hh + ":" + mm + ":" + ss;
+  var minutes = Math.round(ms / 60000);
+  if (minutes < 60)
+    return String(minutes) + " min";
+  var hours = Math.floor(minutes / 60);
+  if (hours < 24)
+    return String(hours) + " hr " + String(minutes % 60) + " min";
+  var days = Math.floor(days / 24);
+  if (days == 1)
+    return "1 day " + String(hours % 24) + " hr";
+  else
+    return String(days) + " days " + String(hours % 24) + " hr";
 }
 
 function bell(on) {