Data and versioned saves
| Task | Repository |
|---|---|
| Read or write one independent object | DataRepository |
| Store several settings sections in one file | UnifiedSettingsDataRepository |
| Use slots, versions, and content pack snapshots | SaveRepository<TSaveData> |
Configure a save repository
Provide storage that implements IStorageBackup, such as FileStorage, in the composition root. Set the save root and slot naming through SaveConfiguration. Set the game ID, version, migrations, and validation in SaveRepositoryOptions<T>. Implement IData for the game snapshot. The repository wraps it in a versioned document.
Load and confirm
- Use
ExistsAsyncto decide whether to show Continue. UseLoadAsyncfor a slot that can be read directly. - For a migration or content reconciliation, call
PrepareLoadAsyncto get a candidate. CheckRequiresConfirmationand let the player approve changes that need consent. - When
RequiresCommitis set, callCommitPreparedAsyncto retain the original backup and commit. Restore the world from the returned data after it succeeds. - Use
RestoreBackupAsyncto restore a selected backup, then load the slot through the normal flow.
Mod save data
Configure a ModSavePolicy for enabled mods. Start a new game with an empty draft and resume with ModState from the prepared save. Give each mod its own scope, then save the game and draft with SaveDocumentAsync.
Continue with implementing saves or bidirectional migrations.