summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-06-29 20:55:15 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-02 15:51:22 +0200
commitad2e1ac6beb05023b2cbcd3e7de1aeeaf4e4f038 (patch)
tree5bf49c12378deb13d152e1ca38cd43d0fafdba6f
parent6b813050b604d878d873ab1f6cf19ca14d0a40ba (diff)
downloadjulius-caesar-ad2e1ac6beb05023b2cbcd3e7de1aeeaf4e4f038.tar.gz
Update "undo".
-rw-r--r--rules.js45
1 files changed, 24 insertions, 21 deletions
diff --git a/rules.js b/rules.js
index 019a7dc..c2e2d25 100644
--- a/rules.js
+++ b/rules.js
@@ -2854,8 +2854,6 @@ function observer_hand() {
return hand
}
-exports.is_checkpoint = (a, b) => a.turn !== b.turn
-
exports.view = function(state, current) {
game = state
@@ -3012,30 +3010,35 @@ function object_copy(original) {
}
function clear_undo() {
- if (game.undo.length > 0)
- game.undo = []
+ if (game.undo) {
+ game.undo.length = 0
+ }
}
function push_undo() {
- let copy = {}
- for (let k in game) {
- let v = game[k]
- if (k === "undo")
- continue
- else if (k === "log")
- v = v.length
- else if (typeof v === "object" && v !== null)
- v = object_copy(v)
- copy[k] = v
+ if (game.undo) {
+ let copy = {}
+ for (let k in game) {
+ let v = game[k]
+ if (k === "undo")
+ continue
+ else if (k === "log")
+ v = v.length
+ else if (typeof v === "object" && v !== null)
+ v = object_copy(v)
+ copy[k] = v
+ }
+ game.undo.push(copy)
}
- game.undo.push(copy)
}
function pop_undo() {
- let save_log = game.log
- let save_undo = game.undo
- game = save_undo.pop()
- save_log.length = game.log
- game.log = save_log
- game.undo = save_undo
+ if (game.undo) {
+ let save_log = game.log
+ let save_undo = game.undo
+ game = save_undo.pop()
+ save_log.length = game.log
+ game.log = save_log
+ game.undo = save_undo
+ }
}