From a7da66a417fcca3819c86e74b01bd8b9f08729f3 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 8 Mar 2026 19:19:30 -0400 Subject: [PATCH] empires: Implement sub-class serialize/restore for extra data This game contains a fair amount of data not in this.state, so we need this functions to correctly save and restore an in-flight game in the case of a server shutdown/restart. --- empires.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/empires.js b/empires.js index 839f5f8..e0efdb8 100644 --- a/empires.js +++ b/empires.js @@ -216,6 +216,34 @@ class Empires extends Game { this.broadcast_phase_change(); } + serialize() { + const data = super.serialize(); + data._spectators = this._spectators; + data.next_spectator_id = this.next_spectator_id; + data._players = this._players; + data.characters_to_reveal = this.characters_to_reveal; + data.phase = this.phase; + data.old_phase = this.old_phase; + data.reveal_index = this.reveal_index; + return data; + } + + restore(data) { + super.restore(data); + this._spectators = data._spectators || []; + this.next_spectator_id = data.next_spectator_id || 1; + this._players = data._players || []; + this.characters_to_reveal = data.characters_to_reveal || null; + this.phase = data.phase || GamePhase.JOIN; + this.old_phase = data.old_phase; + this.reveal_index = data.reveal_index || 0; + + /* Restart the reveal interval if we were mid-reveal. */ + if (this.phase === GamePhase.REVEAL && this.characters_to_reveal) { + this.reveal_interval = setInterval(this.reveal_next.bind(this), 3000); + } + } + handle_events(request, response) { super.handle_events(request, response); -- 2.45.2