From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/resources/management/ItemManager.cs | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 source/resources/management/ItemManager.cs (limited to 'source/resources/management/ItemManager.cs') 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 Types; + private ItemType[] BakedTypes; + private Dictionary keys = new Dictionary(); + + private List _collections = new List(); + public void AddCollection(IResourceCollection collection) => _collections.Add(collection); + + public void LoadContent(ContentManager Content) { + Debug.WriteLine($"Loading item types..."); + + Types = new List(); + + 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 -- cgit v1.2.3