aboutsummaryrefslogtreecommitdiff
path: root/source/resources/management/EntityManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'source/resources/management/EntityManager.cs')
-rw-r--r--source/resources/management/EntityManager.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/source/resources/management/EntityManager.cs b/source/resources/management/EntityManager.cs
new file mode 100644
index 0000000..74a4dbe
--- /dev/null
+++ b/source/resources/management/EntityManager.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using Celesteia.Resources.Types;
+using Microsoft.Xna.Framework.Content;
+
+namespace Celesteia.Resources.Management {
+ public class EntityManager : IResourceManager {
+ public List<EntityType> Types;
+ private EntityType[] BakedTypes;
+ private Dictionary<string, byte> keys = new Dictionary<string, byte>();
+
+ private List<IResourceCollection> _collections = new List<IResourceCollection>();
+ public void AddCollection(IResourceCollection collection) => _collections.Add(collection);
+
+ public void LoadContent(ContentManager Content) {
+ Debug.WriteLine($"Loading entity types...");
+
+ Types = new List<EntityType>();
+
+ foreach (IResourceCollection collection in _collections)
+ LoadCollection(collection);
+
+ BakedTypes = Types.ToArray();
+ }
+
+ private void LoadCollection(IResourceCollection collection) {
+ foreach (NamespacedKey key in collection.GetEntities().Keys) {
+ AddType(key, collection.GetEntities()[key]);
+ }
+ }
+
+ private byte next = 0;
+ private void AddType(NamespacedKey key, EntityType type) {
+ type.SetID(next++);
+ keys.Add(key.Qualify(), type.GetID());
+
+ Types.Add(type);
+ }
+
+ public IResourceType GetResource(NamespacedKey key) {
+ if (!keys.ContainsKey(key.Qualify())) throw new NullReferenceException();
+ return BakedTypes[keys[key.Qualify()]];
+ }
+ }
+} \ No newline at end of file