From 756f8097d6225b3618c783cae68382d0569ac4c8 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 2 Jan 2022 19:39:47 +0100 Subject: Stable undo and fixes for replay. --- rules.js | 10 ++++++---- 1 file 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; -- cgit v1.2.3