From fea41c539e05b210c7df5025d61d9727ffdc9400 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Mon, 1 Nov 2021 17:28:42 +0100 Subject: [PATCH] Add RaiseEvent action to CGL. Machines raise a MachineDeconstructedEvent. The latter is very useful for any special machine cleanup that needs to happen when a machine is deconstructed. The former will be useful for so many things! --- .../Construction/Completions/RaiseEvent.cs | 32 +++++++++++++++++++ .../Components/MachineFrameComponent.cs | 6 ++++ .../Recipes/Construction/Graphs/machine.yml | 4 +++ 3 files changed, 42 insertions(+) create mode 100644 Content.Server/Construction/Completions/RaiseEvent.cs diff --git a/Content.Server/Construction/Completions/RaiseEvent.cs b/Content.Server/Construction/Completions/RaiseEvent.cs new file mode 100644 index 0000000000..f4a5f962f6 --- /dev/null +++ b/Content.Server/Construction/Completions/RaiseEvent.cs @@ -0,0 +1,32 @@ +using Content.Shared.Construction; +using JetBrains.Annotations; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; + +namespace Content.Server.Construction.Completions +{ + [UsedImplicitly] + public class RaiseEvent : IGraphAction + { + [DataField("event", required:true)] + public EntityEventArgs? Event { get; } = null; + + [DataField("directed")] + public bool Directed { get; } = true; + + [DataField("broadcast")] + public bool Broadcast { get; } = true; + + public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager) + { + if (Event == null || !Directed && !Broadcast) + return; + + if(Directed) + entityManager.EventBus.RaiseLocalEvent(uid, (object)Event, false); + + if(Broadcast) + entityManager.EventBus.RaiseEvent(EventSource.Local, (object)Event); + } + } +} diff --git a/Content.Server/Construction/Components/MachineFrameComponent.cs b/Content.Server/Construction/Components/MachineFrameComponent.cs index 0f85261070..34bb43b867 100644 --- a/Content.Server/Construction/Components/MachineFrameComponent.cs +++ b/Content.Server/Construction/Components/MachineFrameComponent.cs @@ -8,6 +8,7 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.Construction.Components @@ -357,4 +358,9 @@ namespace Content.Server.Construction.Components return false; } } + + [DataDefinition] + public class MachineDeconstructedEvent : EntityEventArgs + { + } } diff --git a/Resources/Prototypes/Recipes/Construction/Graphs/machine.yml b/Resources/Prototypes/Recipes/Construction/Graphs/machine.yml index d18c4ac6dd..93a7535235 100644 --- a/Resources/Prototypes/Recipes/Construction/Graphs/machine.yml +++ b/Resources/Prototypes/Recipes/Construction/Graphs/machine.yml @@ -81,6 +81,10 @@ container: machine_board edges: - to: machineFrame + completed: + - !type:RaiseEvent + event: !type:MachineDeconstructedEvent + broadcast: false conditions: - !type:EntityAnchored - !type:WirePanel