summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-01-02 19:39:47 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-18 12:42:59 +0100
commit756f8097d6225b3618c783cae68382d0569ac4c8 (patch)
tree8004f924e150013b949660b791274520bcb62289
parentbd6d271455760a427d553ad4018b3f380dafc952 (diff)
download300-earth-and-water-756f8097d6225b3618c783cae68382d0569ac4c8.tar.gz
Stable undo and fixes for replay.
-rw-r--r--rules.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/rules.js b/rules.js
index a5b0bd1..85c8cc2 100644
--- a/rules.js
+++ b/rules.js
@@ -258,7 +258,7 @@ function clear_undo() {
function push_undo() {
game.undo.push(JSON.stringify(game, (k,v) => {
- if (k === 'undo') return undefined;
+ if (k === 'undo') return 0;
if (k === 'log') return v.length;
return v;
}));
@@ -267,7 +267,7 @@ function push_undo() {
function pop_undo() {
let save_undo = game.undo;
let save_log = game.log;
- Object.assign(game, JSON.parse(save_undo.pop()));
+ game = JSON.parse(save_undo.pop());
game.undo = save_undo;
save_log.length = game.log;
game.log = save_log;
@@ -3362,7 +3362,7 @@ exports.action = function (state, current, action, arg) {
S[action](arg, current);
else
throw new Error("Invalid action: " + action);
- return state;
+ return game;
}
exports.resign = function (state, current) {
@@ -3378,9 +3378,11 @@ exports.resign = function (state, current) {
else
game.result = PERSIA;
}
- return state;
+ return game;
}
+exports.checkpoints = [ "campaign" ];
+
exports.view = function(state, current) {
game = state;