Fix NetEntity DataField in AnalysisConsoleComponent (#39984)
* fix analysis console * fix test * totally not a web edit
This commit is contained in:
@@ -214,6 +214,17 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
|
|||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the entities linked to a specific source port.
|
||||||
|
/// </summary>
|
||||||
|
public HashSet<EntityUid> GetLinkedSinks(Entity<DeviceLinkSourceComponent?> source, ProtoId<SourcePortPrototype> port)
|
||||||
|
{
|
||||||
|
if (!Resolve(source, ref source.Comp) || !source.Comp.Outputs.TryGetValue(port, out var linked))
|
||||||
|
return new HashSet<EntityUid>(); // not a source or not linked
|
||||||
|
|
||||||
|
return new HashSet<EntityUid>(linked); // clone to prevent modifying the original
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the default links for the given list of source port prototypes
|
/// Returns the default links for the given list of source port prototypes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public sealed partial class AnalysisConsoleComponent : Component
|
|||||||
/// Can be null if not linked.
|
/// Can be null if not linked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, AutoNetworkedField]
|
[DataField, AutoNetworkedField]
|
||||||
public NetEntity? AnalyzerEntity;
|
public EntityUid? AnalyzerEntity;
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
public SoundSpecifier? ScanFinishedSound = new SoundPathSpecifier("/Audio/Machines/scan_finish.ogg");
|
public SoundSpecifier? ScanFinishedSound = new SoundPathSpecifier("/Audio/Machines/scan_finish.ogg");
|
||||||
@@ -35,7 +35,7 @@ public sealed partial class AnalysisConsoleComponent : Component
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The machine linking port for the analyzer
|
/// The machine linking port for linking the console with the analyzer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public ProtoId<SourcePortPrototype> LinkingPort = "ArtifactAnalyzerSender";
|
public ProtoId<SourcePortPrototype> LinkingPort = "ArtifactAnalyzerSender";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Robust.Shared.Audio;
|
using Content.Shared.DeviceLinking;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Shared.Xenoarchaeology.Equipment.Components;
|
namespace Content.Shared.Xenoarchaeology.Equipment.Components;
|
||||||
|
|
||||||
@@ -35,4 +36,10 @@ public sealed partial class ArtifactAnalyzerComponent : Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool ReadyToPrint = false;
|
public bool ReadyToPrint = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The machine linking port for linking the analyzer with the console.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public ProtoId<SinkPortPrototype> LinkingPort = "ArtifactAnalyzerReceiver";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Content.Shared.Xenoarchaeology.Equipment;
|
|||||||
public abstract class SharedArtifactAnalyzerSystem : EntitySystem
|
public abstract class SharedArtifactAnalyzerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly SharedPowerReceiverSystem _powerReceiver = default!;
|
[Dependency] private readonly SharedPowerReceiverSystem _powerReceiver = default!;
|
||||||
|
[Dependency] private readonly SharedDeviceLinkSystem _deviceLink = default!;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -23,10 +24,14 @@ public abstract class SharedArtifactAnalyzerSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<ArtifactAnalyzerComponent, ItemPlacedEvent>(OnItemPlaced);
|
SubscribeLocalEvent<ArtifactAnalyzerComponent, ItemPlacedEvent>(OnItemPlaced);
|
||||||
SubscribeLocalEvent<ArtifactAnalyzerComponent, ItemRemovedEvent>(OnItemRemoved);
|
SubscribeLocalEvent<ArtifactAnalyzerComponent, ItemRemovedEvent>(OnItemRemoved);
|
||||||
SubscribeLocalEvent<ArtifactAnalyzerComponent, MapInitEvent>(OnMapInit);
|
SubscribeLocalEvent<ArtifactAnalyzerComponent, NewLinkEvent>(OnNewLinkAnalyzer);
|
||||||
|
SubscribeLocalEvent<ArtifactAnalyzerComponent, LinkAttemptEvent>(OnLinkAttemptAnalyzer);
|
||||||
|
SubscribeLocalEvent<ArtifactAnalyzerComponent, PortDisconnectedEvent>(OnPortDisconnectedAnalyzer);
|
||||||
|
|
||||||
SubscribeLocalEvent<AnalysisConsoleComponent, NewLinkEvent>(OnNewLink);
|
SubscribeLocalEvent<AnalysisConsoleComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<AnalysisConsoleComponent, PortDisconnectedEvent>(OnPortDisconnected);
|
SubscribeLocalEvent<AnalysisConsoleComponent, NewLinkEvent>(OnNewLinkConsole);
|
||||||
|
SubscribeLocalEvent<AnalysisConsoleComponent, LinkAttemptEvent>(OnLinkAttemptConsole);
|
||||||
|
SubscribeLocalEvent<AnalysisConsoleComponent, PortDisconnectedEvent>(OnPortDisconnectedConsole);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnItemPlaced(Entity<ArtifactAnalyzerComponent> ent, ref ItemPlacedEvent args)
|
private void OnItemPlaced(Entity<ArtifactAnalyzerComponent> ent, ref ItemPlacedEvent args)
|
||||||
@@ -44,52 +49,74 @@ public abstract class SharedArtifactAnalyzerSystem : EntitySystem
|
|||||||
Dirty(ent);
|
Dirty(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMapInit(Entity<ArtifactAnalyzerComponent> ent, ref MapInitEvent args)
|
private void OnMapInit(Entity<AnalysisConsoleComponent> ent, ref MapInitEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<DeviceLinkSinkComponent>(ent, out var sink))
|
if (!TryComp<DeviceLinkSourceComponent>(ent, out var source))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var source in sink.LinkedSources)
|
var linkedEntities = _deviceLink.GetLinkedSinks((ent.Owner, source), ent.Comp.LinkingPort);
|
||||||
|
|
||||||
|
foreach (var sink in linkedEntities)
|
||||||
{
|
{
|
||||||
if (!TryComp<AnalysisConsoleComponent>(source, out var analysis))
|
if (!TryComp<ArtifactAnalyzerComponent>(sink, out var analyzer))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
analysis.AnalyzerEntity = GetNetEntity(ent);
|
ent.Comp.AnalyzerEntity = sink;
|
||||||
ent.Comp.Console = source;
|
analyzer.Console = ent.Owner;
|
||||||
Dirty(source, analysis);
|
|
||||||
Dirty(ent);
|
Dirty(ent);
|
||||||
|
Dirty(sink, analyzer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnNewLink(Entity<AnalysisConsoleComponent> ent, ref NewLinkEvent args)
|
private void OnNewLinkConsole(Entity<AnalysisConsoleComponent> ent, ref NewLinkEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<ArtifactAnalyzerComponent>(args.Sink, out var analyzer))
|
if (args.SourcePort != ent.Comp.LinkingPort || !HasComp<ArtifactAnalyzerComponent>(args.Sink))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ent.Comp.AnalyzerEntity = GetNetEntity(args.Sink);
|
ent.Comp.AnalyzerEntity = args.Sink;
|
||||||
analyzer.Console = ent;
|
|
||||||
Dirty(args.Sink, analyzer);
|
|
||||||
Dirty(ent);
|
Dirty(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPortDisconnected(Entity<AnalysisConsoleComponent> ent, ref PortDisconnectedEvent args)
|
private void OnNewLinkAnalyzer(Entity<ArtifactAnalyzerComponent> ent, ref NewLinkEvent args)
|
||||||
{
|
{
|
||||||
var analyzerNetEntity = ent.Comp.AnalyzerEntity;
|
if (args.SinkPort != ent.Comp.LinkingPort || !HasComp<AnalysisConsoleComponent>(args.Source))
|
||||||
if (args.Port != ent.Comp.LinkingPort || analyzerNetEntity == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var analyzerEntityUid = GetEntity(analyzerNetEntity);
|
ent.Comp.Console = args.Source;
|
||||||
if (TryComp<ArtifactAnalyzerComponent>(analyzerEntityUid, out var analyzer))
|
Dirty(ent);
|
||||||
{
|
}
|
||||||
analyzer.Console = null;
|
|
||||||
Dirty(analyzerEntityUid.Value, analyzer);
|
private void OnLinkAttemptConsole(Entity<AnalysisConsoleComponent> ent, ref LinkAttemptEvent args)
|
||||||
}
|
{
|
||||||
|
if (ent.Comp.AnalyzerEntity != null)
|
||||||
|
args.Cancel(); // can only link to one device at a time
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLinkAttemptAnalyzer(Entity<ArtifactAnalyzerComponent> ent, ref LinkAttemptEvent args)
|
||||||
|
{
|
||||||
|
if (ent.Comp.Console != null)
|
||||||
|
args.Cancel(); // can only link to one device at a time
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPortDisconnectedConsole(Entity<AnalysisConsoleComponent> ent, ref PortDisconnectedEvent args)
|
||||||
|
{
|
||||||
|
if (args.Port != ent.Comp.LinkingPort || ent.Comp.AnalyzerEntity == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ent.Comp.AnalyzerEntity = null;
|
ent.Comp.AnalyzerEntity = null;
|
||||||
Dirty(ent);
|
Dirty(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPortDisconnectedAnalyzer(Entity<ArtifactAnalyzerComponent> ent, ref PortDisconnectedEvent args)
|
||||||
|
{
|
||||||
|
if (args.Port != ent.Comp.LinkingPort || ent.Comp.Console == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ent.Comp.Console = null;
|
||||||
|
Dirty(ent);
|
||||||
|
}
|
||||||
|
|
||||||
public bool TryGetAnalyzer(Entity<AnalysisConsoleComponent> ent, [NotNullWhen(true)] out Entity<ArtifactAnalyzerComponent>? analyzer)
|
public bool TryGetAnalyzer(Entity<AnalysisConsoleComponent> ent, [NotNullWhen(true)] out Entity<ArtifactAnalyzerComponent>? analyzer)
|
||||||
{
|
{
|
||||||
analyzer = null;
|
analyzer = null;
|
||||||
@@ -98,14 +125,13 @@ public abstract class SharedArtifactAnalyzerSystem : EntitySystem
|
|||||||
if (!_powerReceiver.IsPowered(consoleEnt))
|
if (!_powerReceiver.IsPowered(consoleEnt))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var analyzerUid = GetEntity(ent.Comp.AnalyzerEntity);
|
if (!TryComp<ArtifactAnalyzerComponent>(ent.Comp.AnalyzerEntity, out var analyzerComp))
|
||||||
if (!TryComp<ArtifactAnalyzerComponent>(analyzerUid, out var analyzerComp))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!_powerReceiver.IsPowered(analyzerUid.Value))
|
if (!_powerReceiver.IsPowered(ent.Comp.AnalyzerEntity.Value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
analyzer = (analyzerUid.Value, analyzerComp);
|
analyzer = (ent.Comp.AnalyzerEntity.Value, analyzerComp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user