Refactor actions to be entities with components (#19900)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.PAI
|
||||
{
|
||||
@@ -23,8 +24,12 @@ namespace Content.Shared.PAI
|
||||
[DataField("lastUSer"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public EntityUid? LastUser;
|
||||
|
||||
[DataField("midiAction", required: true, serverOnly: true)] // server only, as it uses a server-BUI event !type
|
||||
public InstantAction? MidiAction;
|
||||
[DataField("midiActionId", serverOnly: true,
|
||||
customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? MidiActionId = "ActionPAIPlayMidi";
|
||||
|
||||
[DataField("midiAction", serverOnly: true)] // server only, as it uses a server-BUI event !type
|
||||
public EntityUid? MidiAction;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement.Events;
|
||||
|
||||
namespace Content.Shared.PAI
|
||||
{
|
||||
@@ -24,20 +19,18 @@ namespace Content.Shared.PAI
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PAIComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<PAIComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<PAIComponent, ComponentShutdown>(OnShutdown);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, PAIComponent component, ComponentStartup args)
|
||||
private void OnMapInit(EntityUid uid, PAIComponent component, MapInitEvent args)
|
||||
{
|
||||
if (component.MidiAction != null)
|
||||
_actionsSystem.AddAction(uid, component.MidiAction, null);
|
||||
_actionsSystem.AddAction(uid, ref component.MidiAction, component.MidiActionId);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, PAIComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (component.MidiAction != null)
|
||||
_actionsSystem.RemoveAction(uid, component.MidiAction);
|
||||
_actionsSystem.RemoveAction(uid, component.MidiAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user