diff options
-rw-r--r-- | server.js | 60 | ||||
-rw-r--r-- | views/head.pug | 26 | ||||
-rw-r--r-- | views/join.pug | 2 |
3 files changed, 52 insertions, 36 deletions
@@ -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 ? `<a href="/user/${p.name}">${name}</a>` : 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 = `<a href="/user/${p.name}">${name}</a>` + if (game.status === 0 && p.user_id === game.owner_id) + name = `<i>${name}</i>` + 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 = `<a href="/user/${players[i].name}">${players[i].name}</a>` + break + } + } + if (game.status > 1) { + for (let i = 0; i < players.length; ++i) { + if (game.result === players[i].role) { + game.result = `<a href="/user/${players[i].name}">${players[i].name}</a>` + 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) { diff --git a/views/head.pug b/views/head.pug index 9c248a4..0a1052a 100644 --- a/views/head.pug +++ b/views/head.pug @@ -46,7 +46,7 @@ mixin gametable(status,table,hide_title=0) th Description case status when 0 - th Created + th Date when 1 th Changed th Turn @@ -60,33 +60,27 @@ mixin gametable(status,table,hide_title=0) td: a(href="/join/"+row.game_id)= row.game_id unless hide_title td.w: a(href="/"+row.title_id)= row.title_name - if true - td= row.scenario - else - td= row.options !== "None" ? row.scenario + ", " + row.options : row.scenario + td= row.scenario if row.player_names td!= row.player_names else td.error Nobody td= row.description + if row.status === 0 + td.w= row.ctime + else + td.w= row.mtime case status - when 0 - td.w= row.ctime when 1 - td.w= row.mtime if (row.is_active) - td.is_active= row.active + td.is_active!= row.active else - td= row.active + td!= row.active when 2 - td.w= row.mtime - td= row.result + td!= row.result td.command if status === 0 - if row.is_ready - a(href="/join/"+row.game_id) Enter - else - a(href="/join/"+row.game_id) Join + a(href="/join/"+row.game_id) Join else if status === 1 if row.is_yours if row.is_shared diff --git a/views/join.pug b/views/join.pug index e195bf9..bc1567a 100644 --- a/views/join.pug +++ b/views/join.pug @@ -37,7 +37,7 @@ html br | Scenario: #{game.scenario} br - | Options: #{game.options} + | Options: #{game.human_options} p= game.description || "No description." |