blob: cd9f61c9e6081c183e3b8ab02c3b7366ea26c607 (
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
|
using Celesteia.Game.Components;
using Celesteia.Game.Items;
using MonoGame.Extended.TextureAtlases;
namespace Celesteia.Resources.Types.Builders {
public class ItemTypeBuilder {
private TextureAtlas _atlas;
public ItemTypeBuilder(TextureAtlas atlas) {
_atlas = atlas;
}
private ItemType current;
public ItemTypeBuilder WithName(string name) {
current = new ItemType(name);
return this;
}
public ItemTypeBuilder Block(NamespacedKey blockToPlace)
=> Template(ItemTypeTemplate.Block).Actions(new BlockItemActions(blockToPlace));
public ItemTypeBuilder Pickaxe(int power)
=> Template(ItemTypeTemplate.Tool).Actions(new PickaxeItemActions(power));
public ItemTypeBuilder Upgrade(EntityAttribute attribute, float increase, float max )
=> Template(ItemTypeTemplate.Tool).Actions(new UpgradeItemActions(attribute, increase, max));
public ItemTypeBuilder Template(ItemTypeTemplate template) {
current.MaxStackSize = template.MaxStackSize;
current.ConsumeOnUse = template.ConsumeOnUse;
return this;
}
public ItemTypeBuilder Frame(int frame) {
return Frame(_atlas.GetRegion(frame));
}
public ItemTypeBuilder Frame(TextureRegion2D region) {
current.Sprite = region;
return this;
}
public ItemTypeBuilder Actions(IItemActions actions) {
current.Actions = actions;
return this;
}
public ItemType Get() {
return current;
}
}
public class ItemTypeTemplate
{
public static ItemTypeTemplate Block = new ItemTypeTemplate(1000, true);
public static ItemTypeTemplate Tool = new ItemTypeTemplate(1, false);
public static ItemTypeTemplate Upgrade = new ItemTypeTemplate(1, false);
public int MaxStackSize = 99;
public bool ConsumeOnUse = true;
public ItemTypeTemplate(
int maxStackSize = 99,
bool consumeOnUse = true
) {
MaxStackSize = maxStackSize;
ConsumeOnUse = consumeOnUse;
}
}
}
|