using Robust.Shared.Utility;
using Content.Shared.DeviceNetwork.Components;
namespace Content.Shared.DeviceNetwork
{
///
/// A collection of constants to help with using device networks
///
public static class DeviceNetworkConstants
{
///
/// Used by logic gates to transmit the state of their ports
///
public const string LogicState = "logic_state";
#region Commands
///
/// The key for command names
/// E.g. [DeviceNetworkConstants.Command] = "ping"
///
public const string Command = "command";
///
/// The command for setting a devices state
/// E.g. to turn a light on or off
///
public const string CmdSetState = "set_state";
///
/// The command for a device that just updated its state
/// E.g. suit sensors broadcasting owners vitals state
///
public const string CmdUpdatedState = "updated_state";
#endregion
#region SetState
///
/// Used with the command to turn a device on or off
///
public const string StateEnabled = "state_enabled";
#endregion
#region DisplayHelpers
///
/// Converts the unsigned int to string and inserts a number before the last digit
///
public static string FrequencyToString(this uint frequency)
{
var result = frequency.ToString();
if (result.Length <= 2)
return result + ".0";
return result.Insert(result.Length - 1, ".");
}
///
/// Either returns the localized name representation of the corresponding
/// or converts the id to string
///
public static string DeviceNetIdToLocalizedName(this int id)
{
if (!Enum.IsDefined(typeof(DeviceNetworkComponent.DeviceNetIdDefaults), id))
return id.ToString();
var result = ((DeviceNetworkComponent.DeviceNetIdDefaults) id).ToString();
var resultKebab = "device-net-id-" + CaseConversion.PascalToKebab(result);
return !Loc.TryGetString(resultKebab, out var name) ? result : name;
}
#endregion
}
}