Inline TryGetComponent completely, for real

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 14:17:01 +01:00
parent 2ff4ec65d5
commit 69b270017b
425 changed files with 1143 additions and 995 deletions

View File

@@ -48,8 +48,8 @@ namespace Content.IntegrationTests.Tests.Body
var entityManager = IoCManager.Resolve<IEntityManager>();
var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy", new MapCoordinates(Vector2.Zero, mapId));
Assert.That(human.TryGetComponent(out SharedBodyComponent body));
Assert.That(human.TryGetComponent(out appearance));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out SharedBodyComponent body));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out appearance));
Assert.That(!appearance.TryGetData(RotationVisuals.RotationState, out RotationState _));

View File

@@ -66,11 +66,11 @@ namespace Content.IntegrationTests.Tests.Body
var bodySys = EntitySystem.Get<BodySystem>();
var lungSys = EntitySystem.Get<LungSystem>();
Assert.That(human.TryGetComponent(out SharedBodyComponent body));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out SharedBodyComponent body));
var lungs = bodySys.GetComponentsOnMechanisms<LungComponent>(human.Uid, body).ToArray();
Assert.That(lungs.Count, Is.EqualTo(1));
Assert.That(human.TryGetComponent(out BloodstreamComponent bloodstream));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out BloodstreamComponent bloodstream));
var gas = new GasMixture(1);
@@ -172,7 +172,7 @@ namespace Content.IntegrationTests.Tests.Body
human = entityManager.SpawnEntity("HumanBodyAndBloodstreamDummy", coordinates);
Assert.True(IoCManager.Resolve<IEntityManager>().HasComponent<SharedBodyComponent>(human.Uid));
Assert.True(human.TryGetComponent(out respirator));
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out respirator));
Assert.False(respirator.Suffocating);
});

View File

@@ -82,13 +82,13 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork
device1 = entityManager.SpawnEntity("DummyNetworkDevice", MapCoordinates.Nullspace);
Assert.That(device1.TryGetComponent(out networkComponent1), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(device1.Uid, out networkComponent1), Is.True);
Assert.That(networkComponent1.Open, Is.True);
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
device2 = entityManager.SpawnEntity("DummyNetworkDevice", MapCoordinates.Nullspace);
Assert.That(device2.TryGetComponent(out networkComponent2), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(device2.Uid, out networkComponent2), Is.True);
Assert.That(networkComponent2.Open, Is.True);
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));
@@ -145,14 +145,14 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork
device1 = entityManager.SpawnEntity("DummyWirelessNetworkDevice", MapCoordinates.Nullspace);
Assert.That(device1.TryGetComponent(out networkComponent1), Is.True);
Assert.That(device1.TryGetComponent(out wirelessNetworkComponent), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(device1.Uid, out networkComponent1), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(device1.Uid, out wirelessNetworkComponent), Is.True);
Assert.That(networkComponent1.Open, Is.True);
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
device2 = entityManager.SpawnEntity("DummyWirelessNetworkDevice", new MapCoordinates(new Robust.Shared.Maths.Vector2(0,50), MapId.Nullspace));
Assert.That(device2.TryGetComponent(out networkComponent2), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(device2.Uid, out networkComponent2), Is.True);
Assert.That(networkComponent2.Open, Is.True);
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));
@@ -232,14 +232,14 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork
device1 = entityManager.SpawnEntity("DummyWiredNetworkDevice", MapCoordinates.Nullspace);
Assert.That(device1.TryGetComponent(out networkComponent1), Is.True);
Assert.That(device1.TryGetComponent(out wiredNetworkComponent), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(device1.Uid, out networkComponent1), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(device1.Uid, out wiredNetworkComponent), Is.True);
Assert.That(networkComponent1.Open, Is.True);
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
device2 = entityManager.SpawnEntity("DummyWiredNetworkDevice", new MapCoordinates(new Robust.Shared.Maths.Vector2(0, 2), MapId.Nullspace));
Assert.That(device2.TryGetComponent(out networkComponent2), Is.True);
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(device2.Uid, out networkComponent2), Is.True);
Assert.That(networkComponent2.Open, Is.True);
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));

View File

@@ -146,7 +146,8 @@ namespace Content.IntegrationTests.Tests.Disposal
disposalTrunk = entityManager.SpawnEntity("DisposalTrunkDummy", disposalUnit.Transform.MapPosition);
// Test for components existing
Assert.True(disposalUnit.TryGetComponent(out unit!));
ref DisposalUnitComponent? comp = ref unit!;
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(disposalUnit.Uid, out comp));
Assert.True(IoCManager.Resolve<IEntityManager>().HasComponent<DisposalEntryComponent>(disposalTrunk.Uid));
// Can't insert, unanchored and unpowered
@@ -190,7 +191,7 @@ namespace Content.IntegrationTests.Tests.Disposal
await server.WaitAssertion(() =>
{
// Remove power need
Assert.True(disposalUnit.TryGetComponent(out ApcPowerReceiverComponent power));
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(disposalUnit.Uid, out ApcPowerReceiverComponent power));
power!.NeedsPower = false;
Assert.True(unit.Powered);

View File

@@ -65,7 +65,7 @@ namespace Content.IntegrationTests.Tests.Doors
airlock = entityManager.SpawnEntity("AirlockDummy", MapCoordinates.Nullspace);
Assert.True(airlock.TryGetComponent(out doorComponent));
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(airlock.Uid, out doorComponent));
Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Closed));
});
@@ -136,9 +136,9 @@ namespace Content.IntegrationTests.Tests.Doors
airlock = entityManager.SpawnEntity("AirlockDummy", new MapCoordinates((0, 0), mapId));
Assert.True(physicsDummy.TryGetComponent(out physBody));
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(physicsDummy.Uid, out physBody));
Assert.True(airlock.TryGetComponent(out doorComponent));
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(airlock.Uid, out doorComponent));
Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Closed));
});

View File

@@ -66,11 +66,13 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
human.Transform.WorldPosition = otherHuman.Transform.WorldPosition;
// Test for components existing
Assert.True(human.TryGetComponent(out cuffed!), $"Human has no {nameof(CuffableComponent)}");
Assert.True(human.TryGetComponent(out hands!), $"Human has no {nameof(HandsComponent)}");
Assert.True(human.TryGetComponent(out SharedBodyComponent? _), $"Human has no {nameof(SharedBodyComponent)}");
Assert.True(cuffs.TryGetComponent(out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}");
Assert.True(secondCuffs.TryGetComponent(out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
ref CuffableComponent? comp = ref cuffed!;
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out comp), $"Human has no {nameof(CuffableComponent)}");
ref HandsComponent? comp1 = ref hands!;
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out comp1), $"Human has no {nameof(HandsComponent)}");
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out SharedBodyComponent? _), $"Human has no {nameof(SharedBodyComponent)}");
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(cuffs.Uid, out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}");
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(secondCuffs.Uid, out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
// Test to ensure cuffed players register the handcuffs
cuffed.TryAddNewCuffs(human, cuffs);

View File

@@ -251,7 +251,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
// spawn and give them an item that has actions
serverFlashlight = serverEntManager.SpawnEntity("TestFlashlight",
new EntityCoordinates(serverPlayerEnt.Uid, (0, 0)));
Assert.That(serverFlashlight.TryGetComponent<ItemActionsComponent>(out var itemActions));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemActionsComponent?>(serverFlashlight.Uid, out var itemActions));
// we expect this only to have a toggle light action initially
var actionConfigs = itemActions.ActionConfigs.ToList();
Assert.That(actionConfigs.Count == 1);

View File

@@ -54,8 +54,9 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Movement
// Test for climb components existing
// Players and tables should have these in their prototypes.
Assert.That(human.TryGetComponent(out climbing!), "Human has no climbing");
Assert.That(table.TryGetComponent(out ClimbableComponent? _), "Table has no climbable");
ref ClimbingComponent? comp = ref climbing!;
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out comp), "Human has no climbing");
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(table.Uid, out ClimbableComponent? _), "Table has no climbable");
// Now let's make the player enter a climbing transitioning state.
climbing.IsClimbing = true;

View File

@@ -6,6 +6,7 @@ using Content.Shared.Alert;
using Content.Shared.Coordinates;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.IntegrationTests.Tests.Gravity
@@ -52,7 +53,7 @@ namespace Content.IntegrationTests.Tests.Gravity
var coordinates = grid.ToCoordinates();
human = entityManager.SpawnEntity("HumanDummy", coordinates);
Assert.True(human.TryGetComponent(out alerts));
Assert.True(IoCManager.Resolve<IEntityManager>().TryGetComponent(human.Uid, out alerts));
});
// Let WeightlessSystem and GravitySystem tick

View File

@@ -95,7 +95,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
Assert.That(user.TryGetComponent<HandsComponent>(out var hands));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user.Uid, out var hands));
Assert.That(hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(item.Uid)));
interactionSystem.UserInteraction(user, target.Transform.Coordinates, target.Uid);
@@ -167,7 +167,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(interactUsing, Is.False);
Assert.That(interactHand, Is.False);
Assert.That(user.TryGetComponent<HandsComponent>(out var hands));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user.Uid, out var hands));
Assert.That(hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(item.Uid)));
interactionSystem.UserInteraction(user, target.Transform.Coordinates, target.Uid);
@@ -236,7 +236,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
Assert.That(user.TryGetComponent<HandsComponent>(out var hands));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user.Uid, out var hands));
Assert.That(hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(item.Uid)));
interactionSystem.UserInteraction(user, target.Transform.Coordinates, target.Uid);
@@ -306,7 +306,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(interactUsing, Is.False);
Assert.That(interactHand, Is.False);
Assert.That(user.TryGetComponent<HandsComponent>(out var hands));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user.Uid, out var hands));
Assert.That(hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(item.Uid)));
interactionSystem.UserInteraction(user, target.Transform.Coordinates, target.Uid);
@@ -391,7 +391,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
Assert.That(user.TryGetComponent<HandsComponent>(out var hands));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user.Uid, out var hands));
Assert.That(hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(item.Uid)));
interactionSystem.UserInteraction(user, target.Transform.Coordinates, target.Uid);

View File

@@ -4,6 +4,7 @@ using Content.Server.Shuttles;
using Content.Server.Shuttles.Components;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
@@ -30,8 +31,8 @@ namespace Content.IntegrationTests.Tests
var grid = mapMan.CreateGrid(mapId);
gridEnt = entMan.GetEntity(grid.GridEntityId);
Assert.That(gridEnt.TryGetComponent(out ShuttleComponent? shuttleComponent));
Assert.That(gridEnt.TryGetComponent(out PhysicsComponent? physicsComponent));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(gridEnt.Uid, out ShuttleComponent? shuttleComponent));
Assert.That(IoCManager.Resolve<IEntityManager>().TryGetComponent(gridEnt.Uid, out PhysicsComponent? physicsComponent));
Assert.That(physicsComponent!.BodyType, Is.EqualTo(BodyType.Dynamic));
Assert.That(gridEnt.Transform.LocalPosition, Is.EqualTo(Vector2.Zero));
physicsComponent.ApplyLinearImpulse(Vector2.One);