aboutsummaryrefslogtreecommitdiff
path: root/source/resources/management/ItemManager.cs
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/resources/management/ItemManager.cs
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/resources/management/ItemManager.cs')
-rw-r--r--source/resources/management/ItemManager.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/source/resources/management/ItemManager.cs b/source/resources/management/ItemManager.cs
new file mode 100644
index 0000000..3970d7d
--- /dev/null
+++ b/source/resources/management/ItemManager.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using Celesteia.Resources.Types;
+using Microsoft.Xna.Framework.Content;
+
+namespace Celesteia.Resources.Management {
+
+ public class ItemManager : IResourceManager {
+ private List<ItemType> Types;
+ private ItemType[] 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 item types...");
+
+ Types = new List<ItemType>();
+
+ foreach (IResourceCollection collection in _collections)
+ LoadCollection(collection);
+
+ BakedTypes = Types.ToArray();
+ }
+
+ private void LoadCollection(IResourceCollection collection) {
+ foreach (NamespacedKey key in collection.GetItems().Keys) {
+ AddType(key, collection.GetItems()[key]);
+ }
+ }
+
+ private byte next = 0;
+ private void AddType(NamespacedKey key, ItemType 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