summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2025-04-21 09:20:13 +0200
committerTor Andersson <tor@ccxvii.net>2025-04-21 09:40:47 +0200
commit9803f79ed8776723dc7ac98108bc66879f921d23 (patch)
tree92795f2ae4e199b0c61e5480cc9d7b44fed42d60 /rules.js
parentc97ecaf4342a1073fa87ebe74b40de9bcbaed434 (diff)
downloadvijayanagara-9803f79ed8776723dc7ac98108bc66879f921d23.tar.gz
Fix replay view of discard pile.
In the replay mode the view object is not serialized to JSON before viewing, so we cannot rely on the JSON representation dropping any properties with the value "undefined". Don't use (property in object) to check if something is undefined. Initialize game.discard pile in on_setup as well.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js11
1 files changed, 4 insertions, 7 deletions
diff --git a/rules.js b/rules.js
index ac96885..60bcafa 100644
--- a/rules.js
+++ b/rules.js
@@ -140,13 +140,14 @@ exports.view = function (state, role) {
dice: game.dice,
}
- if (game.cmd && "attacker" in game.cmd) {
+ if (game.cmd && game.cmd.attacker !== undefined) {
view.attack = {
where: game.cmd.where,
attacker: game.cmd.attacker,
target: game.cmd.target
}
- if ("n_units" in game.cmd) view.attack.n_units = game.cmd.n_units
+ if (game.cmd.n_units !== undefined)
+ view.attack.n_units = game.cmd.n_units
}
if (game.result) {
@@ -252,7 +253,7 @@ exports.setup = function (seed, scenario, _options) {
cavalry: Array(10).fill(AVAILABLE),
deck: [],
of_gods_and_kings: [null, null, 0],
- // discard: [],
+ discard: [],
order: [],
cmd: {
type: null,
@@ -407,10 +408,6 @@ function end_card() {
}
function update_discard() {
- if ("discard" in game === false) {
- game.discard = []
- }
-
if (this_card() === 45)
game.discard = [45]
else if (this_card() === 46)