aboutsummaryrefslogtreecommitdiff
path: root/source/resources/types/builders
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/resources/types/builders
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/resources/types/builders')
-rw-r--r--source/resources/types/builders/BlockTypeBuilder.cs82
-rw-r--r--source/resources/types/builders/ItemTypeBuilder.cs67
2 files changed, 149 insertions, 0 deletions
diff --git a/source/resources/types/builders/BlockTypeBuilder.cs b/source/resources/types/builders/BlockTypeBuilder.cs
new file mode 100644
index 0000000..e08b1a1
--- /dev/null
+++ b/source/resources/types/builders/BlockTypeBuilder.cs
@@ -0,0 +1,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;
+ }
+ }
+} \ No newline at end of file
diff --git a/source/resources/types/builders/ItemTypeBuilder.cs b/source/resources/types/builders/ItemTypeBuilder.cs
new file mode 100644
index 0000000..cd9f61c
--- /dev/null
+++ b/source/resources/types/builders/ItemTypeBuilder.cs
@@ -0,0 +1,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;
+ }
+ }
+} \ No newline at end of file