diff --git a/src/World.cs b/src/World.cs
index b851f6c..f042800 100644
--- a/src/World.cs
+++ b/src/World.cs
@@ -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() {
diff --git a/src/WorldBuilder.cs b/src/WorldBuilder.cs
new file mode 100644
index 0000000..efb48a7
--- /dev/null
+++ b/src/WorldBuilder.cs
@@ -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;
+ }
+ }
+}
diff --git a/src/encompass-cs.csproj b/src/encompass-cs.csproj
index 214ca26..db07349 100644
--- a/src/encompass-cs.csproj
+++ b/src/encompass-cs.csproj
@@ -11,5 +11,6 @@
+
\ No newline at end of file
diff --git a/test/EntityTest.cs b/test/EntityTest.cs
index dba42e2..2ab8906 100644
--- a/test/EntityTest.cs
+++ b/test/EntityTest.cs
@@ -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);
+
+ var world = worldBuilder.Build();
+ // world.Update();
+
+ Assert.IsTrue(entity.HasComponent());
+ Assert.AreEqual(mockComponent, entity.GetComponent());
}
- 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 mockComponentB;
+ mockComponentB.myInt = 5;
+ mockComponentB.myString = "wassup";
- world.Update();
+ MockComponent mockComponentC;
+ mockComponentC.myInt = 1;
+ mockComponentC.myString = "howdy";
- Assert.IsTrue(entity.HasComponent());
- Assert.AreEqual(mockComponent, entity.GetComponent());
- }
+ entity.AddComponent(mockComponentA);
+ entity.AddComponent(mockComponentB);
+ entity.AddComponent(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().ToList());
+ Assert.Contains(mockComponentB, entity.GetComponents().ToList());
+ Assert.Contains(mockComponentC, entity.GetComponents().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(mockComponentA);
- entity.AddComponent(mockComponentB);
- entity.AddComponent(mockComponentC);
+ entity.AddComponent(mockComponent);
- world.Update();
+ var world = worldBuilder.Build();
- Assert.Contains(mockComponentA, entity.GetComponents().ToList());
- Assert.Contains(mockComponentB, entity.GetComponents().ToList());
- Assert.Contains(mockComponentC, entity.GetComponents().ToList());
- }
+ Assert.AreEqual(mockComponent, entity.GetComponent());
+ }
- [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);
+ entity.AddComponent(mockComponent);
- world.Update();
+ var world = worldBuilder.Build();
- Assert.AreEqual(mockComponent, entity.GetComponent());
- }
-
- [Test]
- public void HasComponent()
- {
- var world = new World();
- var entity = world.CreateEntity();
-
- MockComponent mockComponent;
- mockComponent.myInt = 3;
- mockComponent.myString = "hello";
-
- entity.AddComponent(mockComponent);
-
- world.Update();
-
- Assert.IsTrue(entity.HasComponent());
- }
+ Assert.IsTrue(entity.HasComponent());
}
}
}