feature: Console Replay Simulator
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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()
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user