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,5 +1,4 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Clothing.Components;
using Content.Shared.DoAfter;
using Content.Shared.IdentityManagement;
@@ -10,7 +9,6 @@ using Content.Shared.Popups;
using Content.Shared.Strip;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
@@ -60,7 +58,7 @@ public sealed class ToggleableClothingSystem : EntitySystem
if (!args.CanAccess || !args.CanInteract || component.ClothingUid == null || component.Container == null)
return;
var text = component.VerbText ?? component.ToggleAction?.DisplayName;
var text = component.VerbText ?? (component.ActionEntity == null ? null : Name(component.ActionEntity.Value));
if (text == null)
return;
@@ -179,8 +177,11 @@ public sealed class ToggleableClothingSystem : EntitySystem
// automatically be deleted.
// remove action.
if (component.ToggleAction?.AttachedEntity != null)
_actionsSystem.RemoveAction(component.ToggleAction.AttachedEntity.Value, component.ToggleAction);
if (_actionsSystem.TryGetActionData(component.ActionEntity, out var action) &&
action.AttachedEntity != null)
{
_actionsSystem.RemoveAction(action.AttachedEntity.Value, component.ActionEntity);
}
if (component.ClothingUid != null)
QueueDel(component.ClothingUid.Value);
@@ -200,8 +201,11 @@ public sealed class ToggleableClothingSystem : EntitySystem
return;
// remove action.
if (toggleComp.ToggleAction?.AttachedEntity != null)
_actionsSystem.RemoveAction(toggleComp.ToggleAction.AttachedEntity.Value, toggleComp.ToggleAction);
if (_actionsSystem.TryGetActionData(toggleComp.ActionEntity, out var action) &&
action.AttachedEntity != null)
{
_actionsSystem.RemoveAction(action.AttachedEntity.Value, toggleComp.ActionEntity);
}
RemComp(component.AttachedUid, toggleComp);
}
@@ -259,8 +263,7 @@ public sealed class ToggleableClothingSystem : EntitySystem
if (component.ClothingUid == null || (args.SlotFlags & component.RequiredFlags) != component.RequiredFlags)
return;
if (component.ToggleAction != null)
args.Actions.Add(component.ToggleAction);
args.AddAction(ref component.ActionEntity, component.Action);
}
private void OnInit(EntityUid uid, ToggleableClothingComponent component, ComponentInit args)
@@ -280,13 +283,9 @@ public sealed class ToggleableClothingSystem : EntitySystem
return;
}
if (component.ToggleAction == null
&& _proto.TryIndex(component.ActionId, out InstantActionPrototype? act))
{
component.ToggleAction = new(act);
}
component.ActionEntity ??= Spawn(component.Action);
if (component.ClothingUid != null && component.ToggleAction != null)
if (component.ClothingUid != null && component.ActionEntity != null)
{
DebugTools.Assert(Exists(component.ClothingUid), "Toggleable clothing is missing expected entity.");
DebugTools.Assert(TryComp(component.ClothingUid, out AttachedClothingComponent? comp), "Toggleable clothing is missing an attached component");
@@ -300,10 +299,10 @@ public sealed class ToggleableClothingSystem : EntitySystem
component.Container.Insert(component.ClothingUid.Value, EntityManager, ownerTransform: xform);
}
if (component.ToggleAction != null)
if (_actionsSystem.TryGetActionData(component.ActionEntity, out var action))
{
component.ToggleAction.EntityIcon = component.ClothingUid;
_actionsSystem.Dirty(component.ToggleAction);
action.EntityIcon = component.ClothingUid;
_actionsSystem.Dirty(component.ActionEntity);
}
}
}