]> git.cworth.org Git - lmno-server/commitdiff
lmno: Add game specific restore() operation to reconsstruct Set objects
authorCarl Worth <cworth@cworth.org>
Sun, 8 Mar 2026 23:01:04 +0000 (19:01 -0400)
committerCarl Worth <cworth@cworth.org>
Sun, 8 Mar 2026 23:01:04 +0000 (19:01 -0400)
The game state save logic serializes any Set objects as arrays, so
we need this extra little bit of code to re-construct Set objects
from arrays at time of restore.

anagrams.js
empathy.js
letterrip.js

index 7a6a250354ef2dd0fac9a035f4c61c08b3d9d163..c0e3be87ebfe0f92eb65c272debd74b871e738c8 100644 (file)
@@ -849,6 +849,11 @@ class Anagrams extends Game {
       })}\n\n`);
     }
   }
+
+  restore(data) {
+    super.restore(data);
+    this.state.done_players = new Set(this.state.done_players);
+  }
 }
 
 Anagrams.router = express.Router();
index d6b007b4bc3ef75d32230cde000917cdacdb7fa4..7dc850d6628ccaffcb5f8e57c1c2b13395ac6a22 100644 (file)
@@ -641,6 +641,15 @@ class Empathy extends Game {
     /* And broadcast the scores to all connected clients. */
     this.broadcast_event_object('scores', this.state.scores);
   }
+
+  restore(data) {
+    super.restore(data);
+    this.state.players_answering = new Set(this.state.players_answering);
+    this.state.end_answers = new Set(this.state.end_answers);
+    this.state.players_judging = new Set(this.state.players_judging);
+    this.state.end_judging = new Set(this.state.end_judging);
+    this.state.new_game_votes = new Set(this.state.new_game_votes);
+  }
 }
 
 Empathy.router = express.Router();
index a1e4fc88ffbcefbd94df886efd85d80c37445c90..3bdeaad3b3fefcf60e6b38af2c0982092dc61f46 100644 (file)
@@ -524,6 +524,11 @@ class LetterRip extends Game {
       })}\n\n`);
     }
   }
+
+  restore(data) {
+    super.restore(data);
+    this.state.stuck = new Set(this.state.stuck);
+  }
 }
 
 LetterRip.router = express.Router();