From 49d955e6e751bbed7b4239805f046c16cb5f52d4 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 31 May 2020 16:40:22 -0700 Subject: [PATCH] Add first use of Game.meta to both the Empires and TicTacToe classes 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 | 10 +++++++++- tictactoe.js | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/empires.js b/empires.js index 38d892b..8713c6c 100644 --- a/empires.js +++ b/empires.js @@ -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; diff --git a/tictactoe.js b/tictactoe.js index 6d4b014..7b7df8d 100644 --- a/tictactoe.js +++ b/tictactoe.js @@ -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; -- 2.43.0