summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
Diffstat (limited to 'public')
-rw-r--r--public/common/util.js43
1 files changed, 24 insertions, 19 deletions
diff --git a/public/common/util.js b/public/common/util.js
index 0f6fc44..18a78e8 100644
--- a/public/common/util.js
+++ b/public/common/util.js
@@ -1,32 +1,37 @@
// === COMMON LIBRARY ===
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
+ }
}
function random(range) {