to rename

This commit is contained in:
2026-03-28 11:32:28 -04:00
parent 04d182e93f
commit 640e147ea8
25 changed files with 367 additions and 224 deletions

View File

@@ -1,26 +1,27 @@
using System.Text.Json;
using Microsoft.Extensions.Options;
using SpaceGame.Api.Universe.Bootstrap;
namespace SpaceGame.Api.Universe.Scenario;
public sealed class ScenarioLoader
public sealed class ScenarioLoader(IOptions<StaticDataOptions> staticDataOptions)
{
private readonly WorldBuilder _worldBuilder;
public ScenarioLoader(string contentRootPath, WorldGenerationOptions? worldGeneration = null)
private readonly JsonSerializerOptions _jsonOptions = new()
{
var generationOptions = worldGeneration ?? new WorldGenerationOptions();
var dataRoot = Path.GetFullPath(Path.Combine(contentRootPath, "..", "..", "shared", "data"));
var dataLoader = new DataCatalogLoader(dataRoot);
var generationService = new SystemGenerationService();
var spatialBuilder = new SpatialBuilder();
var seedingService = new WorldSeedingService();
PropertyNameCaseInsensitive = true,
};
_worldBuilder = new WorldBuilder(
generationOptions,
dataLoader,
generationService,
spatialBuilder,
seedingService);
public ScenarioDefinition? Load()
{
var scenarioPath = Path.Combine(staticDataOptions.Value.DataRoot, "scenario.json");
if (!File.Exists(scenarioPath))
{
return null;
}
var json = File.ReadAllText(scenarioPath);
return JsonSerializer.Deserialize<ScenarioDefinition>(json, _jsonOptions)
?? throw new InvalidOperationException("Unable to read scenario.json.");
}
public SimulationWorld Load() => _worldBuilder.Build();
}