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

@@ -5,6 +5,7 @@ using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.UserInterface;
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
using Robust.Server.Player;

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();
}

View File

@@ -1,6 +1,6 @@
using Content.Server.Actions;
using Content.Shared.Actions;
using JetBrains.Annotations;
using Content.Shared.UserInterface;
using Robust.Server.GameObjects;
namespace Content.Server.UserInterface;
@@ -28,7 +28,7 @@ public sealed class IntrinsicUISystem : EntitySystem
foreach (var entry in component.UIs)
{
_actionsSystem.AddAction(uid, entry.ToggleAction, null, actions);
_actionsSystem.AddAction(uid, ref entry.ToggleActionEntity, entry.ToggleAction, null, actions);
}
}
@@ -68,13 +68,6 @@ public sealed class IntrinsicUISystem : EntitySystem
}
}
[UsedImplicitly]
public sealed partial class ToggleIntrinsicUIEvent : InstantActionEvent
{
[ViewVariables]
public Enum? Key { get; set; }
}
// Competing with ActivatableUI for horrible event names.
public sealed class IntrinsicUIOpenAttemptEvent : CancellableEntityEventArgs
{

View File

@@ -1,23 +0,0 @@
using Content.Shared.Actions;
using Robust.Shared.Reflection;
using Robust.Shared.Serialization;
namespace Content.Server.UserInterface;
public sealed partial class OpenUiActionEvent : InstantActionEvent, ISerializationHooks
{
[ViewVariables]
public Enum? Key { get; private set; }
[DataField("key", required: true)]
private string _keyRaw = default!;
void ISerializationHooks.AfterDeserialization()
{
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
if (reflectionManager.TryParseEnumReference(_keyRaw, out var key))
Key = key;
else
Logger.Error($"Invalid UI key ({_keyRaw}) in open-UI action");
}
}