Refactor world bootstrap and allow empty startup worlds
This commit is contained in:
@@ -12,16 +12,16 @@ public sealed class ScenarioLoader(IOptions<StaticDataOptions> staticDataOptions
|
||||
PropertyNameCaseInsensitive = true,
|
||||
};
|
||||
|
||||
public ScenarioDefinition? Load()
|
||||
public ScenarioDefinition Load(string relativePath)
|
||||
{
|
||||
var scenarioPath = Path.Combine(staticDataOptions.Value.DataRoot, "scenario.json");
|
||||
var scenarioPath = Path.Combine(staticDataOptions.Value.DataRoot, relativePath);
|
||||
if (!File.Exists(scenarioPath))
|
||||
{
|
||||
return null;
|
||||
throw new FileNotFoundException($"Scenario file was not found: {relativePath}", scenarioPath);
|
||||
}
|
||||
|
||||
var json = File.ReadAllText(scenarioPath);
|
||||
return JsonSerializer.Deserialize<ScenarioDefinition>(json, _jsonOptions)
|
||||
?? throw new InvalidOperationException("Unable to read scenario.json.");
|
||||
?? throw new InvalidOperationException($"Unable to read {relativePath}.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user