summaryrefslogtreecommitdiff
path: root/server/lib/core
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/core')
-rw-r--r--server/lib/core/save_store.dart4
-rw-r--r--server/lib/core/state/game_state.dart9
2 files changed, 11 insertions, 2 deletions
diff --git a/server/lib/core/save_store.dart b/server/lib/core/save_store.dart
index 5ffdc36..25b4136 100644
--- a/server/lib/core/save_store.dart
+++ b/server/lib/core/save_store.dart
@@ -46,7 +46,9 @@ class FileSaveStore implements SaveStore {
void write(String data) {
final dir = _file.parent;
if (!dir.existsSync()) dir.createSync(recursive: true);
- _file.writeAsString(data, flush: true);
+ // Synchronous write: "save on every action" must be on disk when
+ // [write] returns, or a crash in between loses the snapshot.
+ _file.writeAsStringSync(data, flush: true);
}
@override
diff --git a/server/lib/core/state/game_state.dart b/server/lib/core/state/game_state.dart
index a6884cc..23666fe 100644
--- a/server/lib/core/state/game_state.dart
+++ b/server/lib/core/state/game_state.dart
@@ -152,10 +152,17 @@ class GameState {
List<String> get commandDescriptions => _actionHandler.commandDescriptions;
List<GameSaveState?> get gameSaveStates => _actionHandler.gameSaveStates;
- /// The Phase 2 broadcast hook is reachable through the action handler.
+ /// The Phase 2 broadcast hook, reachable through the action handler: set
+ /// by the network layer, null in headless tests.
void Function(int index, String description, String eventJson)?
get onAction => _actionHandler.onAction;
+ set onAction(
+ void Function(int index, String description, String eventJson)? value,
+ ) {
+ _actionHandler.onAction = value;
+ }
+
// Minimal observer hook — replaces the reference app's ChangeNotifier
// notifications. The network layer (Phase 2) subscribes; unused in Phase 1.
final List<void Function()> _listeners = [];