AtmosCommandUtils.cs 704 B

123456789101112131415161718192021222324
  1. namespace Content.Shared.Atmos
  2. {
  3. public sealed class AtmosCommandUtils
  4. {
  5. /// <summary>
  6. /// Gas ID parser for atmospherics commands.
  7. /// This is so there's a central place for this logic for if the Gas enum gets removed.
  8. /// </summary>
  9. public static bool TryParseGasID(string str, out int x)
  10. {
  11. x = -1;
  12. if (Enum.TryParse<Gas>(str, true, out var gas))
  13. {
  14. x = (int) gas;
  15. }
  16. else
  17. {
  18. if (!int.TryParse(str, out x))
  19. return false;
  20. }
  21. return ((x >= 0) && (x < Atmospherics.TotalNumberOfGases));
  22. }
  23. }
  24. }