diff options
-rw-r--r-- | server.js | 21 | ||||
-rw-r--r-- | views/games.pug | 8 | ||||
-rw-r--r-- | views/head.pug | 5 | ||||
-rw-r--r-- | views/info.pug | 4 | ||||
-rw-r--r-- | views/profile.pug | 6 |
5 files changed, 35 insertions, 9 deletions
@@ -1015,8 +1015,16 @@ function annotate_game(game, user_id) { } function annotate_games(games, user_id) { - for (let i = 0; i < games.length; ++i) - annotate_game(games[i], user_id); + for (let i = 0; i < games.length; ++i) { + let game = games[i]; + if (game.status === 0) { + 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); + } else { + game.is_ready = false; + } + annotate_game(game, user_id); + } } app.get('/games', function (req, res) { @@ -1032,7 +1040,8 @@ app.get('/games', function (req, res) { } res.render('games.pug', { user: req.user, - open_games: open_games, + open_games: open_games.filter(g => !g.is_ready), + ready_games: open_games.filter(g => g.is_ready), active_games: active_games, }); }); @@ -1048,7 +1057,8 @@ app.get('/profile', must_be_logged_in, function (req, res) { res.render('profile.pug', { user: req.user, avatar: avatar, - open_games: open_games, + open_games: open_games.filter(g => !g.is_ready), + ready_games: open_games.filter(g => g.is_ready), active_games: active_games, finished_games: finished_games, }); @@ -1073,7 +1083,8 @@ function get_title_page(req, res, title_id) { user: req.user, title: title, about_html: HTML_ABOUT[title_id], - open_games: open_games, + open_games: open_games.filter(g => !g.is_ready), + ready_games: open_games.filter(g => g.is_ready), active_games: active_games, finished_games: finished_games, }); diff --git a/views/games.pug b/views/games.pug index 2ab54f1..14ea168 100644 --- a/views/games.pug +++ b/views/games.pug @@ -3,16 +3,20 @@ doctype html html head include head - title Public Games + title= SITE_NAME if user meta(http-equiv="refresh" content=300) body include header article - h1 Public Games + h1= SITE_NAME h2 Open +gametable(0, open_games) + if ready_games.length > 0 + h2 Ready to start + +gametable(0, ready_games) + h2 Active +gametable(1, active_games) diff --git a/views/head.pug b/views/head.pug index df1b762..e65fca2 100644 --- a/views/head.pug +++ b/views/head.pug @@ -75,7 +75,10 @@ mixin gametable(status,table,hide_title=0) td= row.result td.command if status === 0 - a(href="/join/"+row.game_id) Join + if row.is_ready + a(href="/join/"+row.game_id) Enter + else + a(href="/join/"+row.game_id) Join else if status === 1 if row.is_yours if row.is_shared diff --git a/views/info.pug b/views/info.pug index 86a74d0..e38091c 100644 --- a/views/info.pug +++ b/views/info.pug @@ -25,6 +25,10 @@ html p a(href="/create/"+title.title_id) Create a new game + if ready_games.length > 0 + h2 Ready to start + +gametable(0,ready_games) + if active_games.length > 0 h2 Active games +gametable(1,active_games,1) diff --git a/views/profile.pug b/views/profile.pug index 6fb777a..5c98743 100644 --- a/views/profile.pug +++ b/views/profile.pug @@ -33,6 +33,10 @@ html br | » <a href="/logout">Logout</a> + if ready_games.length > 0 + h2 Ready to start + +gametable(0,ready_games) + if open_games.length > 0 h2 Open games +gametable(0,open_games) @@ -45,5 +49,5 @@ html h2 Finished games +gametable(2,finished_games) - if open_games.length === 0 && active_games.length === 0 && finished_games.length === 0 + if open_games.length === 0 && ready_games.length === 0 && active_games.length === 0 && finished_games.length === 0 p You don't have any current or finished games. |