Skip to content

Commit

Permalink
Make pointlight setting use an attempt event
Browse files Browse the repository at this point in the history
Makes it easy for content to add functionality if multiple things try to set it without having to funnel every piece of code through a content system.
  • Loading branch information
metalgearsloth committed Aug 22, 2024
1 parent f03c006 commit 3d3fa60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public float AnimatedRadius
public string? MaskPath;
}

/// <summary>
/// Raised directed on an entity when attempting to enable / disable it.
/// </summary>
[ByRefEvent]
public record struct AttemptPointLightToggleEvent(bool Enabled)
{
public bool Cancelled;
}

public sealed class PointLightToggleEvent : EntityEventArgs
{
public bool Enabled;
Expand Down
6 changes: 6 additions & 0 deletions Robust.Shared/GameObjects/Systems/SharedPointLightSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public virtual void SetEnabled(EntityUid uid, bool enabled, SharedPointLightComp
if (!ResolveLight(uid, ref comp) || enabled == comp.Enabled)
return;

var attempt = new AttemptPointLightToggleEvent(enabled);
RaiseLocalEvent(uid, ref attempt);

if (attempt.Cancelled)
return;

comp.Enabled = enabled;
RaiseLocalEvent(uid, new PointLightToggleEvent(comp.Enabled));
if (!Resolve(uid, ref meta))
Expand Down

0 comments on commit 3d3fa60

Please sign in to comment.