34 lines
1006 B
C#
34 lines
1006 B
C#
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);
|
|
}
|
|
}
|
|
} |