From bed556051b45827d8cebc49edaf8cb2f2ee67a21 Mon Sep 17 00:00:00 2001
From: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Date: Sat, 11 Oct 2025 02:22:31 +0200
Subject: [PATCH] Fix NetEntity DataField in AnalysisConsoleComponent (#39984)
* fix analysis console
* fix test
* totally not a web edit
---
.../DeviceLinking/SharedDeviceLinkSystem.cs | 11 +++
.../Components/AnalysisConsoleComponent.cs | 4 +-
.../Components/ArtifactAnalyzerComponent.cs | 9 +-
.../Equipment/SharedArtifactAnalyzerSystem.cs | 82 ++++++++++++-------
4 files changed, 75 insertions(+), 31 deletions(-)
diff --git a/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs b/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs
index 5d51bbc3e8..74bbc259c6 100644
--- a/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs
+++ b/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs
@@ -214,6 +214,17 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
return links;
}
+ ///
+ /// Gets the entities linked to a specific source port.
+ ///
+ public HashSet GetLinkedSinks(Entity source, ProtoId port)
+ {
+ if (!Resolve(source, ref source.Comp) || !source.Comp.Outputs.TryGetValue(port, out var linked))
+ return new HashSet(); // not a source or not linked
+
+ return new HashSet(linked); // clone to prevent modifying the original
+ }
+
///
/// Returns the default links for the given list of source port prototypes
///
diff --git a/Content.Shared/Xenoarchaeology/Equipment/Components/AnalysisConsoleComponent.cs b/Content.Shared/Xenoarchaeology/Equipment/Components/AnalysisConsoleComponent.cs
index 3247e3365a..3f59628714 100644
--- a/Content.Shared/Xenoarchaeology/Equipment/Components/AnalysisConsoleComponent.cs
+++ b/Content.Shared/Xenoarchaeology/Equipment/Components/AnalysisConsoleComponent.cs
@@ -17,7 +17,7 @@ public sealed partial class AnalysisConsoleComponent : Component
/// Can be null if not linked.
///
[DataField, AutoNetworkedField]
- public NetEntity? AnalyzerEntity;
+ public EntityUid? AnalyzerEntity;
[DataField]
public SoundSpecifier? ScanFinishedSound = new SoundPathSpecifier("/Audio/Machines/scan_finish.ogg");
@@ -35,7 +35,7 @@ public sealed partial class AnalysisConsoleComponent : Component
};
///
- /// The machine linking port for the analyzer
+ /// The machine linking port for linking the console with the analyzer.
///
[DataField]
public ProtoId LinkingPort = "ArtifactAnalyzerSender";
diff --git a/Content.Shared/Xenoarchaeology/Equipment/Components/ArtifactAnalyzerComponent.cs b/Content.Shared/Xenoarchaeology/Equipment/Components/ArtifactAnalyzerComponent.cs
index 05d17bb123..9581285efb 100644
--- a/Content.Shared/Xenoarchaeology/Equipment/Components/ArtifactAnalyzerComponent.cs
+++ b/Content.Shared/Xenoarchaeology/Equipment/Components/ArtifactAnalyzerComponent.cs
@@ -1,5 +1,6 @@
-using Robust.Shared.Audio;
+using Content.Shared.DeviceLinking;
using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
namespace Content.Shared.Xenoarchaeology.Equipment.Components;
@@ -35,4 +36,10 @@ public sealed partial class ArtifactAnalyzerComponent : Component
///
[ViewVariables(VVAccess.ReadWrite)]
public bool ReadyToPrint = false;
+
+ ///
+ /// The machine linking port for linking the analyzer with the console.
+ ///
+ [DataField]
+ public ProtoId LinkingPort = "ArtifactAnalyzerReceiver";
}
diff --git a/Content.Shared/Xenoarchaeology/Equipment/SharedArtifactAnalyzerSystem.cs b/Content.Shared/Xenoarchaeology/Equipment/SharedArtifactAnalyzerSystem.cs
index e47e964225..086b402bb2 100644
--- a/Content.Shared/Xenoarchaeology/Equipment/SharedArtifactAnalyzerSystem.cs
+++ b/Content.Shared/Xenoarchaeology/Equipment/SharedArtifactAnalyzerSystem.cs
@@ -15,6 +15,7 @@ namespace Content.Shared.Xenoarchaeology.Equipment;
public abstract class SharedArtifactAnalyzerSystem : EntitySystem
{
[Dependency] private readonly SharedPowerReceiverSystem _powerReceiver = default!;
+ [Dependency] private readonly SharedDeviceLinkSystem _deviceLink = default!;
///
public override void Initialize()
@@ -23,10 +24,14 @@ public abstract class SharedArtifactAnalyzerSystem : EntitySystem
SubscribeLocalEvent(OnItemPlaced);
SubscribeLocalEvent(OnItemRemoved);
- SubscribeLocalEvent(OnMapInit);
+ SubscribeLocalEvent(OnNewLinkAnalyzer);
+ SubscribeLocalEvent(OnLinkAttemptAnalyzer);
+ SubscribeLocalEvent(OnPortDisconnectedAnalyzer);
- SubscribeLocalEvent(OnNewLink);
- SubscribeLocalEvent(OnPortDisconnected);
+ SubscribeLocalEvent(OnMapInit);
+ SubscribeLocalEvent(OnNewLinkConsole);
+ SubscribeLocalEvent(OnLinkAttemptConsole);
+ SubscribeLocalEvent(OnPortDisconnectedConsole);
}
private void OnItemPlaced(Entity ent, ref ItemPlacedEvent args)
@@ -44,52 +49,74 @@ public abstract class SharedArtifactAnalyzerSystem : EntitySystem
Dirty(ent);
}
- private void OnMapInit(Entity ent, ref MapInitEvent args)
+ private void OnMapInit(Entity ent, ref MapInitEvent args)
{
- if (!TryComp(ent, out var sink))
+ if (!TryComp(ent, out var source))
return;
- foreach (var source in sink.LinkedSources)
+ var linkedEntities = _deviceLink.GetLinkedSinks((ent.Owner, source), ent.Comp.LinkingPort);
+
+ foreach (var sink in linkedEntities)
{
- if (!TryComp(source, out var analysis))
+ if (!TryComp(sink, out var analyzer))
continue;
- analysis.AnalyzerEntity = GetNetEntity(ent);
- ent.Comp.Console = source;
- Dirty(source, analysis);
+ ent.Comp.AnalyzerEntity = sink;
+ analyzer.Console = ent.Owner;
Dirty(ent);
+ Dirty(sink, analyzer);
break;
}
}
- private void OnNewLink(Entity ent, ref NewLinkEvent args)
+ private void OnNewLinkConsole(Entity ent, ref NewLinkEvent args)
{
- if (!TryComp(args.Sink, out var analyzer))
+ if (args.SourcePort != ent.Comp.LinkingPort || !HasComp(args.Sink))
return;
- ent.Comp.AnalyzerEntity = GetNetEntity(args.Sink);
- analyzer.Console = ent;
- Dirty(args.Sink, analyzer);
+ ent.Comp.AnalyzerEntity = args.Sink;
Dirty(ent);
}
- private void OnPortDisconnected(Entity ent, ref PortDisconnectedEvent args)
+ private void OnNewLinkAnalyzer(Entity ent, ref NewLinkEvent args)
{
- var analyzerNetEntity = ent.Comp.AnalyzerEntity;
- if (args.Port != ent.Comp.LinkingPort || analyzerNetEntity == null)
+ if (args.SinkPort != ent.Comp.LinkingPort || !HasComp(args.Source))
return;
- var analyzerEntityUid = GetEntity(analyzerNetEntity);
- if (TryComp(analyzerEntityUid, out var analyzer))
- {
- analyzer.Console = null;
- Dirty(analyzerEntityUid.Value, analyzer);
- }
+ ent.Comp.Console = args.Source;
+ Dirty(ent);
+ }
+
+ private void OnLinkAttemptConsole(Entity ent, ref LinkAttemptEvent args)
+ {
+ if (ent.Comp.AnalyzerEntity != null)
+ args.Cancel(); // can only link to one device at a time
+ }
+
+ private void OnLinkAttemptAnalyzer(Entity ent, ref LinkAttemptEvent args)
+ {
+ if (ent.Comp.Console != null)
+ args.Cancel(); // can only link to one device at a time
+ }
+
+ private void OnPortDisconnectedConsole(Entity ent, ref PortDisconnectedEvent args)
+ {
+ if (args.Port != ent.Comp.LinkingPort || ent.Comp.AnalyzerEntity == null)
+ return;
ent.Comp.AnalyzerEntity = null;
Dirty(ent);
}
+ private void OnPortDisconnectedAnalyzer(Entity 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 ent, [NotNullWhen(true)] out Entity? analyzer)
{
analyzer = null;
@@ -98,14 +125,13 @@ public abstract class SharedArtifactAnalyzerSystem : EntitySystem
if (!_powerReceiver.IsPowered(consoleEnt))
return false;
- var analyzerUid = GetEntity(ent.Comp.AnalyzerEntity);
- if (!TryComp(analyzerUid, out var analyzerComp))
+ if (!TryComp(ent.Comp.AnalyzerEntity, out var analyzerComp))
return false;
- if (!_powerReceiver.IsPowered(analyzerUid.Value))
+ if (!_powerReceiver.IsPowered(ent.Comp.AnalyzerEntity.Value))
return false;
- analyzer = (analyzerUid.Value, analyzerComp);
+ analyzer = (ent.Comp.AnalyzerEntity.Value, analyzerComp);
return true;
}