26 lines
811 B
C#
26 lines
811 B
C#
using System.Text.Json;
|
|
|
|
public static class ScenarioLoader
|
|
{
|
|
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
ReadCommentHandling = JsonCommentHandling.Skip,
|
|
AllowTrailingCommas = true
|
|
};
|
|
|
|
public static ScenarioFile Load(string path)
|
|
{
|
|
if (!File.Exists(path))
|
|
throw new FileNotFoundException($"Scenario file not found: {path}");
|
|
|
|
var json = File.ReadAllText(path);
|
|
var scenario = JsonSerializer.Deserialize<ScenarioFile>(json, JsonOptions)
|
|
?? throw new InvalidOperationException($"Failed to deserialize: {path}");
|
|
|
|
return scenario with
|
|
{
|
|
Events = scenario.Events.OrderBy(e => e.OffsetMinutes).ToList()
|
|
};
|
|
}
|
|
} |