add power sensor (#20400)
* clean up logic gate / edge detector components * logic gate usedelay support * new codersprite * PowerSensor component and system * add power sensor * port locale * fix * minecraft * fixy --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,35 +1,34 @@
|
||||
using Content.Server.DeviceLinking.Systems;
|
||||
using Content.Shared.DeviceLinking;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.DeviceLinking.Components;
|
||||
|
||||
/// <summary>
|
||||
/// An edge detector that pulses high or low output ports when the input port gets a rising or falling edge respectively.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(EdgeDetectorSystem))]
|
||||
[RegisterComponent, Access(typeof(EdgeDetectorSystem))]
|
||||
public sealed partial class EdgeDetectorComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the input port.
|
||||
/// </summary>
|
||||
[DataField("inputPort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
|
||||
public string InputPort = "Input";
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<SinkPortPrototype> InputPort = "Input";
|
||||
|
||||
/// <summary>
|
||||
/// Name of the rising edge output port.
|
||||
/// </summary>
|
||||
[DataField("outputHighPort", customTypeSerializer: typeof(PrototypeIdSerializer<SourcePortPrototype>))]
|
||||
public string OutputHighPort = "OutputHigh";
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<SourcePortPrototype> OutputHighPort = "OutputHigh";
|
||||
|
||||
/// <summary>
|
||||
/// Name of the falling edge output port.
|
||||
/// </summary>
|
||||
[DataField("outputLowPort", customTypeSerializer: typeof(PrototypeIdSerializer<SourcePortPrototype>))]
|
||||
public string OutputLowPort = "OutputLow";
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<SourcePortPrototype> OutputLowPort = "OutputLow";
|
||||
|
||||
// Initial state
|
||||
[ViewVariables]
|
||||
[DataField]
|
||||
public SignalState State = SignalState.Low;
|
||||
}
|
||||
|
||||
@@ -2,62 +2,61 @@ using Content.Server.DeviceLinking.Systems;
|
||||
using Content.Shared.DeviceLinking;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.DeviceLinking.Components;
|
||||
|
||||
/// <summary>
|
||||
/// A logic gate that sets its output port by doing an operation on its 2 input ports, A and B.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(LogicGateSystem))]
|
||||
[RegisterComponent, Access(typeof(LogicGateSystem))]
|
||||
public sealed partial class LogicGateComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The logic gate operation to use.
|
||||
/// </summary>
|
||||
[DataField("gate")]
|
||||
[DataField]
|
||||
public LogicGate Gate = LogicGate.Or;
|
||||
|
||||
/// <summary>
|
||||
/// Tool quality to use for cycling logic gate operations.
|
||||
/// Cannot be pulsing since linking uses that.
|
||||
/// </summary>
|
||||
[DataField("cycleQuality", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
public string CycleQuality = "Screwing";
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<ToolQualityPrototype> CycleQuality = "Screwing";
|
||||
|
||||
/// <summary>
|
||||
/// Sound played when cycling logic gate operations.
|
||||
/// </summary>
|
||||
[DataField("cycleSound")]
|
||||
[DataField]
|
||||
public SoundSpecifier CycleSound = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Name of the first input port.
|
||||
/// </summary>
|
||||
[DataField("inputPortA", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
|
||||
public string InputPortA = "InputA";
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<SinkPortPrototype> InputPortA = "InputA";
|
||||
|
||||
/// <summary>
|
||||
/// Name of the second input port.
|
||||
/// </summary>
|
||||
[DataField("inputPortB", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
|
||||
public string InputPortB = "InputB";
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<SinkPortPrototype> InputPortB = "InputB";
|
||||
|
||||
/// <summary>
|
||||
/// Name of the output port.
|
||||
/// </summary>
|
||||
[DataField("outputPort", customTypeSerializer: typeof(PrototypeIdSerializer<SourcePortPrototype>))]
|
||||
public string OutputPort = "Output";
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<SourcePortPrototype> OutputPort = "Output";
|
||||
|
||||
// Initial state
|
||||
[ViewVariables]
|
||||
[DataField]
|
||||
public SignalState StateA = SignalState.Low;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField]
|
||||
public SignalState StateB = SignalState.Low;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField]
|
||||
public bool LastOutput;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
using Content.Server.DeviceLinking.Systems;
|
||||
using Content.Shared.DeviceLinking;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Server.DeviceLinking.Components;
|
||||
|
||||
/// <summary>
|
||||
/// A power sensor checks the power network it's anchored to.
|
||||
/// Has 2 ports for when it is charging or discharging. They should never both be high.
|
||||
/// Requires <see cref="PowerSwitchableComponent"/> to function.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(PowerSensorSystem))]
|
||||
public sealed partial class PowerSensorComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether to check the power network's input or output battery stats.
|
||||
/// Useful when working with SMESes where input and output can both be important.
|
||||
/// Or with APCs where there is no output and only input.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Output;
|
||||
|
||||
/// <summary>
|
||||
/// Tool quality to use for switching between input and output.
|
||||
/// Cannot be pulsing since linking uses that.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<ToolQualityPrototype> SwitchQuality = "Screwing";
|
||||
|
||||
/// <summary>
|
||||
/// Sound played when switching between input and output.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier SwitchSound = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Name of the port set when the network is charging power.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<SourcePortPrototype> ChargingPort = "PowerCharging";
|
||||
|
||||
/// <summary>
|
||||
/// Name of the port set when the network is discharging power.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<SourcePortPrototype> DischargingPort = "PowerDischarging";
|
||||
|
||||
/// <summary>
|
||||
/// How long to wait before checking the power network.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan CheckDelay = TimeSpan.FromSeconds(1);
|
||||
|
||||
/// <summary>
|
||||
/// Time at which power will be checked.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan NextCheck = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Charge the network was at, at the last check.
|
||||
/// Charging/discharging is derived from this.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float LastCharge;
|
||||
|
||||
// Initial state
|
||||
[DataField]
|
||||
public bool ChargingState;
|
||||
|
||||
[DataField]
|
||||
public bool DischargingState;
|
||||
}
|
||||
Reference in New Issue
Block a user