diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-19 08:53:51 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-19 08:53:51 +0100 |
| commit | b884441ba0d10bdd3559748507a0991888f66194 (patch) | |
| tree | 074321d353c1153e8d95191eecf5a61b2eec1096 /server/lib/core/action_handler.dart | |
| parent | d64cf3514e5ff1ddb1c7f3ddac9a769db3e7dde0 (diff) | |
Phase 6: settings, saves, localization parity (M6)
Diffstat (limited to 'server/lib/core/action_handler.dart')
| -rw-r--r-- | server/lib/core/action_handler.dart | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/server/lib/core/action_handler.dart b/server/lib/core/action_handler.dart index 2c73bb1..5b3f8d4 100644 --- a/server/lib/core/action_handler.dart +++ b/server/lib/core/action_handler.dart @@ -89,10 +89,18 @@ class ActionHandler { saveState.load(_gameState); saveState.saveToDisk(_gameState); updateAllUI(); - _sendState('undo'); } lastEvent = const NoEvent(); + // The broadcast travels the undone action's description (as the + // reference's undo envelope does) but the *post-decrement* index: the + // reference reports the pre-decrement index because its clients keep + // local state and reconcile it; our stateless web clients take the + // wire index at face value, so it must equal the state position. + final undoneDescription = commandIndex < _commandDescriptions.length + ? _commandDescriptions[commandIndex] + : ''; commandIndex--; + if (saveState != null) _sendState('undo', description: undoneDescription); } } @@ -115,17 +123,17 @@ class ActionHandler { /// Broadcasts the current command index + description after an undo/redo, /// mirroring the reference app's server-side `StateEnvelope` send. - void _sendState(String action) { + /// [description] overrides the one at the current index (the undo path + /// sends the undone action's name; the redo path sends the redone one). + void _sendState(String action, {String? description}) { final idx = commandIndex; - if (idx >= 0 && idx < _commandDescriptions.length) { - _log.info( - 'server sends, $action index: $idx, description:${_commandDescriptions[idx]}', - ); - onAction?.call( - idx, - _commandDescriptions[idx], - const NoEvent().toJsonString(), - ); + // idx -1 is the baseline (empty history). The reference skips the send + // there because its clients keep local state; the stateless web clients + // only ever see what the server pushes, so the baseline goes out too. + if (idx >= -1 && idx < _commandDescriptions.length) { + final desc = description ?? (idx >= 0 ? _commandDescriptions[idx] : ''); + _log.info('server sends, $action index: $idx, description:$desc'); + onAction?.call(idx, desc, const NoEvent().toJsonString()); } } |
