diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-02-15 18:50:10 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-02-15 20:44:49 +0100 |
commit | 42063475c84efa6e81cbf6dbf7fd1e29b21941b7 (patch) | |
tree | 407afd27fbd6a95ab2ec262ad7b55b60abfbdfa4 /tools/import-game.js | |
parent | c235a8239177d38117f3313d17b904b66a806378 (diff) | |
download | server-42063475c84efa6e81cbf6dbf7fd1e29b21941b7.tar.gz |
Add command line options to import-game to override title and notice.
Diffstat (limited to 'tools/import-game.js')
-rwxr-xr-x | tools/import-game.js | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/tools/import-game.js b/tools/import-game.js index e8553df..4bca88e 100755 --- a/tools/import-game.js +++ b/tools/import-game.js @@ -3,12 +3,35 @@ const fs = require("fs") const sqlite3 = require("better-sqlite3") -if (process.argv.length !== 3) { - console.error("usage: node tools/import-game.js game.json") +var options = {} +var input = null + +for (let i = 2; i < process.argv.length; ++i) { + let opt = process.argv[i] + if (opt.includes("=")) { + let [key, val] = opt.split("=", 2) + options[key] = val + } else { + input = opt + } +} + +if (!input) { + console.error("usage: node tools/import-game.js [title_id=value] [notice=value] game.json") process.exit(1) } -var game = JSON.parse(fs.readFileSync(process.argv[2], "utf8")) +var game = JSON.parse(fs.readFileSync(input, "utf8")) + +if (options.title_id) + game.setup.title_id = options.title_id +if (options.notice) + game.setup.notice = options.notice + +if (game.setup.notice === undefined) + game.setup.notice = "" +if (game.setup.options === undefined) + game.setup.options = "{}" game.setup.active = game.state.active game.setup.moves = game.snaps && game.snaps.length > 0 ? game.snaps.length - 1 : 0 |