Fix parallel tests unreliably failing due to statics in Atmospherics (#1914)

* Fix atmospherics statics unreliably failing parallel tests

* Cache getting atmosphere system
This commit is contained in:
DrSmugleaf
2020-08-25 16:14:26 +02:00
committed by GitHub
parent f436429a81
commit 4f8fbe2749
11 changed files with 107 additions and 73 deletions

View File

@@ -1,45 +1,10 @@
using System.Collections.Generic;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Atmos
namespace Content.Shared.Atmos
{
/// <summary>
/// Class to store atmos constants.
/// </summary>
public static class Atmospherics
public class Atmospherics
{
static Atmospherics()
{
var protoMan = IoCManager.Resolve<IPrototypeManager>();
GasPrototypes = new GasPrototype[TotalNumberOfGases];
GasOverlays = new SpriteSpecifier[TotalNumberOfGases];
for (var i = 0; i < TotalNumberOfGases; i++)
{
var gasPrototype = protoMan.Index<GasPrototype>(i.ToString());
GasPrototypes[i] = gasPrototype;
if(string.IsNullOrEmpty(gasPrototype.GasOverlaySprite) && !string.IsNullOrEmpty(gasPrototype.GasOverlayTexture))
GasOverlays[i] = new SpriteSpecifier.Texture(new ResourcePath(gasPrototype.GasOverlayTexture));
if(!string.IsNullOrEmpty(gasPrototype.GasOverlaySprite) && !string.IsNullOrEmpty(gasPrototype.GasOverlayState))
GasOverlays[i] = new SpriteSpecifier.Rsi(new ResourcePath(gasPrototype.GasOverlaySprite), gasPrototype.GasOverlayState);
}
}
private static readonly GasPrototype[] GasPrototypes;
public static GasPrototype GetGas(int gasId) => GasPrototypes[gasId];
public static GasPrototype GetGas(Gas gasId) => GasPrototypes[(int) gasId];
public static IEnumerable<GasPrototype> Gases => GasPrototypes;
private static readonly SpriteSpecifier[] GasOverlays;
public static SpriteSpecifier GetOverlay(int overlayId) => GasOverlays[overlayId];
#region ATMOS
/// <summary>
/// The universal gas constant, in kPa*L/(K*mol)