aboutsummaryrefslogtreecommitdiff
path: root/source/resources/types
diff options
context:
space:
mode:
Diffstat (limited to 'source/resources/types')
-rw-r--r--source/resources/types/BlockType.cs71
-rw-r--r--source/resources/types/EntityType.cs20
-rw-r--r--source/resources/types/ItemType.cs21
-rw-r--r--source/resources/types/Recipe.cs48
-rw-r--r--source/resources/types/TileEntityType.cs27
-rw-r--r--source/resources/types/builders/BlockTypeBuilder.cs82
-rw-r--r--source/resources/types/builders/ItemTypeBuilder.cs67
7 files changed, 336 insertions, 0 deletions
diff --git a/source/resources/types/BlockType.cs b/source/resources/types/BlockType.cs
new file mode 100644
index 0000000..d55e998
--- /dev/null
+++ b/source/resources/types/BlockType.cs
@@ -0,0 +1,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;
+ }
+ }
+} \ No newline at end of file
diff --git a/source/resources/types/EntityType.cs b/source/resources/types/EntityType.cs
new file mode 100644
index 0000000..4ecc20f
--- /dev/null
+++ b/source/resources/types/EntityType.cs
@@ -0,0 +1,20 @@
+using System;
+using MonoGame.Extended.Entities;
+
+namespace Celesteia.Resources.Types {
+ public class EntityType : IResourceType {
+ private byte id;
+ public byte GetID() => id;
+ public void SetID(byte value) => id = value;
+
+ private Action<Entity> InstantiateAction;
+
+ public EntityType(Action<Entity> instantiate) {
+ InstantiateAction = instantiate;
+ }
+
+ public void Instantiate(Entity entity) {
+ InstantiateAction.Invoke(entity);
+ }
+ }
+} \ No newline at end of file
diff --git a/source/resources/types/ItemType.cs b/source/resources/types/ItemType.cs
new file mode 100644
index 0000000..8b1da27
--- /dev/null
+++ b/source/resources/types/ItemType.cs
@@ -0,0 +1,21 @@
+using Celesteia.Game.Items;
+using MonoGame.Extended.TextureAtlases;
+
+namespace Celesteia.Resources.Types {
+ public class ItemType : IResourceType {
+ private byte id;
+ public readonly string Name;
+ public byte GetID() => id;
+ public void SetID(byte value) => id = value;
+
+ public ItemType(string name) {
+ Name = name;
+ }
+
+ public string Lore = "";
+ public TextureRegion2D Sprite = null;
+ public int MaxStackSize = 99;
+ public IItemActions Actions;
+ public bool ConsumeOnUse;
+ }
+} \ No newline at end of file
diff --git a/source/resources/types/Recipe.cs b/source/resources/types/Recipe.cs
new file mode 100644
index 0000000..94dd9ba
--- /dev/null
+++ b/source/resources/types/Recipe.cs
@@ -0,0 +1,48 @@
+using System.Collections.Generic;
+using Celesteia.Game.Components.Items;
+
+namespace Celesteia.Resources.Types {
+ public class Recipe : IResourceType {
+ private byte id;
+ public readonly string Name;
+ public byte GetID() => id;
+ public void SetID(byte value) => id = value;
+
+ public Part Result;
+ public List<Part> Ingredients;
+
+ public Recipe(Part result, params Part[] ingredients) {
+ Result = result;
+ Ingredients = new List<Part>(ingredients);
+ }
+
+ public bool Craftable(Inventory inventory) {
+ foreach (Part ingredient in Ingredients)
+ if (!inventory.ContainsAmount(ingredient.Key, ingredient.Amount)) return false;
+
+ return true;
+ }
+
+ public void Craft(Inventory inventory) {
+ if (!Craftable(inventory)) return;
+
+ foreach (Part ingredient in Ingredients)
+ inventory.RemoveAmount(ingredient.Key, ingredient.Amount);
+
+ inventory.AddItem(Result.Stack);
+ }
+ }
+
+ public struct Part {
+ public NamespacedKey Key;
+ public int Amount;
+
+ public Part(NamespacedKey key, int amount) {
+ Key = key;
+ Amount = amount;
+ }
+
+ public ItemStack Stack => new ItemStack(Key, Amount);
+ public ItemType GetItemType() => ResourceManager.Items.GetResource(Key) as ItemType;
+ }
+} \ No newline at end of file
diff --git a/source/resources/types/TileEntityType.cs b/source/resources/types/TileEntityType.cs
new file mode 100644
index 0000000..cd40514
--- /dev/null
+++ b/source/resources/types/TileEntityType.cs
@@ -0,0 +1,27 @@
+using System;
+using Microsoft.Xna.Framework;
+using MonoGame.Extended.Entities;
+
+namespace Celesteia.Resources.Types {
+ public class TileEntityType : IResourceType {
+ private byte id;
+ public byte GetID() => id;
+ public void SetID(byte value) => id = value;
+
+ public readonly Point Bounds;
+ public readonly Point Origin;
+ public readonly NamespacedKey PartKey;
+ private Action<Entity> InstantiateAction;
+
+ public TileEntityType(NamespacedKey part, Action<Entity> instantiate, int width, int height, int originX = 0, int originY = 0) {
+ PartKey = part;
+ InstantiateAction = instantiate;
+ Bounds = new Point(width, height);
+ Origin = new Point(originX, originY);
+ }
+
+ public void Instantiate(Entity entity) {
+ InstantiateAction.Invoke(entity);
+ }
+ }
+} \ No newline at end of file
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