feat(progression): snapshots, ports, in-memory adapters (slice 5)
flat snapshot record per aggregate - separate files mean saving a run doesn't rewrite the Profile, deleting a slot is deleting a file, and a corrupt slot doesn't cost achievements or best times. snapshots hold primitives so Restore re-runs the value-object factories; a serialiser building LevelId directly would bypass every guard. LoadResult has three outcomes: Absent != Corrupt. Collapsing them is the bug where a version bump made ContinueGame overwrite the save. Profile.Restore writes collections directly - replaying UnlockAchievement would re-fire popups and Steam pushes on every load. 44 tests.
This commit is contained in:
26
progression.tests/InMemoryProfileStore.cs
Normal file
26
progression.tests/InMemoryProfileStore.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace Mr.BrickAdventures.Progression.Tests;
|
||||
|
||||
internal sealed class InMemoryProfileStore : IProfileStore
|
||||
{
|
||||
private ProfileSnapshot? _saved;
|
||||
private bool _corrupt;
|
||||
|
||||
public void Save(Profile profile) => _saved = profile.Export();
|
||||
|
||||
public void Corrupt() => _corrupt = true;
|
||||
|
||||
public LoadResult<Profile> Load()
|
||||
{
|
||||
if (_corrupt) return LoadResult<Profile>.Corrupt("snapshot could not be read");
|
||||
if (_saved is null) return LoadResult<Profile>.Absent();
|
||||
|
||||
try
|
||||
{
|
||||
return LoadResult<Profile>.Loaded(Profile.Restore(_saved));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return LoadResult<Profile>.Corrupt(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user