summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/rerun.js24
-rw-r--r--tools/sql/schema.txt9
2 files changed, 33 insertions, 0 deletions
diff --git a/tools/rerun.js b/tools/rerun.js
new file mode 100644
index 0000000..d1534e6
--- /dev/null
+++ b/tools/rerun.js
@@ -0,0 +1,24 @@
+const sqlite3 = require('better-sqlite3');
+
+let db = new sqlite3("./db");
+let game_id = process.argv[2] | 0;
+let title_id = db.prepare("SELECT title_id FROM games WHERE game_id = ?").pluck().get(game_id);
+let rules = require("./public/" + title_id + "/rules.js");
+
+console.log("// TITLE", title_id)
+let log = db.prepare("SELECT * FROM game_log WHERE game_id = ?").all(game_id);
+let game = null;
+log.forEach(item => {
+ let args = JSON.parse(item.arguments);
+ if (item.action === 'setup') {
+ console.log("// SETUP", item.arguments)
+ game = rules.setup(args[0], args[1], args[2]);
+ } else if (item.action === 'resign') {
+ console.log("// RESIGN", item.role);
+ game = rules.resign(game, item.role);
+ } else {
+ console.log("// ACTION", item.role, item.action, item.arguments);
+ game = rules.action(game, item.role, item.action, args);
+ }
+ console.log(JSON.stringify(game));
+});
diff --git a/tools/sql/schema.txt b/tools/sql/schema.txt
index e731c8c..1623ec3 100644
--- a/tools/sql/schema.txt
+++ b/tools/sql/schema.txt
@@ -55,6 +55,14 @@ CREATE TABLE IF NOT EXISTS games (
state TEXT
);
+CREATE TABLE IF NOT EXISTS replay (
+ game_id INTEGER,
+ time TIMESTAMP,
+ role TEXT,
+ action TEXT,
+ arguments TEXT
+);
+
CREATE TABLE IF NOT EXISTS chats (
game_id INTEGER PRIMARY KEY,
time TIMESTAMP,
@@ -110,6 +118,7 @@ BEGIN
DELETE FROM players WHERE game_id = old.game_id;
DELETE FROM notifications WHERE game_id = old.game_id;
DELETE FROM chats WHERE game_id = old.game_id;
+ DELETE FROM replay WHERE game_id = old.game_id;
END;
DROP VIEW IF EXISTS player_view;