From 974aedf2e765ce8e102b18eeb67a3c2995801349 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 9 Jun 2022 17:19:51 +0200 Subject: Show player name instead of role in Turn and Result columns. --- server.js | 60 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 19 deletions(-) (limited to 'server.js') diff --git a/server.js b/server.js index 1210e62..dbb11d1 100644 --- a/server.js +++ b/server.js @@ -1034,35 +1034,57 @@ function format_options(options) { } function annotate_game(game, user_id) { - let players = SQL_SELECT_PLAYERS_JOIN.all(game.game_id); + let players = SQL_SELECT_PLAYERS_JOIN.all(game.game_id) + + game.human_options = format_options(game.options) + game.is_ready = RULES[game.title_id].ready(game.scenario, JSON.parse(game.options), players) + game.is_active = is_active(game, players, user_id) + game.is_shared = is_shared(game, players, user_id) + game.is_yours = false + game.your_role = null + game.player_names = players.map(p => { - let name = p.name.replace(/ /g, '\xa0'); - return p.user_id > 0 ? `${name}` : name; - }).join(", "); - game.options = format_options(game.options); - game.is_active = is_active(game, players, user_id); - game.is_shared = is_shared(game, players, user_id); - game.is_yours = false; - game.your_role = null; + let name = p.name.replace(/ /g, '\xa0') + if (p.user_id > 0) + name = `${name}` + if (game.status === 0 && p.user_id === game.owner_id) + name = `${name}` + return name + }).join(", ") + if (user_id > 0) { for (let i = 0; i < players.length; ++i) { if (players[i].user_id === user_id) { - game.is_yours = 1; - game.your_role = players[i].role; + game.is_yours = 1 + game.your_role = players[i].role } } } - game.ctime = human_date(game.ctime); - game.mtime = human_date(game.mtime); + + if (!game.is_shared) { + for (let i = 0; i < players.length; ++i) { + if (game.active === players[i].role) { + game.active = `${players[i].name}` + break + } + } + if (game.status > 1) { + for (let i = 0; i < players.length; ++i) { + if (game.result === players[i].role) { + game.result = `${players[i].name}` + break + } + } + } + } + + game.ctime = human_date(game.ctime) + game.mtime = human_date(game.mtime) } function annotate_games(games, user_id) { - for (let i = 0; i < games.length; ++i) { - let game = games[i]; - let players = SQL_SELECT_PLAYERS_JOIN.all(game.game_id); - game.is_ready = RULES[game.title_id].ready(game.scenario, JSON.parse(game.options), players); - annotate_game(game, user_id); - } + for (let i = 0; i < games.length; ++i) + annotate_game(games[i], user_id) } app.get('/profile', must_be_logged_in, function (req, res) { -- cgit v1.2.3