diff options
Diffstat (limited to 'source/resources/management')
| -rw-r--r-- | source/resources/management/BlockManager.cs | 77 | ||||
| -rw-r--r-- | source/resources/management/EntityManager.cs | 46 | ||||
| -rw-r--r-- | source/resources/management/FontManager.cs | 43 | ||||
| -rw-r--r-- | source/resources/management/ItemManager.cs | 47 | ||||
| -rw-r--r-- | source/resources/management/RecipeManager.cs | 34 | ||||
| -rw-r--r-- | source/resources/management/SkyboxAssets.cs | 42 |
6 files changed, 289 insertions, 0 deletions
diff --git a/source/resources/management/BlockManager.cs b/source/resources/management/BlockManager.cs new file mode 100644 index 0000000..2271c0c --- /dev/null +++ b/source/resources/management/BlockManager.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using Celesteia.Resources.Sprites; +using Celesteia.Resources.Types; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using MonoGame.Extended.TextureAtlases; + +namespace Celesteia.Resources.Management { + public abstract class BlockSpriteProperties { + public const int SIZE = 8; + } + + public class BlockManager : IResourceManager { + private List<BlockType> Types; + private BlockType[] BakedTypes; + private Dictionary<string, byte> keys = new Dictionary<string, byte>(); + + public BlockFrames BreakAnimation; + public BlockFrames Selection; + + private void LoadBreakingAnimation(ContentManager Content) { + Debug.WriteLine($"Loading block break animation..."); + BreakAnimation = new BlockFrames(TextureAtlas.Create("blockbreak", Content.Load<Texture2D>("sprites/blockbreak"), + BlockSpriteProperties.SIZE, + BlockSpriteProperties.SIZE + ), 0, 3); + } + + private void LoadSelector(ContentManager Content) { + Debug.WriteLine($"Loading block selector..."); + Selection = new BlockFrames(TextureAtlas.Create("selection", Content.Load<Texture2D>("sprites/blockselection"), + BlockSpriteProperties.SIZE, + BlockSpriteProperties.SIZE + ), 0, 1); + } + + private List<IResourceCollection> _collections = new List<IResourceCollection>(); + public void AddCollection(IResourceCollection collection) => _collections.Add(collection); + + public void LoadContent(ContentManager Content) { + LoadBreakingAnimation(Content); + LoadSelector(Content); + + Debug.WriteLine($"Loading block types..."); + + Types = new List<BlockType>(); + + foreach (IResourceCollection collection in _collections) + LoadCollection(collection); + + BakedTypes = Types.ToArray(); + } + + private void LoadCollection(IResourceCollection collection) { + foreach (NamespacedKey key in collection.GetBlocks().Keys) { + AddType(key, collection.GetBlocks()[key]); + } + } + + private byte next = 0; + private void AddType(NamespacedKey key, BlockType type) { + type.SetID(next++); + keys.Add(key.Qualify(), type.GetID()); + + Types.Add(type); + } + + public BlockType GetBlock(byte id) => BakedTypes[id]; + + public IResourceType GetResource(NamespacedKey key) { + if (!keys.ContainsKey(key.Qualify())) throw new NullReferenceException(); + return BakedTypes[keys[key.Qualify()]]; + } + } +}
\ No newline at end of file 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 diff --git a/source/resources/management/FontManager.cs b/source/resources/management/FontManager.cs new file mode 100644 index 0000000..482f25e --- /dev/null +++ b/source/resources/management/FontManager.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; + +namespace Celesteia.Resources.Management { + public abstract class FontProperties { + public const int STANDARD_SIZE = 12; + } + + public class FontTypes { + public FontType DEFAULT { get; private set; } + private List<FontType> Types; + + public void LoadContent(ContentManager Content) { + Debug.WriteLine($"Loading fonts..."); + + Types = new List<FontType>(); + + Types.Add(DEFAULT = new FontType("Hobo", Content.Load<SpriteFont>("Hobo"))); + } + + public FontType GetFontType(string name) { + return Types.Find(x => x.Name == name); + } + } + + public class FontType { + public readonly string Name; + public readonly SpriteFont Font; + + public FontType(string name, SpriteFont font) { + Name = name; + Font = font; + + Debug.WriteLine($" Font '{name}' loaded."); + } + + public float Scale(float targetFontSize) { + return targetFontSize / FontProperties.STANDARD_SIZE; + } + } +}
\ No newline at end of file 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 diff --git a/source/resources/management/RecipeManager.cs b/source/resources/management/RecipeManager.cs new file mode 100644 index 0000000..fb6df07 --- /dev/null +++ b/source/resources/management/RecipeManager.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Diagnostics; +using Celesteia.Resources.Types; +using Microsoft.Xna.Framework.Content; + +namespace Celesteia.Resources.Management { + public class RecipeManager : IResourceManager { + public List<Recipe> Recipes; + + private List<IResourceCollection> _collections = new List<IResourceCollection>(); + public void AddCollection(IResourceCollection collection) => _collections.Add(collection); + + public void LoadContent(ContentManager Content) { + Debug.WriteLine($"Loading crafting recipes..."); + + Recipes = new List<Recipe>(); + + foreach (IResourceCollection collection in _collections) + LoadCollection(collection); + } + + private void LoadCollection(IResourceCollection collection) { + foreach (NamespacedKey key in collection.GetRecipes().Keys) { + AddType(collection.GetRecipes()[key]); + } + } + + private void AddType(Recipe recipe) { + Recipes.Add(recipe); + } + + public IResourceType GetResource(NamespacedKey namespacedKey) => null; + } +}
\ No newline at end of file diff --git a/source/resources/management/SkyboxAssets.cs b/source/resources/management/SkyboxAssets.cs new file mode 100644 index 0000000..049c2a5 --- /dev/null +++ b/source/resources/management/SkyboxAssets.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Diagnostics; +using Celesteia.Resources.Sprites; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using MonoGame.Extended.TextureAtlases; + +namespace Celesteia.Resources.Management { + public class SkyboxAssets { + private List<SkyboxAsset> Assets; + + public void LoadContent(ContentManager Content) { + Debug.WriteLine($"Loading skybox assets..."); + + Assets = new List<SkyboxAsset>(); + + Assets.Add(new SkyboxAsset(0, "stars", TextureAtlas.Create("stars", Content.Load<Texture2D>("sprites/skybox/stars2"), 1024, 1024), 1024, 0)); + Assets.Add(new SkyboxAsset(1, "shadow", TextureAtlas.Create("shadow", Content.Load<Texture2D>("sprites/skybox/shadow"), 1024, 1024), 1024, 0)); + Assets.Add(new SkyboxAsset(2, "nebula", TextureAtlas.Create("nebula", Content.Load<Texture2D>("sprites/skybox/nebula"), 1024, 1024), 1024, 0)); + } + + public SkyboxAsset GetAsset(string name) { + return Assets.Find(x => x.Name == name); + } + } + + public class SkyboxAsset { + public readonly byte AssetID; + public readonly string Name; + public readonly SkyboxPortionFrames Frames; + + public SkyboxAsset(byte id, string name, TextureAtlas atlas, int size, int frameStart, int frameCount) { + AssetID = id; + Name = name; + Frames = new SkyboxPortionFrames(atlas, size, frameStart, frameCount); + + Debug.WriteLine($" Skybox asset '{name}' loaded."); + } + + public SkyboxAsset(byte id, string name, TextureAtlas atlas, int size, int frame) : this (id, name, atlas, size, frame, 1) {} + } +}
\ No newline at end of file |
