2019-08-21 22:13:48 +00:00
|
|
|
using System.ComponentModel;
|
2019-07-17 18:24:21 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
|
|
using Encompass;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2019-08-11 00:34:00 +00:00
|
|
|
using Encompass.Exceptions;
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
{
|
|
|
|
public class ComponentTests
|
|
|
|
{
|
2019-08-21 22:13:48 +00:00
|
|
|
struct MockComponent : Encompass.IComponent
|
2019-07-17 18:24:21 +00:00
|
|
|
{
|
|
|
|
public string myString;
|
|
|
|
public int myInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct EntityMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
}
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
static MockComponent gottenMockComponent;
|
2019-07-17 18:24:21 +00:00
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(EntityMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class GetMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var entityMessage in ReadMessages<EntityMessage>())
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
gottenMockComponent = GetComponent<MockComponent>(entityMessage.entity);
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AddComponentTestMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public MockComponent mockComponent;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(AddComponentTestMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-18 21:02:57 +00:00
|
|
|
class AddComponentTestEngine : Engine
|
2019-07-17 18:24:21 +00:00
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var addComponentTestMessage in ReadMessages<AddComponentTestMessage>())
|
|
|
|
{
|
|
|
|
Assert.IsTrue(HasComponent<MockComponent>(addComponentTestMessage.entity));
|
2019-11-21 03:01:29 +00:00
|
|
|
Assert.That(GetComponent<MockComponent>(addComponentTestMessage.entity), Is.EqualTo(addComponentTestMessage.mockComponent));
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AddComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-07-18 21:02:57 +00:00
|
|
|
worldBuilder.AddEngine(new AddComponentTestEngine());
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
2019-08-21 22:13:48 +00:00
|
|
|
worldBuilder.SetComponent(entity, mockComponent);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
AddComponentTestMessage addComponentTestMessage;
|
|
|
|
addComponentTestMessage.entity = entity;
|
|
|
|
addComponentTestMessage.mockComponent = mockComponent;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(addComponentTestMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
}
|
|
|
|
|
2019-08-11 00:34:00 +00:00
|
|
|
[Test]
|
2019-08-21 22:13:48 +00:00
|
|
|
public void SetMultipleComponentOfSameTypeOnEntity()
|
2019-08-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-08-21 22:13:48 +00:00
|
|
|
worldBuilder.AddEngine(new ReadMockComponentEngine());
|
2019-08-11 00:34:00 +00:00
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-12-05 22:59:55 +00:00
|
|
|
worldBuilder.SetComponent(entity, new MockComponent { myInt = 20, myString = "what" });
|
|
|
|
worldBuilder.SetComponent(entity, new MockComponent { myInt = 50, myString = "hi" });
|
|
|
|
worldBuilder.SetComponent(entity, new MockComponent { myInt = 40, myString = "wassup" });
|
2019-08-11 00:34:00 +00:00
|
|
|
|
2019-08-21 22:13:48 +00:00
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
2019-12-05 22:59:55 +00:00
|
|
|
Assert.That(gottenMockComponent.myInt, Is.EqualTo(40));
|
|
|
|
Assert.That(gottenMockComponent.myString, Is.EqualTo("wassup"));
|
2019-08-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-08-21 22:13:48 +00:00
|
|
|
[WritesPending(typeof(MockComponent))]
|
2019-08-21 02:25:59 +00:00
|
|
|
[Writes(typeof(MockComponent))]
|
2019-08-21 22:13:48 +00:00
|
|
|
class OverwriteEngine : Engine
|
2019-08-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
foreach (var (mockComponent, entity) in ReadComponentsIncludingEntity<MockComponent>())
|
2019-08-11 00:34:00 +00:00
|
|
|
{
|
2019-08-21 22:13:48 +00:00
|
|
|
SetComponent(entity, new MockComponent { myInt = 420 });
|
2019-08-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 22:13:48 +00:00
|
|
|
[ReadsPending(typeof(MockComponent))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
|
|
|
class ReadMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
gottenMockComponent = ReadComponent<MockComponent>();
|
2019-08-21 22:13:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-11 00:34:00 +00:00
|
|
|
[Test]
|
2019-08-21 22:13:48 +00:00
|
|
|
public void EngineOverwriteComponent()
|
2019-08-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-08-21 22:13:48 +00:00
|
|
|
worldBuilder.AddEngine(new OverwriteEngine());
|
|
|
|
worldBuilder.AddEngine(new ReadMockComponentEngine());
|
2019-08-11 00:34:00 +00:00
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-11-13 21:15:43 +00:00
|
|
|
worldBuilder.SetComponent(entity, new MockComponent { });
|
2019-08-11 00:34:00 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
2019-08-21 22:13:48 +00:00
|
|
|
world.Update(0.01);
|
2019-08-11 00:34:00 +00:00
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
Assert.That(gottenMockComponent.myInt, Is.EqualTo(420));
|
2019-08-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-08-21 02:25:59 +00:00
|
|
|
[Writes(typeof(MockComponent))]
|
2019-08-11 00:34:00 +00:00
|
|
|
class AddAndRemoveComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
foreach (var (mockComponent, entity) in ReadComponentsIncludingEntity<MockComponent>())
|
2019-08-11 00:34:00 +00:00
|
|
|
{
|
2019-08-21 02:25:59 +00:00
|
|
|
SetComponent(entity, mockComponent);
|
2019-11-21 03:01:29 +00:00
|
|
|
RemoveComponent<MockComponent>(entity);
|
2019-08-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AddMultipleComponentSameFrameAsRemove()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new AddAndRemoveComponentEngine());
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-08-21 22:13:48 +00:00
|
|
|
worldBuilder.SetComponent(entity, new MockComponent());
|
2019-08-11 00:34:00 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
Assert.DoesNotThrow(() => world.Update(0.01));
|
|
|
|
}
|
|
|
|
|
2019-07-18 21:02:57 +00:00
|
|
|
struct AddMockComponentMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public MockComponent mockComponent;
|
|
|
|
}
|
|
|
|
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(AddMockComponentMessage))]
|
2019-07-18 21:02:57 +00:00
|
|
|
class EmitMockComponentMessageEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
|
|
|
|
|
|
|
public EmitMockComponentMessageEngine(Entity entity)
|
|
|
|
{
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 10;
|
|
|
|
mockComponent.myString = "four";
|
|
|
|
|
|
|
|
AddMockComponentMessage addMockComponentMessage;
|
|
|
|
addMockComponentMessage.entity = entity;
|
|
|
|
addMockComponentMessage.mockComponent = mockComponent;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(addMockComponentMessage);
|
2019-07-18 21:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 02:25:59 +00:00
|
|
|
[WritesPending(typeof(MockComponent))]
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(AddMockComponentMessage))]
|
2019-08-21 02:25:59 +00:00
|
|
|
[Writes(typeof(MockComponent))]
|
2019-07-18 21:02:57 +00:00
|
|
|
class AddMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var message in ReadMessages<AddMockComponentMessage>())
|
|
|
|
{
|
2019-08-21 02:25:59 +00:00
|
|
|
SetComponent(message.entity, message.mockComponent);
|
2019-07-18 21:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 17:17:53 +00:00
|
|
|
[ReadsPending(typeof(MockComponent))]
|
2019-07-18 21:02:57 +00:00
|
|
|
class HasMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
|
|
|
|
|
|
|
public HasMockComponentEngine(Entity entity)
|
|
|
|
{
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
2019-07-20 21:10:06 +00:00
|
|
|
Assert.IsTrue(HasComponent<MockComponent>(entity));
|
2019-07-18 21:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AddComponentAndReadSameFrame()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
worldBuilder.AddEngine(new EmitMockComponentMessageEngine(entity));
|
|
|
|
worldBuilder.AddEngine(new AddMockComponentEngine());
|
|
|
|
worldBuilder.AddEngine(new HasMockComponentEngine(entity));
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
}
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
[Test]
|
|
|
|
public void GetComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new GetMockComponentEngine());
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
worldBuilder.SetComponent<MockComponent>(entity, mockComponent);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
EntityMessage entityMessage;
|
|
|
|
entityMessage.entity = entity;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(entityMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
Assert.AreEqual(mockComponent, gottenMockComponent);
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
struct HasComponentTestMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(HasComponentTestMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class HasComponentTestEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var hasComponentTestEngine in ReadMessages<HasComponentTestMessage>())
|
|
|
|
{
|
|
|
|
Assert.IsTrue(HasComponent<MockComponent>(hasComponentTestEngine.entity));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HasComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new HasComponentTestEngine());
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
2019-08-21 22:13:48 +00:00
|
|
|
worldBuilder.SetComponent(entity, mockComponent);
|
2019-11-13 21:15:43 +00:00
|
|
|
|
|
|
|
HasComponentTestMessage hasComponentTestMessage;
|
|
|
|
hasComponentTestMessage.entity = entity;
|
|
|
|
worldBuilder.SendMessage(hasComponentTestMessage);
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
}
|
|
|
|
|
2019-12-06 00:19:35 +00:00
|
|
|
static bool hasComponentRuntimeTypeResult;
|
|
|
|
|
2019-11-13 21:15:43 +00:00
|
|
|
[Receives(typeof(HasComponentTestMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
|
|
|
class HasComponentWithRuntimeTypeEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var hasComponentTestEngine in ReadMessages<HasComponentTestMessage>())
|
|
|
|
{
|
2019-12-06 00:19:35 +00:00
|
|
|
hasComponentRuntimeTypeResult = HasComponent(hasComponentTestEngine.entity, typeof(MockComponent));
|
2019-11-13 21:15:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HasComponentWithRuntimeType()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new HasComponentWithRuntimeTypeEngine());
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
worldBuilder.SetComponent(entity, mockComponent);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
HasComponentTestMessage hasComponentTestMessage;
|
|
|
|
hasComponentTestMessage.entity = entity;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(hasComponentTestMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
2019-12-06 00:19:35 +00:00
|
|
|
|
|
|
|
Assert.IsTrue(hasComponentRuntimeTypeResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HasComponentWithRuntimeTypeFalseWhenNoneHaveBeenCreated()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new HasComponentWithRuntimeTypeEngine());
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
HasComponentTestMessage hasComponentTestMessage;
|
|
|
|
hasComponentTestMessage.entity = entity;
|
|
|
|
worldBuilder.SendMessage(hasComponentTestMessage);
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
|
|
|
Assert.IsFalse(hasComponentRuntimeTypeResult);
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct RemoveComponentTestMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
}
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(RemoveComponentTestMessage))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class RemoveComponentTestEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var removeComponentMessage in ReadMessages<RemoveComponentTestMessage>())
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
RemoveComponent<MockComponent>(removeComponentMessage.entity);
|
2019-07-18 01:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(RemoveComponentTestMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(CheckHasMockComponentMessage))]
|
2019-07-18 01:12:29 +00:00
|
|
|
class DoRemoveCheckEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
2019-07-17 18:24:21 +00:00
|
|
|
|
2019-07-18 01:12:29 +00:00
|
|
|
public DoRemoveCheckEngine(Entity entity)
|
|
|
|
{
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
if (SomeMessage<RemoveComponentTestMessage>())
|
|
|
|
{
|
|
|
|
CheckHasMockComponentMessage checkHasMockComponentMessage;
|
|
|
|
checkHasMockComponentMessage.entity = entity;
|
|
|
|
checkHasMockComponentMessage.shouldHaveComponent = true;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(checkHasMockComponentMessage);
|
2019-07-18 01:12:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CheckHasMockComponentMessage checkHasMockComponentMessage;
|
|
|
|
checkHasMockComponentMessage.entity = entity;
|
|
|
|
checkHasMockComponentMessage.shouldHaveComponent = false;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(checkHasMockComponentMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 03:55:17 +00:00
|
|
|
static bool hasComponentResult;
|
|
|
|
|
2019-07-20 00:50:13 +00:00
|
|
|
[Receives(typeof(CheckHasMockComponentMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
|
|
|
class CheckHasMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var checkHasMockComponentMessage in ReadMessages<CheckHasMockComponentMessage>())
|
|
|
|
{
|
2019-12-06 03:55:17 +00:00
|
|
|
hasComponentResult = HasComponent<MockComponent>(checkHasMockComponentMessage.entity);
|
2019-07-20 00:50:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
[Test]
|
2019-12-06 03:55:17 +00:00
|
|
|
public void RemovedComponentShouldStillExistOnSameFrame()
|
2019-07-17 18:24:21 +00:00
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
2019-07-18 01:12:29 +00:00
|
|
|
worldBuilder.AddEngine(new RemoveComponentTestEngine());
|
|
|
|
worldBuilder.AddEngine(new CheckHasMockComponentEngine());
|
|
|
|
worldBuilder.AddEngine(new DoRemoveCheckEngine(entity));
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
worldBuilder.SetComponent(entity, mockComponent);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
RemoveComponentTestMessage removeComponentMessage;
|
|
|
|
removeComponentMessage.entity = entity;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(removeComponentMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
2019-12-06 03:55:17 +00:00
|
|
|
|
|
|
|
hasComponentResult.Should().BeTrue();
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
|
|
|
|
hasComponentResult.Should().BeFalse();
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 01:12:29 +00:00
|
|
|
struct CheckHasMockComponentMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public bool shouldHaveComponent;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(CheckHasMockComponentMessage))]
|
2019-07-23 17:17:53 +00:00
|
|
|
[ReadsPending(typeof(MockComponent))]
|
2019-07-20 00:50:13 +00:00
|
|
|
class CheckHasPendingMockComponentEngine : Engine
|
2019-07-18 01:12:29 +00:00
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var checkHasMockComponentMessage in ReadMessages<CheckHasMockComponentMessage>())
|
|
|
|
{
|
2019-07-20 21:10:06 +00:00
|
|
|
Assert.IsTrue(HasComponent<MockComponent>(checkHasMockComponentMessage.entity));
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|