From d1318d147297161691f5048e1f2cb4e516159144 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 14 Nov 2021 17:17:49 +0100 Subject: Add 'hidden' column to titles for beta-testing games. --- server.js | 13 +++++-------- tools/readgame.sh | 4 ++-- tools/sql/data-300-ew.txt | 3 --- tools/sql/data-caesar.txt | 3 --- tools/sql/data-crusader.txt | 3 --- tools/sql/data-hammer.txt | 3 --- tools/sql/data-richard.txt | 3 --- tools/sql/data-tripoli.txt | 3 --- tools/sql/data.txt | 29 +++++++++++++++++++++++++++++ tools/sql/schema.txt | 12 +++++++++++- tools/writegame.sh | 2 +- views/header.ejs | 20 ++++++++++---------- views/index.ejs | 23 ++++++++++++----------- views/stats.ejs | 2 ++ 14 files changed, 72 insertions(+), 51 deletions(-) delete mode 100644 tools/sql/data-300-ew.txt delete mode 100644 tools/sql/data-caesar.txt delete mode 100644 tools/sql/data-crusader.txt delete mode 100644 tools/sql/data-hammer.txt delete mode 100644 tools/sql/data-richard.txt delete mode 100644 tools/sql/data-tripoli.txt create mode 100644 tools/sql/data.txt diff --git a/server.js b/server.js index cf5a9d0..0e6c548 100644 --- a/server.js +++ b/server.js @@ -306,7 +306,7 @@ function must_be_logged_in(req, res, next) { } app.get('/', function (req, res) { - res.render('index.ejs', { user: req.user, flash: req.flash('message') }); + res.render('index.ejs', { user: req.user, titles: TITLES, flash: req.flash('message') }); }); app.get('/about', function (req, res) { @@ -1741,12 +1741,7 @@ io.on('connection', (socket) => { * HIDDEN EXTRAS */ -const QUERY_STATS = db.prepare(` - SELECT title_id, scenario, result, count(*) AS count - FROM game_full_view - WHERE status=2 AND is_solo=0 - GROUP BY title_name, scenario, result - `); +const QUERY_STATS = db.prepare("SELECT * FROM game_stat_view"); app.get('/stats', function (req, res) { LOG(req, "GET /stats"); @@ -1754,6 +1749,8 @@ app.get('/stats', function (req, res) { res.render('stats.ejs', { user: req.user, stats: stats, - title_role_map: ROLES, title_name_map: TITLES, title_rule_map: RULES + title_role_map: ROLES, + title_name_map: TITLES, + title_rule_map: RULES, }); }); diff --git a/tools/readgame.sh b/tools/readgame.sh index 5bf93de..4a8fdbd 100644 --- a/tools/readgame.sh +++ b/tools/readgame.sh @@ -1,10 +1,10 @@ #!/bin/bash if [ -n "$1" -a -n "$2" ] then - sqlite3 db "select writefile('$2',state) from games where game_id = $1" + sqlite3 db "select writefile('$2',state) from game_state where game_id = $1" elif [ -n "$1" ] then - sqlite3 db "select state from games where game_id = $1" + sqlite3 db "select state from game_state where game_id = $1" else echo "usage: bash tools/readgame.sh GAME [ state.json ]" fi diff --git a/tools/sql/data-300-ew.txt b/tools/sql/data-300-ew.txt deleted file mode 100644 index 0f6cb16..0000000 --- a/tools/sql/data-300-ew.txt +++ /dev/null @@ -1,3 +0,0 @@ -INSERT OR REPLACE INTO titles VALUES ( '300-earth-and-water', '300: Earth & Water', 267058 ); -INSERT OR REPLACE INTO roles VALUES ( '300-earth-and-water', 'Persia' ); -INSERT OR REPLACE INTO roles VALUES ( '300-earth-and-water', 'Greece' ); diff --git a/tools/sql/data-caesar.txt b/tools/sql/data-caesar.txt deleted file mode 100644 index 1e11df8..0000000 --- a/tools/sql/data-caesar.txt +++ /dev/null @@ -1,3 +0,0 @@ -INSERT OR REPLACE INTO titles VALUES ( 'julius-caesar', 'Julius Caesar', 37836 ); -INSERT OR REPLACE INTO roles VALUES ( 'julius-caesar', 'Caesar' ); -INSERT OR REPLACE INTO roles VALUES ( 'julius-caesar', 'Pompeius' ); diff --git a/tools/sql/data-crusader.txt b/tools/sql/data-crusader.txt deleted file mode 100644 index 4f565b9..0000000 --- a/tools/sql/data-crusader.txt +++ /dev/null @@ -1,3 +0,0 @@ -INSERT OR REPLACE INTO titles VALUES ( 'crusader-rex', 'Crusader Rex', 8481 ); -INSERT OR REPLACE INTO roles VALUES ( 'crusader-rex', 'Franks' ); -INSERT OR REPLACE INTO roles VALUES ( 'crusader-rex', 'Saracens' ); diff --git a/tools/sql/data-hammer.txt b/tools/sql/data-hammer.txt deleted file mode 100644 index 853bed4..0000000 --- a/tools/sql/data-hammer.txt +++ /dev/null @@ -1,3 +0,0 @@ -INSERT OR REPLACE INTO titles VALUES ( 'hammer-of-the-scots', 'Hammer of the Scots', 3685 ); -INSERT OR REPLACE INTO roles VALUES ( 'hammer-of-the-scots', 'England' ); -INSERT OR REPLACE INTO roles VALUES ( 'hammer-of-the-scots', 'Scotland' ); diff --git a/tools/sql/data-richard.txt b/tools/sql/data-richard.txt deleted file mode 100644 index ff0787c..0000000 --- a/tools/sql/data-richard.txt +++ /dev/null @@ -1,3 +0,0 @@ -INSERT OR REPLACE INTO titles VALUES ( 'richard-iii', 'Richard III', 25277 ); -INSERT OR REPLACE INTO roles VALUES ( 'richard-iii', 'York' ); -INSERT OR REPLACE INTO roles VALUES ( 'richard-iii', 'Lancaster' ); diff --git a/tools/sql/data-tripoli.txt b/tools/sql/data-tripoli.txt deleted file mode 100644 index 0addd6d..0000000 --- a/tools/sql/data-tripoli.txt +++ /dev/null @@ -1,3 +0,0 @@ -INSERT OR REPLACE INTO titles VALUES ( 'shores-of-tripoli', 'The Shores of Tripoli', 237860 ); -INSERT OR REPLACE INTO roles VALUES ( 'shores-of-tripoli', 'Tripolitania' ); -INSERT OR REPLACE INTO roles VALUES ( 'shores-of-tripoli', 'United States' ); diff --git a/tools/sql/data.txt b/tools/sql/data.txt new file mode 100644 index 0000000..7268acc --- /dev/null +++ b/tools/sql/data.txt @@ -0,0 +1,29 @@ +PRAGMA foreign_keys=0; + +INSERT OR REPLACE INTO titles VALUES ( '300-earth-and-water', '300: Earth & Water', 267058, 0 ); +INSERT OR REPLACE INTO roles VALUES ( '300-earth-and-water', 'Persia' ); +INSERT OR REPLACE INTO roles VALUES ( '300-earth-and-water', 'Greece' ); + +INSERT OR REPLACE INTO titles VALUES ( 'crusader-rex', 'Crusader Rex', 8481, 0 ); +INSERT OR REPLACE INTO roles VALUES ( 'crusader-rex', 'Franks' ); +INSERT OR REPLACE INTO roles VALUES ( 'crusader-rex', 'Saracens' ); + +INSERT OR REPLACE INTO titles VALUES ( 'julius-caesar', 'Julius Caesar', 37836, 0 ); +INSERT OR REPLACE INTO roles VALUES ( 'julius-caesar', 'Caesar' ); +INSERT OR REPLACE INTO roles VALUES ( 'julius-caesar', 'Pompeius' ); + +INSERT OR REPLACE INTO titles VALUES ( 'hammer-of-the-scots', 'Hammer of the Scots', 3685, 0 ); +INSERT OR REPLACE INTO roles VALUES ( 'hammer-of-the-scots', 'England' ); +INSERT OR REPLACE INTO roles VALUES ( 'hammer-of-the-scots', 'Scotland' ); + +INSERT OR REPLACE INTO titles VALUES ( 'richard-iii', 'Richard III', 25277, 0 ); +INSERT OR REPLACE INTO roles VALUES ( 'richard-iii', 'York' ); +INSERT OR REPLACE INTO roles VALUES ( 'richard-iii', 'Lancaster' ); + +INSERT OR REPLACE INTO titles VALUES ( 'shores-of-tripoli', 'The Shores of Tripoli', 237860, 0 ); +INSERT OR REPLACE INTO roles VALUES ( 'shores-of-tripoli', 'Tripolitania' ); +INSERT OR REPLACE INTO roles VALUES ( 'shores-of-tripoli', 'United States' ); + +INSERT OR REPLACE INTO titles VALUES ( 'wilderness-war', 'Wilderness War', 1822, 1 ); +INSERT OR REPLACE INTO roles VALUES ( 'wilderness-war', 'French' ); +INSERT OR REPLACE INTO roles VALUES ( 'wilderness-war', 'British' ); diff --git a/tools/sql/schema.txt b/tools/sql/schema.txt index 5e80ec6..dc2bcc6 100644 --- a/tools/sql/schema.txt +++ b/tools/sql/schema.txt @@ -4,7 +4,8 @@ CREATE TABLE IF NOT EXISTS blacklist_mail ( mail TEXT NOT NULL PRIMARY KEY ) WIT CREATE TABLE IF NOT EXISTS titles ( title_id TEXT NOT NULL PRIMARY KEY, title_name TEXT NOT NULL, - bgg INTEGER + bgg INTEGER, + hidden BOOLEAN ) WITHOUT ROWID; CREATE TABLE IF NOT EXISTS roles ( @@ -290,3 +291,12 @@ BEGIN DELETE FROM last_notified WHERE game_id = old.game_id; DELETE FROM players WHERE game_id = old.game_id; END; + +DROP VIEW IF EXISTS game_stat_view; +CREATE VIEW game_stat_view AS + SELECT title_id, scenario, result, count(*) AS count + FROM game_full_view + NATURAL JOIN titles + WHERE hidden=0 AND is_solo=0 AND status=2 + GROUP BY title_name, scenario, result + ; diff --git a/tools/writegame.sh b/tools/writegame.sh index 82cff23..a6e673d 100644 --- a/tools/writegame.sh +++ b/tools/writegame.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "$1" -a -f "$2" ] then - sqlite3 db "update games set state=readfile('$2') where game_id = $1" + sqlite3 db "update game_state set state=readfile('$2') where game_id = $1" else echo "usage: bash tools/writegame.sh GAME state.json" fi diff --git a/views/header.ejs b/views/header.ejs index 2628f8d..66f0f2e 100644 --- a/views/header.ejs +++ b/views/header.ejs @@ -2,9 +2,9 @@ -<% if (typeof refresh !== 'undefined' && refresh > 0) { _%> +<% if (typeof refresh !== 'undefined' && refresh > 0) { -%> -<% } _%> +<% } -%> <%= title %> @@ -16,21 +16,21 @@

<%= title %>

-<%_ if (typeof flash !== 'undefined' && flash.length > 0) { _%> +<% if (typeof flash !== 'undefined' && flash.length > 0) { -%>

<%= flash %>

-<%_ } _%> +<% } -%> diff --git a/views/index.ejs b/views/index.ejs index 0b3180f..1f23381 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -1,6 +1,6 @@ -<%- include('header', { title: "Rally the Troops!" }) %> +<%- include('header', { title: "Rally the Troops!" }) _%> @@ -13,15 +13,16 @@ players. Registration and use is free, and there are no ads.
- - - - -
- -
- - +<% + for (let t in titles) { + let title = titles[t]; + if (!title.hidden) { +_%> + +<% + } + } +_%>

diff --git a/views/stats.ejs b/views/stats.ejs index 9e07aaf..95b52d2 100644 --- a/views/stats.ejs +++ b/views/stats.ejs @@ -15,6 +15,8 @@ return info ? info.count : 0; } for (let title_id in title_name_map) { + if (title_name_map[title_id].hidden) + continue; let scenarios = title_rule_map[title_id].scenarios; let roles = title_role_map[title_id].concat(['Draw']); %><%= title_name_map[title_id].title_name %><% -- cgit v1.2.3