]> git.cworth.org Git - empires-server/commitdiff
LMNO: Simplify storage of the games array by not storing ID next to game
authorCarl Worth <cworth@cworth.org>
Mon, 1 Jun 2020 00:49:47 +0000 (17:49 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 1 Jun 2020 00:49:47 +0000 (17:49 -0700)
In the previous commit, we ensured that a game object always knows its
own ID, so it's unnecessary to store it alongside.

Delete this field from this anonymous object and change all references
to instead access game.id.

lmno.js
templates/admin.html

diff --git a/lmno.js b/lmno.js
index 0fd491a6293bf01672ba7d896ecea16689ce89b5..5f5b2c7248db82fbd289002033bbd4c8cc24b05b 100644 (file)
--- a/lmno.js
+++ b/lmno.js
@@ -71,7 +71,6 @@ class LMNO {
     const game = new engine.Game(id);
 
     this.games[id] = {
-      id: id,
       game: game
     };
 
@@ -136,7 +135,7 @@ app.get('/[a-zA-Z0-9]{4}', (request, response) => {
       response.sendStatus(404);
       return;
   }
-  response.redirect(301, `/${game.game.meta.identifier}/${game.id}/`);
+  response.redirect(301, `/${game.game.meta.identifier}/${game.game.id}/`);
 });
 
 /* LMNO middleware to lookup the game. */
index 051d485b962e2aebd45bf33a91fd775e1fa62cc6..4db60ce68615c905d2b8b20eea31488176e69a0f 100644 (file)
@@ -12,7 +12,7 @@
 <ul>
   {% for game in games.active %}
   <li>
-    {{ game.id }} ({{ game.game.clients.length }}/{{ game.game._players.length }} active)
+    {{ game.game.id }} ({{ game.game.clients.length }}/{{ game.game._players.length }} active)
     {% for player in game.game._players %}
       {{ player.name }}
     {% endfor %}
@@ -27,7 +27,7 @@
 <ul>
   {% for game in games.idle %}
   <li>
-    {{ game.id }} ({{ game.game._players.length }})
+    {{ game.game.id }} ({{ game.game._players.length }})
     {% for player in game.game._players %}
       {{ player.name }}
     {% endfor %}