Simulation bridge
This commit is contained in:
34
src/ReactorMaintenance.Godot/Data/LevelStateLoader.cs
Normal file
34
src/ReactorMaintenance.Godot/Data/LevelStateLoader.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using ReactorMaintenance.Simulation;
|
||||
using FileAccess = Godot.FileAccess;
|
||||
|
||||
namespace ReactorMaintenance.Godot.Data;
|
||||
|
||||
public static class LevelStateLoader
|
||||
{
|
||||
public static LevelState Load(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
throw new ArgumentException("Level path must not be null or empty.", nameof(path));
|
||||
|
||||
if (!FileAccess.FileExists(path))
|
||||
throw new FileNotFoundException($"Level file not found: {path}");
|
||||
|
||||
var json = FileAccess.GetFileAsString(path);
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
throw new InvalidOperationException($"Level file is empty: {path}");
|
||||
|
||||
try
|
||||
{
|
||||
return LevelSerializer.Deserialize(json);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Failed to deserialize level from {path}: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user