new progression.adapters project, no engine reference. Stores take a directory path; Godot resolves user:// with GlobalizePath and passes it in, which is what makes them testable at all - originally I'd written this slice off as untestable. version lives in a file envelope, not the snapshot, so the domain only knows the current shape. A newer-build save reports Corrupt with a reason instead of masquerading as "no save" and getting overwritten. atomic write via temp + rename. One file per aggregate: saving a run leaves the profile file byte-identical, asserted. guard rail fixed - it was matching prose in doc comments, now anchored to using-directives plus a project.assets.json check. 63 tests.
21 lines
771 B
C#
21 lines
771 B
C#
namespace Mr.BrickAdventures.Progression.Adapters;
|
|
|
|
/// <summary>
|
|
/// Keeps the Profile in its own JSON file, beside the Playthrough files but written independently.
|
|
/// </summary>
|
|
public sealed class JsonProfileStore : IProfileStore
|
|
{
|
|
/// <summary>Versioned separately from Playthroughs — the two shapes drift at their own pace.</summary>
|
|
private const int CurrentVersion = 1;
|
|
|
|
private readonly string _path;
|
|
|
|
public JsonProfileStore(string directory) => _path = Path.Combine(directory, "profile.json");
|
|
|
|
public void Save(Profile profile) =>
|
|
JsonFiles.WriteAtomic(_path, CurrentVersion, profile.Export());
|
|
|
|
public LoadResult<Profile> Load() =>
|
|
JsonFiles.Read<ProfileSnapshot, Profile>(_path, CurrentVersion, Profile.Restore);
|
|
}
|