Refactor actions to be entities with components (#19900)

This commit is contained in:
DrSmugleaf
2023-09-08 18:16:05 -07:00
committed by GitHub
parent e18f731b91
commit c71f97e3a2
210 changed files with 10693 additions and 11714 deletions

View File

@@ -1,57 +1,32 @@
using Content.Shared.Actions.ActionTypes;
using Robust.Shared.Reflection;
using Robust.Shared.Serialization;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.UserInterface;
[RegisterComponent]
public sealed partial class IntrinsicUIComponent : Component, ISerializationHooks
public sealed partial class IntrinsicUIComponent : Component
{
/// <summary>
/// List of UIs and their actions that this entity has.
/// </summary>
[DataField("uis", required: true)]
public List<IntrinsicUIEntry> UIs = new();
void ISerializationHooks.AfterDeserialization()
{
for (var i = 0; i < UIs.Count; i++)
{
var ui = UIs[i];
ui.AfterDeserialization();
UIs[i] = ui;
}
}
[DataField("uis", required: true)] public List<IntrinsicUIEntry> UIs = new();
}
[DataDefinition]
public partial struct IntrinsicUIEntry
public partial class IntrinsicUIEntry
{
[ViewVariables] public Enum? Key { get; private set; } = null;
/// <summary>
/// The BUI key that this intrinsic UI should open.
/// </summary>
[DataField("key", required: true)]
private string _keyRaw = default!;
public Enum? Key { get; private set; }
[DataField("toggleAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>), required: true)]
public string? ToggleAction;
/// <summary>
/// The action used for this BUI.
/// </summary>
[DataField("toggleAction", required: true)]
public InstantAction ToggleAction = new();
public void AfterDeserialization()
{
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
if (reflectionManager.TryParseEnumReference(_keyRaw, out var key))
Key = key;
if (ToggleAction.Event is ToggleIntrinsicUIEvent ev)
{
ev.Key = Key;
}
}
public IntrinsicUIEntry() {}
[DataField("toggleActionEntity")]
public EntityUid? ToggleActionEntity = new();
}