aboutsummaryrefslogtreecommitdiff
path: root/source/resources/types/BlockType.cs
blob: d55e998201c1e33b95ae53a834af4721ea4400ff (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
using Celesteia.Graphics.Lighting;
using Celesteia.Resources.Sprites;
using MonoGame.Extended;
using MonoGame.Extended.TextureAtlases;

namespace Celesteia.Resources.Types {
    public class BlockType : IResourceType {
        private byte id;
        public readonly string Name;
        public void SetID(byte value) => id = value;
        public byte GetID() => id;

        public BlockType(string name) {
            Name = name;
        }

        public BlockFrames Frames = null;
        public NamespacedKey? DropKey = null;
        public RectangleF? BoundingBox = new RectangleF(0f, 0f, 1f, 1f);
        public int Strength = 1;
        public bool Translucent = false;
        public BlockLightProperties Light = new BlockLightProperties();


        public BlockType MakeFrames(TextureAtlas atlas, int frameStart, int frameCount) {
            Frames = new BlockFrames(atlas, frameStart, frameCount);
            return this;
        }

        public BlockType AddDrop(NamespacedKey dropKey) {
            DropKey = dropKey;
            return this;
        }

        public BlockType SetBoundingBox(RectangleF boundingBox) {
            BoundingBox = boundingBox;
            return this;
        }

        public BlockType SetStrength(int strength) {
            Strength = strength;
            return this;
        }

        public BlockType SetLightProperties(BlockLightProperties properties) {
            Light = properties;
            if (Light == null) Light = new BlockLightProperties();
            return this;
        }

        public BlockType SetTranslucent(bool translucent) {
            Translucent = translucent;
            return this;
        }
    }

    public class BlockLightProperties {
        public readonly bool Emits = false;
        public readonly bool Occludes = true;
        public readonly int Propagation = 0;
        public readonly LightColor Color = LightColor.black;

        public BlockLightProperties() {}
        public BlockLightProperties(LightColor color, int propagation = 0, bool occludes = true) {
            Emits = !color.Equals(LightColor.black);
            Propagation = propagation;
            Occludes = occludes;
            Color = color;
        }
    }
}