]> git.cworth.org Git - lmno-server/commitdiff
Add first use of Game.meta to both the Empires and TicTacToe classes
authorCarl Worth <cworth@cworth.org>
Sun, 31 May 2020 23:40:22 +0000 (16:40 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 1 Jun 2020 00:09:57 +0000 (17:09 -0700)
So far, we just set a name field, then we access this name field from
a game instance in each of the implementations of the route handler
for the root path. In each case this is to provide the name of the
game as context for the rendering of the choose-nickname template.

The reason for all of this is to enable convergence of the code
handling that route, (since as soon as the code is precisely common
between both games the code can move up into the base class).

It's close here, but will also need to be able to select the proper
template in the case where a nickname is already chosen.

empires.js
tictactoe.js

index 38d892bde64620d7e4a6e4c0ff186f79813c222d..8713c6cf2f3d903b40b7a2597e0339161f39514c 100644 (file)
@@ -250,8 +250,10 @@ class Empires extends Game {
 }
 
 router.get('/', (request, response) => {
+  const game = request.game;
+
   if (! request.session.nickname)
-    response.render('choose-nickname.html', { game_name: "Empires" });
+    response.render('choose-nickname.html', { game_name: game.meta.name });
   else
     response.render('empires-game.html');
 });
@@ -356,3 +358,9 @@ router.get('/events', (request, response) => {
 exports.router = router;
 exports.name = engine_name;
 exports.Game = Empires;
+
+Empires.meta = {
+  name: "Empires"
+};
+
+exports.meta = Empires.meta;
index 6d4b0148a4a12afa4a5e8046fd3c8447d9d6729d..7b7df8d4ac912da483348cb78354330eb74f5cfa 100644 (file)
@@ -42,7 +42,7 @@ router.get('/', (request, response) => {
   const game = request.game;
 
   if (! request.session.nickname)
-    response.render('choose-nickname.html', { game_name: "Tic Tac Toe" });
+    response.render('choose-nickname.html', { game_name: game.meta.name });
   else
     response.render('tictactoe-game.html');
 });
@@ -72,3 +72,9 @@ router.get('/events', (request, response) => {
 exports.router = router;
 exports.name = engine_name;
 exports.Game = TicTacToe;
+
+TicTacToe.meta = {
+  name: "Tic Tac Toe"
+};
+
+exports.meta = TicTacToe.meta;