SaveManager class
Resource managing save/load operations.
Aggregates state from all Saveable resources and handles file I/O. Save files are stored in the application documents directory, or in SaveConfig.baseDirectory when set.
Save Flow
The save system uses a request pattern to bridge ECS and async I/O:
- ECS system sets saveRequested when trigger occurs (e.g., sleep, checkpoint)
- Flutter widget layer checks saveRequested in game loop
- Widget calls save with current World
- saveRequested is reset after save completes
Usage
// In ECS system (synchronous)
final saveManager = world.getResource<SaveManager>();
saveManager?.requestSave(metadata: {'playerX': 100, 'playerY': 200});
// In Flutter game loop (async)
if (saveManager.saveRequested) {
saveManager.clearSaveRequest();
await saveManager.save(world, 'slot1');
}
- Implementers
Constructors
- SaveManager({SaveConfig config = const SaveConfig.defaults()})
- Creates a save manager with the given configuration.
Properties
- config → SaveConfig
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isInitialized → bool
-
Whether the manager has been initialized.
no setter
-
pendingMetadata
↔ Map<
String, dynamic> ? -
Metadata to include with the requested save.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- saveRequested ↔ bool
-
Whether a save was requested (set by ECS, consumed by Flutter).
getter/setter pair
Methods
-
clearSaveRequest(
) → void - Clear save request after processing.
-
deleteSave(
[String? slotName]) → Future< bool> - Delete a save file, along with its backup and any leftover temp file.
-
getSaveableResources(
World world) → Iterable< Saveable> - Get all Saveable resources.
-
hasBackup(
[String? slotName]) → Future< bool> -
Check if a backup file (
<slot>.backup.json) exists for the given slot. -
hasSaveFile(
[String? slotName]) → Future< bool> - Check if a save file exists for the given slot.
-
initialize(
) → Future< void> - Initialize the save manager.
-
listSaveSlots(
) → Future< List< SaveSlotInfo> > - List all available save slots.
-
load(
World world, {String? slotName, bool fromBackup = false}) → Future< Map< String, dynamic> ?> - Load game state from a save file.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
requestSave(
{Map< String, dynamic> ? metadata}) → void - Request a save with optional metadata.
-
save(
World world, {String? slotName, Map< String, dynamic> ? metadata}) → Future<bool> - Save the current game state.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited