world builder
parent
56bf01f03c
commit
f88870e2d8
|
@ -1,14 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Encompass {
|
||||
public class World {
|
||||
EntityManager entityManager;
|
||||
ComponentManager componentManager;
|
||||
|
||||
public World() {
|
||||
this.componentManager = new ComponentManager();
|
||||
this.entityManager = new EntityManager(componentManager);
|
||||
internal World(EntityManager entityManager, ComponentManager componentManager) {
|
||||
this.entityManager = entityManager;
|
||||
this.componentManager = componentManager;
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Encompass {
|
||||
public class WorldBuilder {
|
||||
private ComponentManager componentManager;
|
||||
private EntityManager entityManager;
|
||||
|
||||
public WorldBuilder() {
|
||||
componentManager = new ComponentManager();
|
||||
entityManager = new EntityManager(componentManager);
|
||||
}
|
||||
|
||||
public Entity CreateEntity() {
|
||||
return this.entityManager.CreateEntity();
|
||||
}
|
||||
|
||||
public World Build() {
|
||||
var world = new World(this.entityManager, this.componentManager);
|
||||
|
||||
this.componentManager.ActivateComponents();
|
||||
this.componentManager.RemoveComponents();
|
||||
|
||||
return world;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,5 +11,6 @@
|
|||
<Content Include="World.cs" />
|
||||
<Content Include="EntityManager.cs" />
|
||||
<Content Include="ComponentManager.cs" />
|
||||
<Content Include="WorldBuilder.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,96 +1,96 @@
|
|||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
|
||||
namespace Encompass
|
||||
{
|
||||
namespace Tests {
|
||||
struct MockComponent : IComponent {
|
||||
public string myString;
|
||||
public int myInt;
|
||||
using Encompass;
|
||||
|
||||
namespace Tests {
|
||||
struct MockComponent : IComponent {
|
||||
public string myString;
|
||||
public int myInt;
|
||||
}
|
||||
|
||||
public class EntityTest
|
||||
{
|
||||
[Test]
|
||||
public void AddComponent()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
MockComponent mockComponent;
|
||||
mockComponent.myInt = 3;
|
||||
mockComponent.myString = "hello";
|
||||
|
||||
entity.AddComponent<MockComponent>(mockComponent);
|
||||
|
||||
var world = worldBuilder.Build();
|
||||
// world.Update();
|
||||
|
||||
Assert.IsTrue(entity.HasComponent<MockComponent>());
|
||||
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
|
||||
}
|
||||
|
||||
public class EntityTest
|
||||
[Test]
|
||||
public void GetComponents()
|
||||
{
|
||||
[Test]
|
||||
public void AddComponent()
|
||||
{
|
||||
var world = new World();
|
||||
var entity = world.CreateEntity();
|
||||
var worldBuilder = new WorldBuilder();
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
MockComponent mockComponent;
|
||||
mockComponent.myInt = 3;
|
||||
mockComponent.myString = "hello";
|
||||
MockComponent mockComponentA;
|
||||
mockComponentA.myInt = 3;
|
||||
mockComponentA.myString = "hello";
|
||||
|
||||
entity.AddComponent<MockComponent>(mockComponent);
|
||||
MockComponent mockComponentB;
|
||||
mockComponentB.myInt = 5;
|
||||
mockComponentB.myString = "wassup";
|
||||
|
||||
world.Update();
|
||||
MockComponent mockComponentC;
|
||||
mockComponentC.myInt = 1;
|
||||
mockComponentC.myString = "howdy";
|
||||
|
||||
Assert.IsTrue(entity.HasComponent<MockComponent>());
|
||||
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
|
||||
}
|
||||
entity.AddComponent<MockComponent>(mockComponentA);
|
||||
entity.AddComponent<MockComponent>(mockComponentB);
|
||||
entity.AddComponent<MockComponent>(mockComponentC);
|
||||
|
||||
[Test]
|
||||
public void GetComponents()
|
||||
{
|
||||
var world = new World();
|
||||
var entity = world.CreateEntity();
|
||||
var world = worldBuilder.Build();
|
||||
|
||||
MockComponent mockComponentA;
|
||||
mockComponentA.myInt = 3;
|
||||
mockComponentA.myString = "hello";
|
||||
Assert.Contains(mockComponentA, entity.GetComponents<MockComponent>().ToList());
|
||||
Assert.Contains(mockComponentB, entity.GetComponents<MockComponent>().ToList());
|
||||
Assert.Contains(mockComponentC, entity.GetComponents<MockComponent>().ToList());
|
||||
}
|
||||
|
||||
MockComponent mockComponentB;
|
||||
mockComponentB.myInt = 5;
|
||||
mockComponentB.myString = "wassup";
|
||||
[Test]
|
||||
public void GetComponent()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
MockComponent mockComponentC;
|
||||
mockComponentC.myInt = 1;
|
||||
mockComponentC.myString = "howdy";
|
||||
MockComponent mockComponent;
|
||||
mockComponent.myInt = 3;
|
||||
mockComponent.myString = "hello";
|
||||
|
||||
entity.AddComponent<MockComponent>(mockComponentA);
|
||||
entity.AddComponent<MockComponent>(mockComponentB);
|
||||
entity.AddComponent<MockComponent>(mockComponentC);
|
||||
entity.AddComponent<MockComponent>(mockComponent);
|
||||
|
||||
world.Update();
|
||||
var world = worldBuilder.Build();
|
||||
|
||||
Assert.Contains(mockComponentA, entity.GetComponents<MockComponent>().ToList());
|
||||
Assert.Contains(mockComponentB, entity.GetComponents<MockComponent>().ToList());
|
||||
Assert.Contains(mockComponentC, entity.GetComponents<MockComponent>().ToList());
|
||||
}
|
||||
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetComponent()
|
||||
{
|
||||
var world = new World();
|
||||
var entity = world.CreateEntity();
|
||||
[Test]
|
||||
public void HasComponent()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
MockComponent mockComponent;
|
||||
mockComponent.myInt = 3;
|
||||
mockComponent.myString = "hello";
|
||||
MockComponent mockComponent;
|
||||
mockComponent.myInt = 3;
|
||||
mockComponent.myString = "hello";
|
||||
|
||||
entity.AddComponent<MockComponent>(mockComponent);
|
||||
entity.AddComponent<MockComponent>(mockComponent);
|
||||
|
||||
world.Update();
|
||||
var world = worldBuilder.Build();
|
||||
|
||||
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasComponent()
|
||||
{
|
||||
var world = new World();
|
||||
var entity = world.CreateEntity();
|
||||
|
||||
MockComponent mockComponent;
|
||||
mockComponent.myInt = 3;
|
||||
mockComponent.myString = "hello";
|
||||
|
||||
entity.AddComponent<MockComponent>(mockComponent);
|
||||
|
||||
world.Update();
|
||||
|
||||
Assert.IsTrue(entity.HasComponent<MockComponent>());
|
||||
}
|
||||
Assert.IsTrue(entity.HasComponent<MockComponent>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue