Decouple GasPrototype IDs from Gas Enum (#41266)
* Remove final enum coupling from gas YAML * Fix comment * Fix test * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Client.Atmos.Components;
|
|||||||
using Content.Client.Atmos.EntitySystems;
|
using Content.Client.Atmos.EntitySystems;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.Atmos.Components;
|
using Content.Shared.Atmos.Components;
|
||||||
|
using Content.Shared.Atmos.EntitySystems;
|
||||||
using Content.Shared.Atmos.Prototypes;
|
using Content.Shared.Atmos.Prototypes;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
@@ -23,6 +24,7 @@ namespace Content.Client.Atmos.Overlays
|
|||||||
|
|
||||||
private readonly IEntityManager _entManager;
|
private readonly IEntityManager _entManager;
|
||||||
private readonly IMapManager _mapManager;
|
private readonly IMapManager _mapManager;
|
||||||
|
private readonly SharedAtmosphereSystem _atmosphereSystem;
|
||||||
private readonly SharedMapSystem _mapSystem;
|
private readonly SharedMapSystem _mapSystem;
|
||||||
private readonly SharedTransformSystem _xformSys;
|
private readonly SharedTransformSystem _xformSys;
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ namespace Content.Client.Atmos.Overlays
|
|||||||
{
|
{
|
||||||
_entManager = entManager;
|
_entManager = entManager;
|
||||||
_mapManager = IoCManager.Resolve<IMapManager>();
|
_mapManager = IoCManager.Resolve<IMapManager>();
|
||||||
|
_atmosphereSystem = entManager.System<SharedAtmosphereSystem>();
|
||||||
_mapSystem = entManager.System<SharedMapSystem>();
|
_mapSystem = entManager.System<SharedMapSystem>();
|
||||||
_xformSys = xformSys;
|
_xformSys = xformSys;
|
||||||
_shader = protoMan.Index(UnshadedShader).Instance();
|
_shader = protoMan.Index(UnshadedShader).Instance();
|
||||||
@@ -67,7 +70,7 @@ namespace Content.Client.Atmos.Overlays
|
|||||||
|
|
||||||
for (var i = 0; i < _gasCount; i++)
|
for (var i = 0; i < _gasCount; i++)
|
||||||
{
|
{
|
||||||
var gasPrototype = protoMan.Index<GasPrototype>(system.VisibleGasId[i].ToString());
|
var gasPrototype = _atmosphereSystem.GetGas(system.VisibleGasId[i]);
|
||||||
|
|
||||||
SpriteSpecifier overlay;
|
SpriteSpecifier overlay;
|
||||||
|
|
||||||
|
|||||||
@@ -38,12 +38,10 @@ public sealed class ConstantsTest
|
|||||||
Assert.That(Atmospherics.GasAbbreviations, Has.Count.EqualTo(Atmospherics.TotalNumberOfGases),
|
Assert.That(Atmospherics.GasAbbreviations, Has.Count.EqualTo(Atmospherics.TotalNumberOfGases),
|
||||||
$"GasAbbreviations size is not equal to TotalNumberOfGases.");
|
$"GasAbbreviations size is not equal to TotalNumberOfGases.");
|
||||||
|
|
||||||
// the ID for each gas has to be a number from 0 to TotalNumberOfGases-1
|
// the ID for each gas has to correspond to a value in the Gas enum (converted to a string)
|
||||||
foreach (var gas in gasProtos)
|
foreach (var gas in gasProtos)
|
||||||
{
|
{
|
||||||
var validInteger = int.TryParse(gas.ID, out var number);
|
Assert.That(Enum.TryParse<Gas>(gas.ID, out _), $"GasPrototype {gas.ID} has an invalid ID. It must correspond to a value in the {nameof(Gas)} enum.");
|
||||||
Assert.That(validInteger, Is.True, $"GasPrototype {gas.ID} has an invalid ID. It has to be an integer between 0 and TotalNumberOfGases - 1.");
|
|
||||||
Assert.That(number, Is.InRange(0, Atmospherics.TotalNumberOfGases - 1), $"GasPrototype {gas.ID} has an invalid ID. It has to be an integer between 0 and TotalNumberOfGases - 1.");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using Content.Shared.Atmos.Components;
|
|
||||||
using Content.Shared.Atmos.Prototypes;
|
using Content.Shared.Atmos.Prototypes;
|
||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
using Content.Shared.Body.Systems;
|
using Content.Shared.Body.Systems;
|
||||||
@@ -25,10 +24,17 @@ namespace Content.Shared.Atmos.EntitySystems
|
|||||||
|
|
||||||
InitializeBreathTool();
|
InitializeBreathTool();
|
||||||
|
|
||||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
foreach (var gas in Enum.GetValues<Gas>())
|
||||||
{
|
{
|
||||||
GasPrototypes[i] = _prototypeManager.Index<GasPrototype>(i.ToString());
|
var idx = (int)gas;
|
||||||
GasReagents[i] = GasPrototypes[i].Reagent;
|
// Log an error if the corresponding prototype isn't found
|
||||||
|
if (!_prototypeManager.TryIndex<GasPrototype>(gas.ToString(), out var gasPrototype))
|
||||||
|
{
|
||||||
|
Log.Error($"Failed to find corresponding {nameof(GasPrototype)} for gas ID {(int)gas} ({gas}) with expected ID \"{gas.ToString()}\". Is your prototype named correctly?");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
GasPrototypes[idx] = gasPrototype;
|
||||||
|
GasReagents[idx] = gasPrototype.Reagent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Content.Shared.Atmos.EntitySystems
|
|||||||
protected bool PvsEnabled;
|
protected bool PvsEnabled;
|
||||||
|
|
||||||
[Dependency] protected readonly IPrototypeManager ProtoMan = default!;
|
[Dependency] protected readonly IPrototypeManager ProtoMan = default!;
|
||||||
|
[Dependency] private readonly SharedAtmosphereSystem _atmosphere = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// array of the ids of all visible gases.
|
/// array of the ids of all visible gases.
|
||||||
@@ -28,7 +29,7 @@ namespace Content.Shared.Atmos.EntitySystems
|
|||||||
|
|
||||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
||||||
{
|
{
|
||||||
var gasPrototype = ProtoMan.Index<GasPrototype>(i.ToString());
|
var gasPrototype = _atmosphere.GetGas(i);
|
||||||
if (!string.IsNullOrEmpty(gasPrototype.GasOverlayTexture) || !string.IsNullOrEmpty(gasPrototype.GasOverlaySprite) && !string.IsNullOrEmpty(gasPrototype.GasOverlayState))
|
if (!string.IsNullOrEmpty(gasPrototype.GasOverlayTexture) || !string.IsNullOrEmpty(gasPrototype.GasOverlaySprite) && !string.IsNullOrEmpty(gasPrototype.GasOverlayState))
|
||||||
visibleGases.Add(i);
|
visibleGases.Add(i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
- type: gas
|
- type: gas
|
||||||
id: 0
|
id: Oxygen
|
||||||
name: gases-oxygen
|
name: gases-oxygen
|
||||||
specificHeat: 20
|
specificHeat: 20
|
||||||
heatCapacityRatio: 1.4
|
heatCapacityRatio: 1.4
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
pricePerMole: 0
|
pricePerMole: 0
|
||||||
|
|
||||||
- type: gas
|
- type: gas
|
||||||
id: 1
|
id: Nitrogen
|
||||||
name: gases-nitrogen
|
name: gases-nitrogen
|
||||||
specificHeat: 30
|
specificHeat: 30
|
||||||
heatCapacityRatio: 1.4
|
heatCapacityRatio: 1.4
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
pricePerMole: 0
|
pricePerMole: 0
|
||||||
|
|
||||||
- type: gas
|
- type: gas
|
||||||
id: 2
|
id: CarbonDioxide
|
||||||
name: gases-co2
|
name: gases-co2
|
||||||
specificHeat: 30
|
specificHeat: 30
|
||||||
heatCapacityRatio: 1.3
|
heatCapacityRatio: 1.3
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
pricePerMole: 0
|
pricePerMole: 0
|
||||||
|
|
||||||
- type: gas
|
- type: gas
|
||||||
id: 3
|
id: Plasma
|
||||||
name: gases-plasma
|
name: gases-plasma
|
||||||
specificHeat: 200
|
specificHeat: 200
|
||||||
heatCapacityRatio: 1.7
|
heatCapacityRatio: 1.7
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
pricePerMole: 0
|
pricePerMole: 0
|
||||||
|
|
||||||
- type: gas
|
- type: gas
|
||||||
id: 4
|
id: Tritium
|
||||||
name: gases-tritium
|
name: gases-tritium
|
||||||
specificHeat: 10
|
specificHeat: 10
|
||||||
heatCapacityRatio: 1.3
|
heatCapacityRatio: 1.3
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
pricePerMole: 2.5
|
pricePerMole: 2.5
|
||||||
|
|
||||||
- type: gas
|
- type: gas
|
||||||
id: 5
|
id: WaterVapor
|
||||||
name: gases-water-vapor
|
name: gases-water-vapor
|
||||||
specificHeat: 40
|
specificHeat: 40
|
||||||
heatCapacityRatio: 1.33
|
heatCapacityRatio: 1.33
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
pricePerMole: 0
|
pricePerMole: 0
|
||||||
|
|
||||||
- type: gas
|
- type: gas
|
||||||
id: 6
|
id: Ammonia
|
||||||
name: gases-ammonia
|
name: gases-ammonia
|
||||||
specificHeat: 20
|
specificHeat: 20
|
||||||
heatCapacityRatio: 1.4
|
heatCapacityRatio: 1.4
|
||||||
@@ -79,7 +79,7 @@
|
|||||||
pricePerMole: 0.15
|
pricePerMole: 0.15
|
||||||
|
|
||||||
- type: gas
|
- type: gas
|
||||||
id: 7
|
id: NitrousOxide
|
||||||
name: gases-n2o
|
name: gases-n2o
|
||||||
specificHeat: 40
|
specificHeat: 40
|
||||||
heatCapacityRatio: 1.3
|
heatCapacityRatio: 1.3
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
pricePerMole: 0.1
|
pricePerMole: 0.1
|
||||||
|
|
||||||
- type: gas
|
- type: gas
|
||||||
id: 8
|
id: Frezon
|
||||||
name: gases-frezon
|
name: gases-frezon
|
||||||
specificHeat: 600 # Strongest by far
|
specificHeat: 600 # Strongest by far
|
||||||
heatCapacityRatio: 1.33
|
heatCapacityRatio: 1.33
|
||||||
|
|||||||
Reference in New Issue
Block a user