using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
namespace Content.Shared.Power;
///
/// Flags an entity as being a power monitoring console
///
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedPowerMonitoringConsoleSystem), Other = AccessPermissions.ReadExecute)]
public sealed partial class PowerMonitoringConsoleComponent : Component
{
///
/// The EntityUid of the device that is the console's current focus
///
///
/// Not-networked - set by the console UI
///
[ViewVariables]
public EntityUid? Focus;
///
/// The group that the device that is the console's current focus belongs to
///
/// ///
/// Not-networked - set by the console UI
///
[ViewVariables]
public PowerMonitoringConsoleGroup FocusGroup = PowerMonitoringConsoleGroup.Generator;
///
/// A list of flags relating to currently active events of interest to the console.
/// E.g., power sinks, power net anomalies
///
[ViewVariables, AutoNetworkedField]
public PowerMonitoringFlags Flags = PowerMonitoringFlags.None;
///
/// A dictionary containing all the meta data for tracked power monitoring devices
///
[ViewVariables, AutoNetworkedField]
public Dictionary PowerMonitoringDeviceMetaData = new();
}
[Serializable, NetSerializable]
public struct PowerMonitoringDeviceMetaData
{
public string EntityName;
public NetCoordinates Coordinates;
public PowerMonitoringConsoleGroup Group;
public string SpritePath;
public string SpriteState;
public NetEntity? CollectionMaster;
public PowerMonitoringDeviceMetaData(string name, NetCoordinates coordinates, PowerMonitoringConsoleGroup group, string spritePath, string spriteState)
{
EntityName = name;
Coordinates = coordinates;
Group = group;
SpritePath = spritePath;
SpriteState = spriteState;
}
}
///
/// Data from by the server to the client for the power monitoring console UI
///
[Serializable, NetSerializable]
public sealed class PowerMonitoringConsoleBoundInterfaceState : BoundUserInterfaceState
{
public double TotalSources;
public double TotalBatteryUsage;
public double TotalLoads;
public PowerMonitoringConsoleEntry[] AllEntries;
public PowerMonitoringConsoleEntry[] FocusSources;
public PowerMonitoringConsoleEntry[] FocusLoads;
public PowerMonitoringConsoleBoundInterfaceState
(double totalSources,
double totalBatteryUsage,
double totalLoads,
PowerMonitoringConsoleEntry[] allEntries,
PowerMonitoringConsoleEntry[] focusSources,
PowerMonitoringConsoleEntry[] focusLoads)
{
TotalSources = totalSources;
TotalBatteryUsage = totalBatteryUsage;
TotalLoads = totalLoads;
AllEntries = allEntries;
FocusSources = focusSources;
FocusLoads = focusLoads;
}
}
///
/// Contains all the data needed to update a single device on the power monitoring UI
///
[Serializable, NetSerializable]
public struct PowerMonitoringConsoleEntry
{
public NetEntity NetEntity;
public PowerMonitoringConsoleGroup Group;
public double PowerValue;
public float? BatteryLevel;
[NonSerialized] public PowerMonitoringDeviceMetaData? MetaData = null;
public PowerMonitoringConsoleEntry(NetEntity netEntity, PowerMonitoringConsoleGroup group, double powerValue = 0d, float? batteryLevel = null)
{
NetEntity = netEntity;
Group = group;
PowerValue = powerValue;
BatteryLevel = batteryLevel;
}
}
///
/// Triggers the server to send updated power monitoring console data to the client for the single player session
///
[Serializable, NetSerializable]
public sealed class PowerMonitoringConsoleMessage : BoundUserInterfaceMessage
{
public NetEntity? FocusDevice;
public PowerMonitoringConsoleGroup FocusGroup;
public PowerMonitoringConsoleMessage(NetEntity? focusDevice, PowerMonitoringConsoleGroup focusGroup)
{
FocusDevice = focusDevice;
FocusGroup = focusGroup;
}
}
///
/// Determines how entities are grouped and color coded on the power monitor
///
public enum PowerMonitoringConsoleGroup : byte
{
Generator,
SMES,
Substation,
APC,
Consumer,
}
[Flags]
public enum PowerMonitoringFlags : byte
{
None = 0,
RoguePowerConsumer = 1,
PowerNetAbnormalities = 2,
}
///
/// UI key associated with the power monitoring console
///
[Serializable, NetSerializable]
public enum PowerMonitoringConsoleUiKey
{
Key
}