aboutsummaryrefslogtreecommitdiff
path: root/source/resources/Resources.cs
blob: d200764eeaeecda422d52dc237bd3b51464f07f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.Collections.Generic;
using Celesteia.Resources.Management;
using Celesteia.Resources.Types;
using Microsoft.Xna.Framework.Content;

namespace Celesteia.Resources {
    public static class ResourceManager {
        public static ItemManager Items = new ItemManager();
        public static BlockManager Blocks = new BlockManager();
        public static RecipeManager Recipes = new RecipeManager();
        public static EntityManager Entities = new EntityManager();
        public static FontTypes Fonts = new FontTypes();
        public static SkyboxAssets Skybox = new SkyboxAssets();

        public const float SPRITE_SCALING = 0.125f;
        public const int INVERSE_SPRITE_SCALING = 8;

        public static void AddCollection(IResourceCollection collection) {
            Blocks.AddCollection(collection);
            Items.AddCollection(collection);
            Recipes.AddCollection(collection);
            Entities.AddCollection(collection);
        }

        public static void LoadContent(ContentManager content) {
            Blocks.LoadContent(content);
            Items.LoadContent(content);
            Recipes.LoadContent(content);
            Entities.LoadContent(content);
            
            Fonts.LoadContent(content);
            Skybox.LoadContent(content);
        }
    }

    public struct NamespacedKey {
        public readonly string Namespace;
        public readonly string Index;

        public NamespacedKey(string ns, string index) {
            Namespace = ns;
            Index = index;
        }

        public static NamespacedKey Base(string index) {
            return new NamespacedKey("celesteia", index);
        }

        public string Qualify() {
            return $"{Namespace}:{Index}";
        }

        public override bool Equals(object obj)
        {
            return obj is NamespacedKey && ((NamespacedKey)obj).Namespace == Namespace && ((NamespacedKey)obj).Index == Index;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }

    public interface IResourceType {
        public byte GetID();
        public void SetID(byte id);
    }

    public interface IResourceManager {
        public void AddCollection(IResourceCollection collection);
        public IResourceType GetResource(NamespacedKey namespacedKey);
    }

    public interface IResourceCollection {
        public Dictionary<NamespacedKey, BlockType> GetBlocks();
        public Dictionary<NamespacedKey, ItemType> GetItems();
        public Dictionary<NamespacedKey, Recipe> GetRecipes();
        public Dictionary<NamespacedKey, EntityType> GetEntities();
        public NamespacedKey GetKey(string index);
    }
}