Files
crystall-punk-14/Content.IntegrationTests/Tests/PDA/PDAExtensionsTests.cs

136 lines
4.8 KiB
C#
Raw Normal View History

using System.Linq;
using System.Threading.Tasks;
2021-06-09 22:19:39 +02:00
using Content.Server.Hands.Components;
using Content.Server.Inventory.Components;
using Content.Server.Items;
using Content.Server.PDA;
2021-12-16 23:42:02 +13:00
using Content.Shared.Access.Components;
using Content.Shared.Containers.ItemSlots;
2021-12-16 23:42:02 +13:00
using Content.Shared.PDA;
using NUnit.Framework;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
namespace Content.IntegrationTests.Tests.PDA
{
public class PDAExtensionsTests : ContentIntegrationTest
{
private const string IdCardDummy = "DummyIdCard";
private const string PdaDummy = "DummyPda";
private static readonly string Prototypes = $@"
- type: entity
id: {IdCardDummy}
name: {IdCardDummy}
components:
- type: IdCard
- type: Item
- type: entity
id: {PdaDummy}
name: {PdaDummy}
components:
- type: PDA
idSlot:
name: ID Card
whitelist:
components:
- IdCard
- type: Item";
[Test]
public async Task PlayerGetIdComponent()
{
var clientOptions = new ClientIntegrationOptions
{
ExtraPrototypes = Prototypes
};
var serverOptions = new ServerIntegrationOptions
{
ExtraPrototypes = Prototypes
};
var (client, server) = await StartConnectedServerClientPair(clientOptions, serverOptions);
await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync());
var sPlayerManager = server.ResolveDependency<IPlayerManager>();
var sEntityManager = server.ResolveDependency<IEntityManager>();
await server.WaitAssertion(() =>
{
2021-12-06 15:34:46 +01:00
var player = sPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
2021-12-06 15:39:46 +11:00
Assert.That(player != default);
// The player spawns with an ID on by default
Assert.NotNull(player.GetHeldId());
Assert.True(player.TryGetHeldId(out var id));
Assert.NotNull(id);
// Put PDA in hand
2021-12-05 18:09:01 +01:00
var dummyPda = sEntityManager.SpawnEntity(PdaDummy, sEntityManager.GetComponent<TransformComponent>(player).MapPosition);
var pdaItemComponent = sEntityManager.GetComponent<ItemComponent>(dummyPda);
sEntityManager.GetComponent<HandsComponent>(player).PutInHand(pdaItemComponent);
2021-12-05 18:09:01 +01:00
var pdaComponent = sEntityManager.GetComponent<PDAComponent>(dummyPda);
var pdaIdCard = sEntityManager.SpawnEntity(IdCardDummy, sEntityManager.GetComponent<TransformComponent>(player).MapPosition);
Moving PDA to ECS (#4538) * Moved pen slot to separate component * Moved it all to more generic item slot class * Add sounds * Item slots now supports many slots * Some clean-up * Refactored slots a bit * Moving ID card out * Moving pda to system * Moving PDA owner to ECS * Moved PDA flashlight to separate component * Toggle lights work through events * Fixing UI * Moving uplink to separate component * Continue moving uplink to separate component * More cleaning * Removing pda shared * Nuked shared pda component * Fixed flashlight * Pen slot now showed in UI * Light toggle now shows correctly in UI * Small refactoring of item slots * Added contained entity * Fixed tests * Finished with PDA * Moving PDA uplink to separate window * Adding-removing uplink should show new button * Working on a better debug * Debug command to add uplink * Uplink send state to UI * Almost working UI * Uplink correcty updates when you buy-sell items * Ups * Moved localization to separate file * Minor fixes * Removed item slots methods events * Removed PDA owner name * Removed one uplink event * Deleted all uplink events * Removed flashlight events * Update Content.Shared/Traitor/Uplink/UplinkVisuals.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Item slots system review * Flashlight review * PDA to XAML * Move UplinkMenu to seperate class, fix WeightedColors methods * Move UI to XAML * Moved events to entity id * Address review * Removed uplink extensions * Minor fix * Moved item slots to shared * My bad Robust... * Fixed pda sound * Fixed pda tests * Fixed pda test again Co-authored-by: Alexander Evgrashin <evgrashin.adl@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Visne <vincefvanwijk@gmail.com>
2021-10-03 07:05:52 +03:00
2021-12-05 18:09:01 +01:00
var itemSlots = sEntityManager.GetComponent<ItemSlotsComponent>(dummyPda);
sEntityManager.EntitySysManager.GetEntitySystem<ItemSlotsSystem>()
2021-12-16 23:42:02 +13:00
.TryInsert(dummyPda, pdaComponent.IdSlot, pdaIdCard, null);
var pdaContainedId = pdaComponent.ContainedID;
// The PDA in the hand should be found first
Assert.NotNull(player.GetHeldId());
Assert.True(player.TryGetHeldId(out id));
Moving PDA to ECS (#4538) * Moved pen slot to separate component * Moved it all to more generic item slot class * Add sounds * Item slots now supports many slots * Some clean-up * Refactored slots a bit * Moving ID card out * Moving pda to system * Moving PDA owner to ECS * Moved PDA flashlight to separate component * Toggle lights work through events * Fixing UI * Moving uplink to separate component * Continue moving uplink to separate component * More cleaning * Removing pda shared * Nuked shared pda component * Fixed flashlight * Pen slot now showed in UI * Light toggle now shows correctly in UI * Small refactoring of item slots * Added contained entity * Fixed tests * Finished with PDA * Moving PDA uplink to separate window * Adding-removing uplink should show new button * Working on a better debug * Debug command to add uplink * Uplink send state to UI * Almost working UI * Uplink correcty updates when you buy-sell items * Ups * Moved localization to separate file * Minor fixes * Removed item slots methods events * Removed PDA owner name * Removed one uplink event * Deleted all uplink events * Removed flashlight events * Update Content.Shared/Traitor/Uplink/UplinkVisuals.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Item slots system review * Flashlight review * PDA to XAML * Move UplinkMenu to seperate class, fix WeightedColors methods * Move UI to XAML * Moved events to entity id * Address review * Removed uplink extensions * Minor fix * Moved item slots to shared * My bad Robust... * Fixed pda sound * Fixed pda tests * Fixed pda test again Co-authored-by: Alexander Evgrashin <evgrashin.adl@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Visne <vincefvanwijk@gmail.com>
2021-10-03 07:05:52 +03:00
Assert.NotNull(id);
Assert.That(id, Is.EqualTo(pdaContainedId));
// Put ID card in hand
2021-12-05 18:09:01 +01:00
var idDummy = sEntityManager.SpawnEntity(IdCardDummy, sEntityManager.GetComponent<TransformComponent>(player).MapPosition);
var idItemComponent = sEntityManager.GetComponent<ItemComponent>(idDummy);
sEntityManager.GetComponent<HandsComponent>(player).PutInHand(idItemComponent);
2021-12-05 18:09:01 +01:00
var idCardComponent = sEntityManager.GetComponent<IdCardComponent>(idDummy);
// The ID in the hand should be found first
Assert.NotNull(player.GetHeldId());
Assert.True(player.TryGetHeldId(out id));
Assert.NotNull(id);
Assert.That(id, Is.EqualTo(idCardComponent));
// Remove all IDs and PDAs
2021-12-05 18:09:01 +01:00
var inventory = sEntityManager.GetComponent<InventoryComponent>(player);
foreach (var slot in inventory.Slots)
{
var item = inventory.GetSlotItem(slot);
if (item == null)
{
continue;
}
2021-12-05 18:09:01 +01:00
if (sEntityManager.HasComponent<PDAComponent>(item.Owner))
{
inventory.ForceUnequip(slot);
}
}
2021-12-05 18:09:01 +01:00
var hands = sEntityManager.GetComponent<HandsComponent>(player);
hands.Drop(dummyPda, false);
hands.Drop(idDummy, false);
// No ID
Assert.Null(player.GetHeldId());
Assert.False(player.TryGetHeldId(out id));
Assert.Null(id);
});
}
}
}