Skip to content

Commit

Permalink
IFIlesystem.FromJsonTo -> ReadJsonInto
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Jamrozik committed Jan 2, 2024
1 parent 511f76c commit 9e146da
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/game-lib/Controller/GameSessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public GameState LoadCurrentGameStateFromFile()
GameSession.AddCurrentStateToPastStates();

GameSession.CurrentGameState =
_config.SaveFile.FromJsonTo<GameState>(GameState.StateJsonSerializerOptions);
_config.SaveFile.ReadJsonInto<GameState>(GameState.StateJsonSerializerOptions);

_log.Info($"Loaded game state from {_config.SaveFile.FullPath}");
return GameSession.CurrentGameState;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Json/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public static class JsonExtensions
public static T FromJsonTo<T>(this string json)
=> JsonSerializer.Deserialize<T>(json, SerializerOptions)!;

public static T FromJsonTo<T>(this File file, JsonSerializerOptions? options = null)
=> file.FileSystem.FromJsonTo<T>(file, options);
public static T ReadJsonInto<T>(this File file, JsonSerializerOptions? options = null)
=> file.FileSystem.ReadJsonInto<T>(file, options);

public static T FromJsonTo<T>(this byte[] bytes, JsonSerializerOptions? options = null)
=> JsonSerializer.Deserialize<T>(bytes, options ?? SerializerOptions)!;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/OS/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ public string GetFullPath(string path)

public JsonElement ReadAllJson(string path) => ReadAllBytes(path).FromJsonTo<JsonElement>();

public T FromJsonTo<T>(string path)
public T ReadJsonInto<T>(string path)
{
throw new System.NotImplementedException();
}

public T FromJsonTo<T>(string path, JsonSerializerOptions? options)
public T ReadJsonInto<T>(string path, JsonSerializerOptions? options)
=> ReadAllBytes(path).FromJsonTo<T>(options);

public T FromJsonTo<T>(File file, JsonSerializerOptions? options)
=> FromJsonTo<T>(file.FullPath, options);
public T ReadJsonInto<T>(File file, JsonSerializerOptions? options)
=> ReadJsonInto<T>(file.FullPath, options);

public FileTree FileTree(string path) => new FileTree(this, path);

Expand Down
6 changes: 3 additions & 3 deletions src/lib/OS/IFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public interface IFileSystem
string CombinePath(string path1, string path2);
string ReadAllText(string path);
JsonElement ReadAllJson(string path);
T FromJsonTo<T>(string path);
T FromJsonTo<T>(string path, JsonSerializerOptions? options);
T FromJsonTo<T>(File file, JsonSerializerOptions? options);
T ReadJsonInto<T>(string path);
T ReadJsonInto<T>(string path, JsonSerializerOptions? options);
T ReadJsonInto<T>(File file, JsonSerializerOptions? options);
byte[] ReadAllBytes(string path);
FileTree FileTree(string path);
Dir? Parent(string path);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/OS/SimulatedFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public string ReadAllText(string path) =>

public JsonElement ReadAllJson(string path) => ReadAllBytes(path).FromJsonTo<JsonElement>();

public T FromJsonTo<T>(string path) => ReadAllBytes(path).FromJsonTo<T>();
public T ReadJsonInto<T>(string path) => ReadAllBytes(path).FromJsonTo<T>();

public T FromJsonTo<T>(string path, JsonSerializerOptions? options)
public T ReadJsonInto<T>(string path, JsonSerializerOptions? options)
=> throw new NotImplementedException();

public T FromJsonTo<T>(File file, JsonSerializerOptions? options)
=> FromJsonTo<T>(file.FullPath, options);
public T ReadJsonInto<T>(File file, JsonSerializerOptions? options)
=> ReadJsonInto<T>(file.FullPath, options);

public byte[] ReadAllBytes(string path) => Encoding.UTF8.GetBytes(ReadAllText(path));

Expand Down

0 comments on commit 9e146da

Please sign in to comment.