chore: convert movement regime kinds to enum
This commit is contained in:
@@ -94,12 +94,25 @@ public enum SpaceLayerKind
|
||||
LocalSpace,
|
||||
}
|
||||
|
||||
public static class MovementRegimeKinds
|
||||
public enum MovementRegimeKind
|
||||
{
|
||||
public const string LocalFlight = "local-flight";
|
||||
public const string Warp = "warp";
|
||||
public const string StargateTransit = "stargate-transit";
|
||||
public const string FtlTransit = "ftl-transit";
|
||||
LocalFlight,
|
||||
Warp,
|
||||
StargateTransit,
|
||||
FtlTransit,
|
||||
}
|
||||
|
||||
public enum ModuleType
|
||||
{
|
||||
BuildModule,
|
||||
ConnectionModule,
|
||||
DefenceModule,
|
||||
DockArea,
|
||||
Habitation,
|
||||
Pier,
|
||||
ProcessingModule,
|
||||
Production,
|
||||
Storage,
|
||||
}
|
||||
|
||||
public static class CommanderKind
|
||||
@@ -182,6 +195,34 @@ public static class MarketOrderStateKinds
|
||||
|
||||
public static class SimulationEnumMappings
|
||||
{
|
||||
public static string ToDataValue(this ModuleType moduleType) => moduleType switch
|
||||
{
|
||||
ModuleType.BuildModule => "buildmodule",
|
||||
ModuleType.ConnectionModule => "connectionmodule",
|
||||
ModuleType.DefenceModule => "defencemodule",
|
||||
ModuleType.DockArea => "dockarea",
|
||||
ModuleType.Habitation => "habitation",
|
||||
ModuleType.Pier => "pier",
|
||||
ModuleType.ProcessingModule => "processingmodule",
|
||||
ModuleType.Production => "production",
|
||||
ModuleType.Storage => "storage",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(moduleType), moduleType, null),
|
||||
};
|
||||
|
||||
public static ModuleType ToModuleType(this string value) => value.Trim() switch
|
||||
{
|
||||
"buildmodule" => ModuleType.BuildModule,
|
||||
"connectionmodule" => ModuleType.ConnectionModule,
|
||||
"defencemodule" => ModuleType.DefenceModule,
|
||||
"dockarea" => ModuleType.DockArea,
|
||||
"habitation" => ModuleType.Habitation,
|
||||
"pier" => ModuleType.Pier,
|
||||
"processingmodule" => ModuleType.ProcessingModule,
|
||||
"production" => ModuleType.Production,
|
||||
"storage" => ModuleType.Storage,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unsupported module type."),
|
||||
};
|
||||
|
||||
public static string ToContractValue(this SpatialNodeKind kind) => kind switch
|
||||
{
|
||||
SpatialNodeKind.Star => "star",
|
||||
@@ -283,4 +324,13 @@ public static class SimulationEnumMappings
|
||||
SpaceLayerKind.LocalSpace => "local-space",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(kind), kind, null),
|
||||
};
|
||||
|
||||
public static string ToContractValue(this MovementRegimeKind kind) => kind switch
|
||||
{
|
||||
MovementRegimeKind.LocalFlight => "local-flight",
|
||||
MovementRegimeKind.Warp => "warp",
|
||||
MovementRegimeKind.StargateTransit => "stargate-transit",
|
||||
MovementRegimeKind.FtlTransit => "ftl-transit",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(kind), kind, null),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@ internal static class SimulationRuntimeSupport
|
||||
internal static int CountStationModules(StationRuntime station, string moduleId) =>
|
||||
station.Modules.Count(module => string.Equals(module.ModuleId, moduleId, StringComparison.Ordinal));
|
||||
|
||||
internal static int CountStationModules(SimulationWorld world, StationRuntime station, ModuleType moduleType) =>
|
||||
station.Modules.Count(module =>
|
||||
world.ModuleDefinitions.TryGetValue(module.ModuleId, out var definition)
|
||||
&& definition.ModuleType == moduleType);
|
||||
|
||||
internal static void AddStationModule(SimulationWorld world, StationRuntime station, string moduleId)
|
||||
{
|
||||
if (!world.ModuleDefinitions.TryGetValue(moduleId, out var definition))
|
||||
@@ -61,6 +66,14 @@ internal static class SimulationRuntimeSupport
|
||||
internal static int CountModules(IEnumerable<string> modules, string moduleId) =>
|
||||
modules.Count(candidate => string.Equals(candidate, moduleId, StringComparison.Ordinal));
|
||||
|
||||
internal static int CountModules(
|
||||
IEnumerable<string> modules,
|
||||
IReadOnlyDictionary<string, ModuleDefinition> moduleDefinitions,
|
||||
ModuleType moduleType) =>
|
||||
modules.Count(moduleId =>
|
||||
moduleDefinitions.TryGetValue(moduleId, out var definition)
|
||||
&& definition.ModuleType == moduleType);
|
||||
|
||||
internal static float GetInventoryAmount(IReadOnlyDictionary<string, float> inventory, string itemId) =>
|
||||
inventory.TryGetValue(itemId, out var amount) ? amount : 0f;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user