summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-09-10 19:00:39 +0200
committerTor Andersson <tor@ccxvii.net>2022-10-05 17:36:50 +0200
commit5071f6bfa5d4dc1ea50c9b889b5a8ff457a08cfb (patch)
tree5e64a371c848a35a8d200dd228157ebf00f05615 /public
parent8071fa832da17a4452ae728a05d2cdc057b136da (diff)
downloadserver-5071f6bfa5d4dc1ea50c9b889b5a8ff457a08cfb.tar.gz
Make copy of state for replay checkpoints.
Diffstat (limited to 'public')
-rw-r--r--public/common/play.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/public/common/play.js b/public/common/play.js
index 6ac9355..e80dc08 100644
--- a/public/common/play.js
+++ b/public/common/play.js
@@ -620,6 +620,31 @@ function send_restart(scenario) {
/* REPLAY */
+function deep_copy(original) {
+ if (Array.isArray(original)) {
+ let n = original.length
+ let copy = new Array(n)
+ for (let i = 0; i < n; ++i) {
+ let v = original[i]
+ if (typeof v === "object" && v !== null)
+ copy[i] = deep_copy(v)
+ else
+ copy[i] = v
+ }
+ return copy
+ } else {
+ let copy = {}
+ for (let i in original) {
+ let v = original[i]
+ if (typeof v === "object" && v !== null)
+ copy[i] = deep_copy(v)
+ else
+ copy[i] = v
+ }
+ return copy
+ }
+}
+
function adler32(data) {
let a = 1, b = 0
for (let i = 0, n = data.length; i < n; ++i) {
@@ -698,7 +723,7 @@ async function init_replay(debug) {
if (rules.is_checkpoint) {
replay[p].is_checkpoint = (p > 0 && rules.is_checkpoint(ss, s))
- ss = Object.assign({}, s)
+ ss = deep_copy(s)
}
try {