Refactor station modules into typed runtime models
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
using SpaceGame.Api.Definitions;
|
||||
using SpaceGame.Api.Shared.Runtime;
|
||||
|
||||
namespace SpaceGame.Api.Stations.Runtime;
|
||||
|
||||
public sealed class StationRuntime
|
||||
@@ -33,12 +36,55 @@ public sealed class StationRuntime
|
||||
public string LastDeltaSignature { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public sealed class StationModuleRuntime
|
||||
public class StationModuleRuntime
|
||||
{
|
||||
public required string Id { get; init; }
|
||||
public required string ModuleId { get; init; }
|
||||
public required ModuleType ModuleType { get; init; }
|
||||
public float Health { get; set; }
|
||||
public float MaxHealth { get; set; }
|
||||
|
||||
public static StationModuleRuntime Create(string id, ModuleDefinition definition) =>
|
||||
definition switch
|
||||
{
|
||||
StorageModuleDefinition storage => new StorageStationModuleRuntime
|
||||
{
|
||||
Id = id,
|
||||
ModuleId = storage.Id,
|
||||
ModuleType = storage.ModuleType,
|
||||
StorageKind = storage.StorageKind,
|
||||
Health = storage.Hull,
|
||||
MaxHealth = storage.Hull,
|
||||
},
|
||||
ProductionModuleDefinition production => new ProductionStationModuleRuntime
|
||||
{
|
||||
Id = id,
|
||||
ModuleId = production.Id,
|
||||
ModuleType = production.ModuleType,
|
||||
ProductItemIds = [.. production.ProductItemIds],
|
||||
Health = production.Hull,
|
||||
MaxHealth = production.Hull,
|
||||
},
|
||||
_ => new StationModuleRuntime
|
||||
{
|
||||
Id = id,
|
||||
ModuleId = definition.Id,
|
||||
ModuleType = definition.ModuleType,
|
||||
Health = definition.Hull,
|
||||
MaxHealth = definition.Hull,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class ProductionStationModuleRuntime : StationModuleRuntime
|
||||
{
|
||||
public IReadOnlyList<string> ProductItemIds { get; init; } = [];
|
||||
}
|
||||
|
||||
public sealed class StorageStationModuleRuntime : StationModuleRuntime
|
||||
{
|
||||
public StorageKind StorageKind { get; init; }
|
||||
public float CurrentLevel { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ModuleConstructionRuntime
|
||||
|
||||
Reference in New Issue
Block a user