namespace Mr.BrickAdventures.Progression.Adapters; /// /// Keeps each Playthrough in its own JSON file inside a directory. /// /// /// Takes a directory path rather than using Godot's FileAccess. Godot resolves user:// to an /// absolute path with ProjectSettings.GlobalizePath and passes it in, so this whole class has /// no engine dependency and can be tested against a real temp directory. /// public sealed class JsonPlaythroughStore : IPlaythroughStore { /// Bump only alongside a migration for the version being replaced. private const int CurrentVersion = 1; private readonly string _directory; public JsonPlaythroughStore(string directory) => _directory = directory; /// One file per slot, so saving a run never rewrites the Profile or another slot. private string PathFor(PlaythroughId id) => Path.Combine(_directory, $"playthrough_{id.Value:N}.json"); public void Save(Playthrough playthrough) => JsonFiles.WriteAtomic(PathFor(playthrough.Id), CurrentVersion, playthrough.Export()); public LoadResult Load(PlaythroughId id) => JsonFiles.Read( PathFor(id), CurrentVersion, Playthrough.Restore); }