]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
fix: #25102 cryo pod now uses health-analyzer system to update body state in UI ...
authorFildrance <fildrance@gmail.com>
Wed, 21 Feb 2024 14:47:23 +0000 (17:47 +0300)
committerGitHub <noreply@github.com>
Wed, 21 Feb 2024 14:47:23 +0000 (17:47 +0300)
* fix: cryo pod now uses health-analyzer system to update body state in UI

* refactor: use EntityEventRefHandler instead ComponentEventRefHandler in CryoPodComponent subscribe on EntRemovedFromContainerMessage

---------

Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Content.Server/Medical/Components/HealthAnalyzerComponent.cs
Content.Server/Medical/CryoPodSystem.cs
Resources/Prototypes/Entities/Structures/Machines/Medical/cryo_pod.yml

index 0002f275c5b05685fb61e8648422e253819c0b5d..a7fed0cae364c537e4caf5b7761216fc3d13e869 100644 (file)
@@ -7,7 +7,7 @@ namespace Content.Server.Medical.Components;
 /// After scanning, retrieves the target Uid to use with its related UI.
 /// </summary>
 [RegisterComponent]
-[Access(typeof(HealthAnalyzerSystem))]
+[Access(typeof(HealthAnalyzerSystem), typeof(CryoPodSystem))]
 public sealed partial class HealthAnalyzerComponent : Component
 {
     /// <summary>
index 25a47933a84c937f3c2a5b1831ea4d3599f8df98..97ae72bd1100583f0e2291cb52a8242c175ef0ab 100644 (file)
@@ -30,6 +30,7 @@ using Content.Shared.Medical.Cryogenics;
 using Content.Shared.MedicalScanner;
 using Content.Shared.Verbs;
 using Robust.Server.GameObjects;
+using Robust.Shared.Containers;
 using Robust.Shared.Timing;
 using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
@@ -71,6 +72,7 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
         SubscribeLocalEvent<CryoPodComponent, GasAnalyzerScanEvent>(OnGasAnalyzed);
         SubscribeLocalEvent<CryoPodComponent, ActivatableUIOpenAttemptEvent>(OnActivateUIAttempt);
         SubscribeLocalEvent<CryoPodComponent, AfterActivatableUIOpenEvent>(OnActivateUI);
+        SubscribeLocalEvent<CryoPodComponent, EntRemovedFromContainerMessage>(OnEjected);
     }
 
     public override void Update(float frameTime)
@@ -187,6 +189,11 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
         TryComp<TemperatureComponent>(entity.Comp.BodyContainer.ContainedEntity, out var temp);
         TryComp<BloodstreamComponent>(entity.Comp.BodyContainer.ContainedEntity, out var bloodstream);
 
+        if (TryComp<HealthAnalyzerComponent>(entity, out var healthAnalyzer))
+        {
+            healthAnalyzer.ScannedEntity = entity.Comp.BodyContainer.ContainedEntity;
+        }
+
         _userInterfaceSystem.TrySendUiMessage(
             entity.Owner,
             HealthAnalyzerUiKey.Key,
@@ -282,5 +289,16 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
         args.GasMixtures = gasMixDict;
     }
 
+    private void OnEjected(Entity<CryoPodComponent> cryoPod, ref EntRemovedFromContainerMessage args)
+    {
+        if (TryComp<HealthAnalyzerComponent>(cryoPod.Owner, out var healthAnalyzer))
+        {
+            healthAnalyzer.ScannedEntity = null;
+        }
+
+        // if body is ejected - no need to display health-analyzer
+        _uiSystem.TryCloseAll(cryoPod.Owner, HealthAnalyzerUiKey.Key);
+    }
+
     #endregion
 }
index f150a3f63b0627dca1bff8ef4f63d586fcec0e85..6ac969171e037539af5cd32060a1eebfee5d6e61 100644 (file)
@@ -85,6 +85,8 @@
         whitelist:
           components:
             - FitsInDispenser
+  - type: HealthAnalyzer
+    scanDelay: 0
   - type: UserInterface
     interfaces:
       - key: enum.HealthAnalyzerUiKey.Key