1
0

DeviceNetworkConstants.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Content.Server.DeviceNetwork.Components;
  2. using Robust.Shared.Utility;
  3. namespace Content.Server.DeviceNetwork
  4. {
  5. /// <summary>
  6. /// A collection of constants to help with using device networks
  7. /// </summary>
  8. public static class DeviceNetworkConstants
  9. {
  10. /// <summary>
  11. /// Used by logic gates to transmit the state of their ports
  12. /// </summary>
  13. public const string LogicState = "logic_state";
  14. #region Commands
  15. /// <summary>
  16. /// The key for command names
  17. /// E.g. [DeviceNetworkConstants.Command] = "ping"
  18. /// </summary>
  19. public const string Command = "command";
  20. /// <summary>
  21. /// The command for setting a devices state
  22. /// E.g. to turn a light on or off
  23. /// </summary>
  24. public const string CmdSetState = "set_state";
  25. /// <summary>
  26. /// The command for a device that just updated its state
  27. /// E.g. suit sensors broadcasting owners vitals state
  28. /// </summary>
  29. public const string CmdUpdatedState = "updated_state";
  30. #endregion
  31. #region SetState
  32. /// <summary>
  33. /// Used with the <see cref="CmdSetState"/> command to turn a device on or off
  34. /// </summary>
  35. public const string StateEnabled = "state_enabled";
  36. #endregion
  37. #region DisplayHelpers
  38. /// <summary>
  39. /// Converts the unsigned int to string and inserts a number before the last digit
  40. /// </summary>
  41. public static string FrequencyToString(this uint frequency)
  42. {
  43. var result = frequency.ToString();
  44. if (result.Length <= 2)
  45. return result + ".0";
  46. return result.Insert(result.Length - 1, ".");
  47. }
  48. /// <summary>
  49. /// Either returns the localized name representation of the corresponding <see cref="DeviceNetworkComponent.DeviceNetIdDefaults"/>
  50. /// or converts the id to string
  51. /// </summary>
  52. public static string DeviceNetIdToLocalizedName(this int id)
  53. {
  54. if (!Enum.IsDefined(typeof(DeviceNetworkComponent.DeviceNetIdDefaults), id))
  55. return id.ToString();
  56. var result = ((DeviceNetworkComponent.DeviceNetIdDefaults) id).ToString();
  57. var resultKebab = "device-net-id-" + CaseConversion.PascalToKebab(result);
  58. return !Loc.TryGetString(resultKebab, out var name) ? result : name;
  59. }
  60. #endregion
  61. }
  62. }