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
82
|
using Microsoft.Xna.Framework;
using MonoGame.Extended;
using MonoGame.Extended.TextureAtlases;
namespace Celesteia.Resources.Types.Builders {
public class BlockTypeBuilder {
private TextureAtlas _atlas;
public BlockTypeBuilder(TextureAtlas atlas) {
_atlas = atlas;
}
private BlockType current;
public BlockTypeBuilder WithName(string name) {
current = new BlockType(name);
return this;
}
public BlockTypeBuilder Full() => WithTemplate(BlockTypeTemplate.Full);
public BlockTypeBuilder Invisible() => WithTemplate(BlockTypeTemplate.Invisible);
public BlockTypeBuilder Walkthrough() => WithTemplate(BlockTypeTemplate.Walkthrough);
public BlockTypeBuilder WithTemplate(BlockTypeTemplate template) {
current.Translucent = template.Translucent;
current.BoundingBox = template.BoundingBox;
current.DropKey = template.DropKey;
current.SetLightProperties(template.LightProperties);
current.Strength = template.Strength;
return this;
}
public BlockTypeBuilder Frames(int start, int count = 1) {
current.MakeFrames(_atlas, start, count);
return this;
}
public BlockTypeBuilder UniqueFrames(TextureAtlas atlas, int start, int count = 1, Vector2? origin = null) {
current.Frames = new Sprites.BlockFrames(atlas, start, count, origin);
return this;
}
public BlockTypeBuilder Properties(bool translucent = false, int strength = 1, NamespacedKey? drop = null, BlockLightProperties light = null) {
current.Translucent = translucent;
current.Strength = strength;
current.DropKey = drop;
current.SetLightProperties(light);
return this;
}
public BlockType Get() {
return current;
}
}
public class BlockTypeTemplate
{
public static BlockTypeTemplate Invisible = new BlockTypeTemplate(null, null, 0, true);
public static BlockTypeTemplate Full = new BlockTypeTemplate(new RectangleF(0f, 0f, 1f, 1f), null, 1, false, null);
public static BlockTypeTemplate Walkthrough = new BlockTypeTemplate(null);
public RectangleF? BoundingBox;
public NamespacedKey? DropKey;
public int Strength;
public bool Translucent;
public BlockLightProperties LightProperties;
public BlockTypeTemplate(
RectangleF? boundingBox = null,
NamespacedKey? dropKey = null,
int strength = 1,
bool translucent = false,
BlockLightProperties lightProperties = null
) {
BoundingBox = boundingBox;
DropKey = dropKey;
Strength = strength;
Translucent = translucent;
LightProperties = lightProperties;
}
}
}
|