]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
fix: EyeOffset when eyes are closed (#38534)
authorŁukasz Mędrek <lukasz@lukaszm.xyz>
Wed, 25 Jun 2025 20:22:05 +0000 (20:22 +0000)
committerGitHub <noreply@github.com>
Wed, 25 Jun 2025 20:22:05 +0000 (22:22 +0200)
* fix: EyeOffset when eyes are closed

* fix: Relay only blocked on eyes closed action

* cleanup: whitespace

* fix: missing cancel on PVS, dependencies

* remove: namespace import

* change: apply from review

* Apply suggestions from code review

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Shared/Camera/GetEyeOffsetEvent.cs
Content.Shared/Camera/GetEyePvsScaleEvent.cs
Content.Shared/Eye/Blinding/Systems/BlindableSystem.cs
Content.Shared/Movement/Systems/SharedContentEyeSystem.cs

index 0e3c00110a321a5160bdff67a9e5e2aff73221c4..fc118315ec3e7258fc410d2bcab978140ae2a052 100644 (file)
@@ -19,6 +19,13 @@ namespace Content.Shared.Camera;
 [ByRefEvent]
 public record struct GetEyeOffsetEvent(Vector2 Offset);
 
+/// <summary>
+///     Raised before the <see cref="GetEyeOffsetEvent"/> and <see cref="GetEyeOffsetRelayedEvent"/>, to check if any of the subscribed
+///     systems want to cancel offset changes.
+/// </summary>
+[ByRefEvent]
+public record struct GetEyeOffsetAttemptEvent(bool Cancelled);
+
 /// <summary>
 ///     Raised on any equipped and in-hand items that may modify the eye offset.
 ///     Pockets and suitstorage are excluded.
index 482b755db8d33ccbd4207f2bca2b2efd453466aa..4e8c48ade1731053b26cafb66b401789e73acf4c 100644 (file)
@@ -20,6 +20,13 @@ namespace Content.Shared.Camera;
 [ByRefEvent]
 public record struct GetEyePvsScaleEvent(float Scale);
 
+/// <summary>
+///     Raised before the <see cref="GetEyePvsScaleEvent"/> and <see cref="GetEyePvsScaleRelayedEvent"/>, to check if any on the subscribed
+///     systems want to cancel PVS changes.
+/// </summary>
+[ByRefEvent]
+public record struct GetEyePvsScaleAttemptEvent(bool Cancelled);
+
 /// <summary>
 ///     Raised on any equipped and in-hand items that may modify the eye offset.
 ///     Pockets and suitstorage are excluded.
index 24eed3adcf5701e20b58e59df9a4ce1cceaa7295..ae81226a4b2606dcaaae0cbf6d84740c059a55d2 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Shared.Camera;
 using Content.Shared.Eye.Blinding.Components;
 using Content.Shared.Inventory;
 using Content.Shared.Rejuvenate;
@@ -15,6 +16,8 @@ public sealed class BlindableSystem : EntitySystem
         base.Initialize();
         SubscribeLocalEvent<BlindableComponent, RejuvenateEvent>(OnRejuvenate);
         SubscribeLocalEvent<BlindableComponent, EyeDamageChangedEvent>(OnDamageChanged);
+        SubscribeLocalEvent<BlindableComponent, GetEyePvsScaleAttemptEvent>(OnGetEyePvsScaleAttemptEvent);
+        SubscribeLocalEvent<BlindableComponent, GetEyeOffsetAttemptEvent>(OnGetEyeOffsetAttemptEvent);
     }
 
     private void OnRejuvenate(Entity<BlindableComponent> ent, ref RejuvenateEvent args)
@@ -28,6 +31,18 @@ public sealed class BlindableSystem : EntitySystem
         _eyelids.UpdateEyesClosable((ent.Owner, ent.Comp));
     }
 
+    private void OnGetEyePvsScaleAttemptEvent(Entity<BlindableComponent> ent, ref GetEyePvsScaleAttemptEvent args)
+    {
+        if (ent.Comp.IsBlind)
+            args.Cancelled = true;
+    }
+
+    private void OnGetEyeOffsetAttemptEvent(Entity<BlindableComponent> ent, ref GetEyeOffsetAttemptEvent args)
+    {
+        if (ent.Comp.IsBlind)
+            args.Cancelled = true;
+    }
+
     [PublicAPI]
     public void UpdateIsBlind(Entity<BlindableComponent?> blindable)
     {
index 71bc65a79ea0ab710d452d68ee64dbc55370d495..8063948eeae31f049e886476b13c1bb1848a3a50 100644 (file)
@@ -142,6 +142,15 @@ public abstract class SharedContentEyeSystem : EntitySystem
 
     public void UpdateEyeOffset(Entity<EyeComponent> eye)
     {
+        var evAttempt = new GetEyeOffsetAttemptEvent();
+        RaiseLocalEvent(eye, ref evAttempt);
+
+        if (evAttempt.Cancelled)
+        {
+            _eye.SetOffset(eye, Vector2.Zero, eye);
+            return;
+        }
+
         var ev = new GetEyeOffsetEvent();
         RaiseLocalEvent(eye, ref ev);
 
@@ -156,6 +165,15 @@ public abstract class SharedContentEyeSystem : EntitySystem
         if (!Resolve(uid, ref contentEye) || !Resolve(uid, ref eye))
             return;
 
+        var evAttempt = new GetEyePvsScaleAttemptEvent();
+        RaiseLocalEvent(uid, ref evAttempt);
+
+        if (evAttempt.Cancelled)
+        {
+            _eye.SetPvsScale((uid, eye), 1);
+            return;
+        }
+
         var ev = new GetEyePvsScaleEvent();
         RaiseLocalEvent(uid, ref ev);