make linking logic gates 1000% better (#25041)
* make door status use SendSignal * LastSignals and logic, add ClearSignal api too * make everything outputting a logic signal default to false * refactor ops * :trollface: * :trollface: * protoid for LastSignals * oop --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.DeviceLinking;
|
||||
|
||||
@@ -11,25 +11,32 @@ public sealed partial class DeviceLinkSourceComponent : Component
|
||||
/// <summary>
|
||||
/// The ports the device link source sends signals from
|
||||
/// </summary>
|
||||
[DataField("ports", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<SourcePortPrototype>))]
|
||||
public HashSet<string>? Ports;
|
||||
[DataField]
|
||||
public HashSet<ProtoId<SourcePortPrototype>>? Ports;
|
||||
|
||||
/// <summary>
|
||||
/// A list of sink uids that got linked for each port
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Dictionary<string, HashSet<EntityUid>> Outputs = new();
|
||||
public Dictionary<ProtoId<SourcePortPrototype>, HashSet<EntityUid>> Outputs = new();
|
||||
|
||||
/// <summary>
|
||||
/// If set to High or Low, the last signal state for a given port.
|
||||
/// Used when linking ports of devices that are currently outputting a signal.
|
||||
/// Only set by <c>DeviceLinkSystem.SendSignal</c>.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public Dictionary<ProtoId<SourcePortPrototype>, bool> LastSignals = new();
|
||||
|
||||
/// <summary>
|
||||
/// The list of source to sink ports for each linked sink entity for easier managing of links
|
||||
/// </summary>
|
||||
[DataField("linkedPorts")]
|
||||
public Dictionary<EntityUid, HashSet<(string source, string sink)>> LinkedPorts = new();
|
||||
[DataField]
|
||||
public Dictionary<EntityUid, HashSet<(ProtoId<SourcePortPrototype> source, ProtoId<SinkPortPrototype> sink)>> LinkedPorts = new();
|
||||
|
||||
/// <summary>
|
||||
/// Limits the range devices can be linked across.
|
||||
/// </summary>
|
||||
[DataField("range")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public float Range = 30f;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
|
||||
return;
|
||||
|
||||
var comp = EnsureComp<DeviceLinkSourceComponent>(uid);
|
||||
comp.Ports ??= new HashSet<string>();
|
||||
comp.Ports ??= new HashSet<ProtoId<SourcePortPrototype>>();
|
||||
|
||||
foreach (var port in ports)
|
||||
{
|
||||
@@ -233,10 +233,10 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
|
||||
/// Returns the links of a source
|
||||
/// </summary>
|
||||
/// <returns>A list of sink and source port ids that are linked together</returns>
|
||||
public HashSet<(string source, string sink)> GetLinks(EntityUid sourceUid, EntityUid sinkUid, DeviceLinkSourceComponent? sourceComponent = null)
|
||||
public HashSet<(ProtoId<SourcePortPrototype> source, ProtoId<SinkPortPrototype> sink)> GetLinks(EntityUid sourceUid, EntityUid sinkUid, DeviceLinkSourceComponent? sourceComponent = null)
|
||||
{
|
||||
if (!Resolve(sourceUid, ref sourceComponent) || !sourceComponent.LinkedPorts.TryGetValue(sinkUid, out var links))
|
||||
return new HashSet<(string source, string sink)>();
|
||||
return new HashSet<(ProtoId<SourcePortPrototype>, ProtoId<SinkPortPrototype>)>();
|
||||
|
||||
return links;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user