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!
This commit is contained in:
32
Content.Server/Construction/Completions/RaiseEvent.cs
Normal file
32
Content.Server/Construction/Completions/RaiseEvent.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ using Robust.Server.GameObjects;
|
|||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
namespace Content.Server.Construction.Components
|
namespace Content.Server.Construction.Components
|
||||||
@@ -357,4 +358,9 @@ namespace Content.Server.Construction.Components
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DataDefinition]
|
||||||
|
public class MachineDeconstructedEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,10 @@
|
|||||||
container: machine_board
|
container: machine_board
|
||||||
edges:
|
edges:
|
||||||
- to: machineFrame
|
- to: machineFrame
|
||||||
|
completed:
|
||||||
|
- !type:RaiseEvent
|
||||||
|
event: !type:MachineDeconstructedEvent
|
||||||
|
broadcast: false
|
||||||
conditions:
|
conditions:
|
||||||
- !type:EntityAnchored
|
- !type:EntityAnchored
|
||||||
- !type:WirePanel
|
- !type:WirePanel
|
||||||
|
|||||||
Reference in New Issue
Block a user