From 8175df9f9af2393964f053af5a98851c376e1675 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 11 Jun 2022 02:06:51 +0200 Subject: Use game boxes instead of tables. --- server.js | 93 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 46 insertions(+), 47 deletions(-) (limited to 'server.js') diff --git a/server.js b/server.js index ad13b88..e8d9c14 100644 --- a/server.js +++ b/server.js @@ -1009,14 +1009,6 @@ function is_active(game, players, user_id) { return false } -function is_shared(game, players, user_id) { - let n = 0 - for (let i = 0; i < players.length; ++i) - if (players[i].user_id === user_id) - ++n - return n > 1 -} - function is_solo(players) { return players.every(p => p.user_id === players[0].user_id) } @@ -1027,53 +1019,60 @@ function format_options(options) { if (k === false) return 'no' return k.replace(/_/g, " ").replace(/^\w/, c => c.toUpperCase()) } - if (!options || options === '{}') - return "None" - options = JSON.parse(options) return Object.entries(options||{}).map(([k,v]) => (v === true || v === 1) ? to_english(k) : `${to_english(k)}=${to_english(v)}`).join(", ") } function annotate_game(game, user_id) { let players = SQL_SELECT_PLAYERS_JOIN.all(game.game_id) + let options = JSON.parse(game.options) - 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') - if (p.user_id > 0) - 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 - } - } - } + if (game.options === '{}') + game.human_options = "None" + else + game.human_options = format_options(options) - if (!game.is_shared) { - for (let i = 0; i < players.length; ++i) { - if (game.active === players[i].role) { - game.active = `${players[i].name}` - break - } + game.is_ready = RULES[game.title_id].ready(game.scenario, options, players) + + let your_count = 0 + let your_role = null + game.player_names = "" + for (let i = 0; i < players.length; ++i) { + let p = players[i] + + if (p.user_id === user_id) { + your_role = p.role + your_count++ } - if (game.status > 1) { - for (let i = 0; i < players.length; ++i) { - if (game.result === players[i].role) { - game.result = `${players[i].name}` - break - } - } + + let p_is_active = false + if (game.status === 0 && (game.owner_id === p.user_id)) + p_is_active = true + if (game.status === 1 && (game.active === p.role || game.active === "Both" || game.active === "All")) + p_is_active = true + + let link + if (p_is_active) { + link = `${p.name}` + if (p.user_id === user_id) + game.your_turn = true + } else { + link = `${p.name}` } + + if (game.player_names.length > 0) + game.player_names += ", " + game.player_names += link + + if (game.active === p.role) + game.active = link + if (game.result === p.role) + game.result = `${link} (${game.result})` + } + + if (your_count > 0) { + game.is_yours = true + if (your_count === 1) + game.your_role = your_role } game.ctime = human_date(game.ctime) @@ -2064,7 +2063,7 @@ app.get('/stats', function (req, res) { let stats = SQL_GAME_STATS.all() stats.forEach(row => { row.title_name = TITLES[row.title_id].title_name - row.options = format_options(row.options) + row.options = format_options(JSON.parse(row.options)) row.result_role = row.result_role.split(",") row.result_count = row.result_count.split(",").map(Number) }) -- cgit v1.2.3