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,6 +1,5 @@
using System.Linq;
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.CombatMode;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
@@ -25,6 +24,8 @@ public sealed class ActionsAddedTest
var sEntMan = server.ResolveDependency<IEntityManager>();
var cEntMan = client.ResolveDependency<IEntityManager>();
var session = server.ResolveDependency<IPlayerManager>().ServerSessions.Single();
var sActionSystem = server.System<SharedActionsSystem>();
var cActionSystem = client.System<SharedActionsSystem>();
// Dummy ticker is disabled - client should be in control of a normal mob.
Assert.NotNull(session.AttachedEntity);
@@ -43,21 +44,24 @@ public sealed class ActionsAddedTest
// This action should have a non-null event both on the server & client.
var evType = typeof(ToggleCombatActionEvent);
var sActions = sComp!.Actions.Where(
x => x is InstantAction act && act.Event?.GetType() == evType).ToArray();
var cActions = cComp!.Actions.Where(
x => x is InstantAction act && act.Event?.GetType() == evType).ToArray();
var sActions = sActionSystem.GetActions(ent).Where(
x => x.Comp is InstantActionComponent act && act.Event?.GetType() == evType).ToArray();
var cActions = cActionSystem.GetActions(ent).Where(
x => x.Comp is InstantActionComponent act && act.Event?.GetType() == evType).ToArray();
Assert.That(sActions.Length, Is.EqualTo(1));
Assert.That(cActions.Length, Is.EqualTo(1));
var sAct = (InstantAction) sActions[0];
var cAct = (InstantAction) cActions[0];
var sAct = sActions[0].Comp;
var cAct = cActions[0].Comp;
Assert.NotNull(sAct);
Assert.NotNull(cAct);
// Finally, these two actions are not the same object
// required, because integration tests do not respect the [NonSerialized] attribute and will simply events by reference.
Assert.That(ReferenceEquals(sAct, cAct), Is.False);
Assert.That(ReferenceEquals(sAct.Event, cAct.Event), Is.False);
Assert.That(ReferenceEquals(sAct.BaseEvent, cAct.BaseEvent), Is.False);
await pair.CleanReturnAsync();
}