fix: EyeOffset when eyes are closed (#38534)

* 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>
This commit is contained in:
Łukasz Mędrek
2025-06-25 20:22:05 +00:00
committed by GitHub
parent 433893679e
commit 1ba0191808
4 changed files with 47 additions and 0 deletions

View 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.

View 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.

View 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)
{

View 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);