refactor(backend): align api namespaces and project name

This commit is contained in:
2026-03-19 17:44:53 -04:00
parent a281d37fb4
commit 07a3142316
35 changed files with 191 additions and 169 deletions

View File

@@ -1,4 +1,7 @@
namespace SpaceGame.Simulation.Api.Simulation;
using SpaceGame.Api.Simulation.Engine;
using SpaceGame.Api.Simulation.Model;
namespace SpaceGame.Api.Simulation.AI;
// ─── Planning State ────────────────────────────────────────────────────────────

View File

@@ -1,4 +1,7 @@
namespace SpaceGame.Simulation.Api.Simulation;
using SpaceGame.Api.Simulation.Engine;
using SpaceGame.Api.Simulation.Model;
namespace SpaceGame.Api.Simulation.AI;
public abstract class GoapAction<TState>
{

View File

@@ -1,10 +1,13 @@
namespace SpaceGame.Simulation.Api.Simulation;
using SpaceGame.Api.Simulation.Engine;
using SpaceGame.Api.Simulation.Model;
namespace SpaceGame.Api.Simulation.AI;
internal interface IShipBehaviorState
{
string Kind { get; }
string Kind { get; }
void Plan(SimulationEngine engine, ShipRuntime ship, SimulationWorld world);
void Plan(SimulationEngine engine, ShipRuntime ship, SimulationWorld world);
void ApplyEvent(SimulationEngine engine, ShipRuntime ship, SimulationWorld world, string controllerEvent);
void ApplyEvent(SimulationEngine engine, ShipRuntime ship, SimulationWorld world, string controllerEvent);
}

View File

@@ -1,38 +1,41 @@
namespace SpaceGame.Simulation.Api.Simulation;
using SpaceGame.Api.Simulation.Engine;
using SpaceGame.Api.Simulation.Model;
namespace SpaceGame.Api.Simulation.AI;
internal sealed class ShipBehaviorStateMachine
{
private readonly IReadOnlyDictionary<string, IShipBehaviorState> states;
private readonly IShipBehaviorState fallbackState;
private readonly IReadOnlyDictionary<string, IShipBehaviorState> states;
private readonly IShipBehaviorState fallbackState;
private ShipBehaviorStateMachine(IReadOnlyDictionary<string, IShipBehaviorState> states, IShipBehaviorState fallbackState)
{
this.states = states;
this.fallbackState = fallbackState;
}
private ShipBehaviorStateMachine(IReadOnlyDictionary<string, IShipBehaviorState> states, IShipBehaviorState fallbackState)
{
this.states = states;
this.fallbackState = fallbackState;
}
public static ShipBehaviorStateMachine CreateDefault()
public static ShipBehaviorStateMachine CreateDefault()
{
var idleState = new IdleShipBehaviorState();
var knownStates = new IShipBehaviorState[]
{
var idleState = new IdleShipBehaviorState();
var knownStates = new IShipBehaviorState[]
{
idleState,
new PatrolShipBehaviorState(),
new ResourceHarvestShipBehaviorState("auto-mine", "ore", "mining"),
new ConstructStationShipBehaviorState(),
};
};
return new ShipBehaviorStateMachine(
knownStates.ToDictionary(state => state.Kind, StringComparer.Ordinal),
idleState);
}
return new ShipBehaviorStateMachine(
knownStates.ToDictionary(state => state.Kind, StringComparer.Ordinal),
idleState);
}
public void Plan(SimulationEngine engine, ShipRuntime ship, SimulationWorld world) =>
Resolve(ship.DefaultBehavior.Kind).Plan(engine, ship, world);
public void Plan(SimulationEngine engine, ShipRuntime ship, SimulationWorld world) =>
Resolve(ship.DefaultBehavior.Kind).Plan(engine, ship, world);
public void ApplyEvent(SimulationEngine engine, ShipRuntime ship, SimulationWorld world, string controllerEvent) =>
Resolve(ship.DefaultBehavior.Kind).ApplyEvent(engine, ship, world, controllerEvent);
public void ApplyEvent(SimulationEngine engine, ShipRuntime ship, SimulationWorld world, string controllerEvent) =>
Resolve(ship.DefaultBehavior.Kind).ApplyEvent(engine, ship, world, controllerEvent);
private IShipBehaviorState Resolve(string kind) =>
states.TryGetValue(kind, out var state) ? state : fallbackState;
private IShipBehaviorState Resolve(string kind) =>
states.TryGetValue(kind, out var state) ? state : fallbackState;
}

View File

@@ -1,4 +1,7 @@
namespace SpaceGame.Simulation.Api.Simulation;
using SpaceGame.Api.Simulation.Engine;
using SpaceGame.Api.Simulation.Model;
namespace SpaceGame.Api.Simulation.AI;
internal sealed class IdleShipBehaviorState : IShipBehaviorState
{

View File

@@ -1,4 +1,7 @@
namespace SpaceGame.Simulation.Api.Simulation;
using SpaceGame.Api.Simulation.Engine;
using SpaceGame.Api.Simulation.Model;
namespace SpaceGame.Api.Simulation.AI;
// ─── Planning State ────────────────────────────────────────────────────────────