diff --git a/Blarg.GameFramework/Blarg.GameFramework.csproj b/Blarg.GameFramework/Blarg.GameFramework.csproj
index d833910..a8477c5 100644
--- a/Blarg.GameFramework/Blarg.GameFramework.csproj
+++ b/Blarg.GameFramework/Blarg.GameFramework.csproj
@@ -222,6 +222,9 @@
+
+
+
diff --git a/Blarg.GameFramework/Entities/EntityManager.cs b/Blarg.GameFramework/Entities/EntityManager.cs
index 7f9032b..2c15ad1 100644
--- a/Blarg.GameFramework/Entities/EntityManager.cs
+++ b/Blarg.GameFramework/Entities/EntityManager.cs
@@ -13,6 +13,7 @@ namespace Blarg.GameFramework.Entities
using ComponentStore = Dictionary>;
using GlobalComponentStore = Dictionary;
using ComponentSystemList = List;
+ using EntityPresetMap = Dictionary;
public class EntityManager : IDisposable
{
@@ -22,6 +23,7 @@ namespace Blarg.GameFramework.Entities
ComponentStore _components;
GlobalComponentStore _globalComponents;
ComponentSystemList _componentSystems;
+ EntityPresetMap _presets;
EntityPool _entityPool;
@@ -37,6 +39,7 @@ namespace Blarg.GameFramework.Entities
_components = new ComponentStore();
_globalComponents = new GlobalComponentStore();
_componentSystems = new ComponentSystemList();
+ _presets = new EntityPresetMap();
_entityPool = new EntityPool(this);
@@ -82,6 +85,29 @@ namespace Blarg.GameFramework.Entities
#endregion
+ #region Preset management
+
+ public void AddPreset() where T : EntityPreset
+ {
+ if (_presets.ContainsKey(typeof(T)))
+ throw new InvalidOperationException("EntityPreset of that type is already registered.");
+
+ T preset = (T)Activator.CreateInstance(typeof(T), this);
+ _presets.Add(typeof(T), preset);
+ }
+
+ public void RemovePreset() where T : EntityPreset
+ {
+ _presets.Remove(typeof(T));
+ }
+
+ public void RemoveAllPresets()
+ {
+ _presets.Clear();
+ }
+
+ #endregion
+
#region Entity management
public Entity Add()
@@ -91,6 +117,23 @@ namespace Blarg.GameFramework.Entities
return entity;
}
+ public Entity AddUsingPreset() where T : EntityPreset
+ {
+ return AddUsingPreset(new EntityPreset.EmptyEntityPresetArgs());
+ }
+
+ public Entity AddUsingPreset(EntityPresetArgs args) where T : EntityPreset
+ {
+ var preset = _presets.Get(typeof(T));
+ if (preset == null)
+ throw new InvalidOperationException("Cannot add entity using a non-existant preset.");
+
+ var entity = preset.Create(args);
+ entity.Add().PresetType = typeof(T);
+
+ return entity;
+ }
+
public Entity GetFirstWith() where T : Component
{
EntityToComponentMap componentEntities = _components.Get(typeof(T));
diff --git a/Blarg.GameFramework/Entities/EntityPreset.cs b/Blarg.GameFramework/Entities/EntityPreset.cs
new file mode 100644
index 0000000..4310697
--- /dev/null
+++ b/Blarg.GameFramework/Entities/EntityPreset.cs
@@ -0,0 +1,24 @@
+using System;
+
+namespace Blarg.GameFramework.Entities
+{
+ public abstract class EntityPreset
+ {
+ public struct EmptyEntityPresetArgs : EntityPresetArgs
+ {
+ }
+
+ public readonly EntityManager EntityManager;
+
+ public EntityPreset(EntityManager entityManager)
+ {
+ if (entityManager == null)
+ throw new ArgumentNullException("entityManager");
+
+ EntityManager = entityManager;
+ }
+
+ public abstract Entity Create(EntityPresetArgs args);
+ }
+}
+
diff --git a/Blarg.GameFramework/Entities/EntityPresetArgs.cs b/Blarg.GameFramework/Entities/EntityPresetArgs.cs
new file mode 100644
index 0000000..38e4d2a
--- /dev/null
+++ b/Blarg.GameFramework/Entities/EntityPresetArgs.cs
@@ -0,0 +1,9 @@
+using System;
+
+namespace Blarg.GameFramework.Entities
+{
+ public interface EntityPresetArgs
+ {
+ }
+}
+
diff --git a/Blarg.GameFramework/Entities/SystemComponents/EntityPresetComponent.cs b/Blarg.GameFramework/Entities/SystemComponents/EntityPresetComponent.cs
new file mode 100644
index 0000000..f228949
--- /dev/null
+++ b/Blarg.GameFramework/Entities/SystemComponents/EntityPresetComponent.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace Blarg.GameFramework.Entities.SystemComponents
+{
+ public class EntityPresetComponent : Component
+ {
+ public Type PresetType;
+
+ public override void Reset()
+ {
+ PresetType = null;
+ }
+ }
+}
+