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:
@@ -19,6 +19,13 @@ namespace Content.Shared.Camera;
|
|||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public record struct GetEyeOffsetEvent(Vector2 Offset);
|
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>
|
/// <summary>
|
||||||
/// Raised on any equipped and in-hand items that may modify the eye offset.
|
/// Raised on any equipped and in-hand items that may modify the eye offset.
|
||||||
/// Pockets and suitstorage are excluded.
|
/// Pockets and suitstorage are excluded.
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ namespace Content.Shared.Camera;
|
|||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public record struct GetEyePvsScaleEvent(float Scale);
|
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>
|
/// <summary>
|
||||||
/// Raised on any equipped and in-hand items that may modify the eye offset.
|
/// Raised on any equipped and in-hand items that may modify the eye offset.
|
||||||
/// Pockets and suitstorage are excluded.
|
/// Pockets and suitstorage are excluded.
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Content.Shared.Camera;
|
||||||
using Content.Shared.Eye.Blinding.Components;
|
using Content.Shared.Eye.Blinding.Components;
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Rejuvenate;
|
using Content.Shared.Rejuvenate;
|
||||||
@@ -15,6 +16,8 @@ public sealed class BlindableSystem : EntitySystem
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<BlindableComponent, RejuvenateEvent>(OnRejuvenate);
|
SubscribeLocalEvent<BlindableComponent, RejuvenateEvent>(OnRejuvenate);
|
||||||
SubscribeLocalEvent<BlindableComponent, EyeDamageChangedEvent>(OnDamageChanged);
|
SubscribeLocalEvent<BlindableComponent, EyeDamageChangedEvent>(OnDamageChanged);
|
||||||
|
SubscribeLocalEvent<BlindableComponent, GetEyePvsScaleAttemptEvent>(OnGetEyePvsScaleAttemptEvent);
|
||||||
|
SubscribeLocalEvent<BlindableComponent, GetEyeOffsetAttemptEvent>(OnGetEyeOffsetAttemptEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRejuvenate(Entity<BlindableComponent> ent, ref RejuvenateEvent args)
|
private void OnRejuvenate(Entity<BlindableComponent> ent, ref RejuvenateEvent args)
|
||||||
@@ -28,6 +31,18 @@ public sealed class BlindableSystem : EntitySystem
|
|||||||
_eyelids.UpdateEyesClosable((ent.Owner, ent.Comp));
|
_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]
|
[PublicAPI]
|
||||||
public void UpdateIsBlind(Entity<BlindableComponent?> blindable)
|
public void UpdateIsBlind(Entity<BlindableComponent?> blindable)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -142,6 +142,15 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
|
|
||||||
public void UpdateEyeOffset(Entity<EyeComponent> eye)
|
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();
|
var ev = new GetEyeOffsetEvent();
|
||||||
RaiseLocalEvent(eye, ref ev);
|
RaiseLocalEvent(eye, ref ev);
|
||||||
|
|
||||||
@@ -156,6 +165,15 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
if (!Resolve(uid, ref contentEye) || !Resolve(uid, ref eye))
|
if (!Resolve(uid, ref contentEye) || !Resolve(uid, ref eye))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var evAttempt = new GetEyePvsScaleAttemptEvent();
|
||||||
|
RaiseLocalEvent(uid, ref evAttempt);
|
||||||
|
|
||||||
|
if (evAttempt.Cancelled)
|
||||||
|
{
|
||||||
|
_eye.SetPvsScale((uid, eye), 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var ev = new GetEyePvsScaleEvent();
|
var ev = new GetEyePvsScaleEvent();
|
||||||
RaiseLocalEvent(uid, ref ev);
|
RaiseLocalEvent(uid, ref ev);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user