diff --git a/Assets/Recipes.json b/Assets/Recipes.json new file mode 100644 index 0000000..11a4b52 --- /dev/null +++ b/Assets/Recipes.json @@ -0,0 +1,701 @@ +[ + { + "id": "sand", + "inputs": [ + { + "ingredient": "stone", + "amount": 1 + } + ], + "output": { + "item": "sand", + "amount": 1 + }, + "workstation": "crusher", + "texture": "res://Assets/Images/Items/SandSymbol.png", + "research": "stoneage" + }, + { + "id": "stone_gear", + "inputs": [ + { + "ingredient": "stone", + "amount": 1 + } + ], + "output": { + "item": "stone_gear", + "amount": 1 + }, + "workstation": "workbench", + "texture": "res://Assets/Images/Items/StoneGearSymbol.png", + "research": "stoneage" + }, + { + "id": "copper_gear", + "inputs": [ + { + "ingredient": "copper_ingot", + "amount": 1 + } + ], + "output": { + "item": "copper_gear", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/CopperGearSymbol.png", + "research": "copperage" + }, + { + "id": "tin_gear", + "inputs": [ + { + "ingredient": "tin_ingot", + "amount": 1 + } + ], + "output": { + "item": "tin_gear", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/TinGearSymbol.png", + "research": "copperage" + }, + { + "id": "bronze_gear", + "inputs": [ + { + "ingredient": "bronze_ingot", + "amount": 1 + } + ], + "output": { + "item": "bronze_gear", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/BronzeGearSymbol.png", + "research": "bronzeage" + }, + { + "id": "bronze_ingot", + "inputs": [ + { + "ingredient": "tin_ingot", + "amount": 1 + }, + { + "ingredient": "copper_ingot", + "amount": 1 + }, + { + "ingredient": "coal", + "amount": 1 + } + ], + "output": { + "item": "bronze_ingot", + "amount": 1 + }, + "workstation": "furnace", + "texture": "res://Assets/Images/Items/BronzeIngotSymbol.png", + "research": "bronzeage" + }, + { + "id": "iron_gear", + "inputs": [ + { + "ingredient": "iron_ingot", + "amount": 1 + } + ], + "output": { + "item": "iron_gear", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/IronGearSymbol.png", + "research": "ironage" + }, + { + "id": "iron_ingot", + "inputs": [ + { + "ingredient": "iron_ore", + "amount": 1 + }, + { + "ingredient": "coal", + "amount": 1 + } + ], + "output": { + "item": "iron_ingot", + "amount": 1 + }, + "workstation": "furnace", + "texture": "res://Assets/Images/Items/IronIngotSymbol.png", + "research": "ironage" + }, + { + "id": "tin_ingot", + "inputs": [ + { + "ingredient": "tin_ore", + "amount": 1 + }, + { + "ingredient": "coal", + "amount": 1 + } + ], + "output": { + "item": "tin_ingot", + "amount": 1 + }, + "workstation": "furnace", + "texture": "res://Assets/Images/Items/TinIngotSymbol.png", + "research": "copperage" + }, + { + "id": "copper_ingot", + "inputs": [ + { + "ingredient": "copper_ore", + "amount": 1 + }, + { + "ingredient": "coal", + "amount": 1 + } + ], + "output": { + "item": "copper_ingot", + "amount": 1 + }, + "workstation": "furnace", + "texture": "res://Assets/Images/Items/CopperIngotSymbol.png", + "research": "copperage" + }, + { + "id": "rope", + "inputs": [ + { + "ingredient": "spider_silk", + "amount": 1 + } + ], + "output": { + "item": "rope", + "amount": 1 + }, + "workstation": "workbench", + "texture": "res://Assets/Images/Items/RopeSymbol.png", + "research": "stoneage" + }, + { + "id": "spider_silk", + "inputs": [], + "output": { + "item": "spider_silk", + "amount": 1 + }, + "workstation": "", + "texture": "res://Assets/Images/Items/RopeSymbol.png", + "research": "basics" + }, + { + "id": "stone_robot", + "inputs": [ + { + "ingredient": "stone", + "amount": 1 + }, + { + "ingredient": "rope", + "amount": 1 + }, + { + "ingredient": "stone_gear", + "amount": 1 + } + ], + "output": { + "item": "stone_robot", + "amount": 1 + }, + "workstation": "workbench", + "texture": "res://Assets/Images/Items/StoneRobotSymbol.png", + "research": "stoneage" + }, + { + "id": "copper_robot", + "inputs": [ + { + "ingredient": "copper_plate", + "amount": 1 + }, + { + "ingredient": "rope", + "amount": 1 + }, + { + "ingredient": "copper_gear", + "amount": 1 + }, + { + "ingredient": "battery_v1", + "amount": 1 + } + ], + "output": { + "item": "copper_robot", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/CopperRobotSymbol.png", + "research": "copperage" + }, + { + "id": "tin_robot", + "inputs": [ + { + "ingredient": "tin_plate", + "amount": 1 + }, + { + "ingredient": "rope", + "amount": 1 + }, + { + "ingredient": "tin_gear", + "amount": 1 + }, + { + "ingredient": "battery_v1", + "amount": 1 + } + ], + "output": { + "item": "tin_robot", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/TinRobotSymbol.png", + "research": "copperage" + }, + { + "id": "bronze_robot", + "inputs": [ + { + "ingredient": "bronze_plate", + "amount": 1 + }, + { + "ingredient": "rope", + "amount": 1 + }, + { + "ingredient": "bronze_gear", + "amount": 1 + }, + { + "ingredient": "battery_v1", + "amount": 1 + } + ], + "output": { + "item": "bronze_robot", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/BronzeRobotSymbol.png", + "research": "bronzeage" + }, + { + "id": "iron_robot", + "inputs": [ + { + "ingredient": "iron_plate", + "amount": 1 + }, + { + "ingredient": "rope", + "amount": 1 + }, + { + "ingredient": "iron_gear", + "amount": 1 + }, + { + "ingredient": "battery_v2", + "amount": 1 + } + ], + "output": { + "item": "iron_robot", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/IronRobotSymbol.png", + "research": "ironage" + }, + { + "id": "glass", + "inputs": [ + { + "ingredient": "sand", + "amount": 1 + }, + { + "ingredient": "coal", + "amount": 1 + } + ], + "output": { + "item": "glass", + "amount": 1 + }, + "workstation": "furnace", + "texture": "res://Assets/Images/Items/GlassSymbol.png", + "research": "stoneage" + }, + { + "id": "fabric", + "inputs": [ + { + "ingredient": "rope", + "amount": 1 + }, + { + "ingredient": "spider_silk", + "amount": 1 + } + ], + "output": { + "item": "fabric", + "amount": 1 + }, + "workstation": "loom", + "texture": "res://Assets/Images/Items/RopeSymbol.png", + "research": "copperage" + }, + { + "id": "copper_rod", + "inputs": [ + { + "ingredient": "copper_ingot", + "amount": 1 + } + ], + "output": { + "item": "copper_rod", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/CopperRodSymbol.png", + "research": "copperage" + }, + { + "id": "tin_rod", + "inputs": [ + { + "ingredient": "tin_ingot", + "amount": 1 + } + ], + "output": { + "item": "tin_rod", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/TinRodSymbol.png", + "research": "copperage" + }, + { + "id": "bronze_rod", + "inputs": [ + { + "ingredient": "bronze_ingot", + "amount": 1 + } + ], + "output": { + "item": "bronze_rod", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/BronzeRodSymbol.png", + "research": "bronzeage" + }, + { + "id": "iron_rod", + "inputs": [ + { + "ingredient": "iron_ingot", + "amount": 1 + } + ], + "output": { + "item": "iron_rod", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/IronRodSymbol.png", + "research": "ironage" + }, + { + "id": "battery_v1", + "inputs": [ + { + "ingredient": "copper_rod", + "amount": 1 + }, + { + "ingredient": "tin_rod", + "amount": 1 + }, + { + "ingredient": "water", + "amount": 1 + } + ], + "output": { + "item": "battery_v1", + "amount": 1 + }, + "workstation": "workbench", + "texture": "res://Assets/Images/Items/Batteryv1Symbol.png", + "research": "copperage" + }, + { + "id": "dynamo_v1", + "inputs": [ + { + "ingredient": "battery_v1", + "amount": 1 + }, + { + "ingredient": "tin_rod", + "amount": 1 + }, + { + "ingredient": "copper_wire", + "amount": 1 + } + ], + "output": { + "item": "dynamo_v1", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/Dynamov1Symbol.png", + "research": "copperage" + }, + { + "id": "copper_wire", + "inputs": [ + { + "ingredient": "copper_ingot", + "amount": 1 + } + ], + "output": { + "item": "copper_wire", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/CopperWireSymbol.png", + "research": "copperage" + }, + { + "id": "heating_element_v1", + "inputs": [ + { + "ingredient": "stone", + "amount": 1 + } + ], + "output": { + "item": "heating_element_v1", + "amount": 1 + }, + "workstation": "workbench", + "texture": "res://Assets/Images/Items/Heaterv1Symbol.png", + "research": "stoneage" + }, + { + "id": "stone_plate", + "inputs": [ + { + "ingredient": "stone", + "amount": 1 + } + ], + "output": { + "item": "stone_plate", + "amount": 1 + }, + "workstation": "workbench", + "texture": "res://Assets/Images/Items/StonePlateSymbol.png", + "research": "stoneage" + }, + { + "id": "copper_plate", + "inputs": [ + { + "ingredient": "copper_ingot", + "amount": 1 + } + ], + "output": { + "item": "copper_plate", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/CopperPlateSymbol.png", + "research": "copperage" + }, + { + "id": "iron_plate", + "inputs": [ + { + "ingredient": "iron_ingot", + "amount": 1 + } + ], + "output": { + "item": "iron_plate", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/IronPlateSymbol.png", + "research": "ironage" + }, + { + "id": "bronze_plate", + "inputs": [ + { + "ingredient": "bronze_ingot", + "amount": 1 + } + ], + "output": { + "item": "bronze_plate", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/BronzePlateSymbol.png", + "research": "bronzeage" + }, + { + "id": "tin_plate", + "inputs": [ + { + "ingredient": "tin_ingot", + "amount": 1 + } + ], + "output": { + "item": "tin_plate", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/TinPlateSymbol.png", + "research": "copperage" + }, + { + "id": "battery_v2", + "inputs": [ + { + "ingredient": "iron_rod", + "amount": 1 + }, + { + "ingredient": "copper_rod", + "amount": 1 + }, + { + "ingredient": "water", + "amount": 1 + } + ], + "output": { + "item": "battery_v2", + "amount": 1 + }, + "workstation": "workbench", + "texture": "res://Assets/Images/Items/Batteryv2Symbol.png", + "research": "ironage" + }, + { + "id": "dynamo_v2", + "inputs": [ + { + "ingredient": "battery_v2", + "amount": 1 + }, + { + "ingredient": "iron_rod", + "amount": 1 + }, + { + "ingredient": "copper_wire", + "amount": 1 + }, + { + "ingredient": "tin_plate", + "amount": 1 + } + ], + "output": { + "item": "dynamo_v2", + "amount": 1 + }, + "workstation": "anvil", + "texture": "res://Assets/Images/Items/Dynamov2Symbol.png", + "research": "ironage" + }, + { + "id": "steam", + "inputs": [ + { + "ingredient": "water", + "amount": 1 + }, + { + "ingredient": "coal", + "amount": 1 + } + ], + "output": { + "item": "steam", + "amount": 1 + }, + "workstation": "steam_generator_v1", + "texture": "res://Assets/Images/Items/SteamSymbol.png", + "research": "copperage" + }, + { + "id": "glass_bottles", + "inputs": [ + { + "ingredient": "glass", + "amount": 1 + }, + { + "ingredient": "coal", + "amount": 1 + } + ], + "output": { + "item": "glass_bottles", + "amount": 1 + }, + "workstation": "glassblower", + "texture": "res://Assets/Images/Items/GlassBottleSymbol.png", + "research": "stoneage" + } +] \ No newline at end of file diff --git a/Scripts/Crafting/CraftingResult.cs b/Scripts/Crafting/CraftingResult.cs new file mode 100644 index 0000000..7f81465 --- /dev/null +++ b/Scripts/Crafting/CraftingResult.cs @@ -0,0 +1,6 @@ +public enum CraftingResult +{ + FAILED, + CRAFTING, + FINISHED +} \ No newline at end of file diff --git a/Scripts/Crafting/CraftingResult.cs.uid b/Scripts/Crafting/CraftingResult.cs.uid new file mode 100644 index 0000000..4747de0 --- /dev/null +++ b/Scripts/Crafting/CraftingResult.cs.uid @@ -0,0 +1 @@ +uid://bd7t0os166lu3 diff --git a/Scripts/Crafting/GameResource.cs b/Scripts/Crafting/GameResource.cs index 7111260..15b0366 100644 --- a/Scripts/Crafting/GameResource.cs +++ b/Scripts/Crafting/GameResource.cs @@ -1,12 +1,11 @@ using Godot; -public class GameResource +public class GameResource : Ingredient { int maxAmount; - int currentAmount; bool isEndless; float extractionSpeed; - public string name; + double timeSinceLastExtraction; public GameResource(string name) { @@ -17,8 +16,11 @@ public class GameResource extractionSpeed = 1f; } - public bool Extract() + public bool Extract(double delta) { + timeSinceLastExtraction += delta; + if (timeSinceLastExtraction < extractionSpeed) return false; + timeSinceLastExtraction = 0; if(isEndless) return true; if (currentAmount > 0) { diff --git a/Scripts/Crafting/Ingredient.cs b/Scripts/Crafting/Ingredient.cs new file mode 100644 index 0000000..c8fc739 --- /dev/null +++ b/Scripts/Crafting/Ingredient.cs @@ -0,0 +1,8 @@ +using Godot; + +public abstract class Ingredient +{ + public string name; + public int currentAmount; + public int stackSize; +} \ No newline at end of file diff --git a/Scripts/Crafting/Ingredient.cs.uid b/Scripts/Crafting/Ingredient.cs.uid new file mode 100644 index 0000000..5ec77df --- /dev/null +++ b/Scripts/Crafting/Ingredient.cs.uid @@ -0,0 +1 @@ +uid://dital81qfptdr diff --git a/Scripts/Crafting/Inventory.cs b/Scripts/Crafting/Inventory.cs new file mode 100644 index 0000000..354a3bd --- /dev/null +++ b/Scripts/Crafting/Inventory.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using Godot; + +public class Inventory +{ + public List inventory = new(); + + public int maxInventorySize = 8; + + public bool AddIngredient(Ingredient ingredient, int amount) + { + Ingredient ing = inventory.Find(x => x.name == ingredient.name && x.currentAmount + amount <= x.stackSize); + if (ing != null) + { + ing.currentAmount += amount; + return true; + } + else + { + if (inventory.Count < maxInventorySize) + { + inventory.Add(ingredient); + inventory[inventory.Count - 1].currentAmount += amount; + return true; + } + } + return false; + } + + public bool CanCraft(Dictionary neededIngredients, int amount) + { + bool canCraft = true; + Ingredient ingredient; + foreach(Ingredient key in neededIngredients.Keys) + { + ingredient = inventory.Find(x => x.name == key.name && x.currentAmount >= neededIngredients[key] * amount); + if (ingredient == null) + { + canCraft = false; + break; + } + } + return canCraft; + } +} \ No newline at end of file diff --git a/Scripts/Crafting/Inventory.cs.uid b/Scripts/Crafting/Inventory.cs.uid new file mode 100644 index 0000000..94a0184 --- /dev/null +++ b/Scripts/Crafting/Inventory.cs.uid @@ -0,0 +1 @@ +uid://dnbdfvox75hk8 diff --git a/Scripts/Crafting/Item.cs b/Scripts/Crafting/Item.cs index e388af9..58b8706 100644 --- a/Scripts/Crafting/Item.cs +++ b/Scripts/Crafting/Item.cs @@ -1,5 +1,43 @@ +using System.Collections.Generic; using Godot; -public class Item +public class Item : Ingredient { + public Dictionary ingredients; + public double craftTime; + public double elapsedCraftTime; + public int amountCrafted; + + + public Item(string name, Dictionary ingredients, int stackSize, double craftTime) + { + this.name = name; + this.ingredients = ingredients; + currentAmount = 0; + this.stackSize = stackSize; + this.craftTime = craftTime; + amountCrafted = 0; + } + + public CraftingResult Craft(int amount, double delta) + { + if (GameData.inventory.CanCraft(ingredients, amount-amountCrafted)) + { + elapsedCraftTime += delta; + if (elapsedCraftTime >= craftTime) + { + elapsedCraftTime -= craftTime; + currentAmount += 1; + amountCrafted++; + if (amountCrafted >= amount) + { + amountCrafted = 0; + elapsedCraftTime = 0; + return CraftingResult.FINISHED; + } + } + return CraftingResult.CRAFTING; + } + return CraftingResult.FAILED; + } } \ No newline at end of file diff --git a/Scripts/Helpers/GameData.cs b/Scripts/Helpers/GameData.cs index de2b9d6..e22e106 100644 --- a/Scripts/Helpers/GameData.cs +++ b/Scripts/Helpers/GameData.cs @@ -17,6 +17,7 @@ public partial class GameData public static float robotSpeed = 20f; public static float tileWidth = 6; public static float tileHeight = 4; + public static Dictionary availableIngredients = ResourceLoader.LoadIngredients(); //--- PLAYER ADJUSTABLE VALUES --- //Color used in primary objects (e.g. Robots) @@ -29,5 +30,8 @@ public partial class GameData public static int layerSize = 20; //Seed used for all random generation except WFC public static int seed = 12345; + + //--- PLAYER VALUES --- + public static Inventory inventory = new Inventory(); } diff --git a/Scripts/Helpers/ResourceLoader.cs b/Scripts/Helpers/ResourceLoader.cs index 6d32e0a..6758e57 100644 --- a/Scripts/Helpers/ResourceLoader.cs +++ b/Scripts/Helpers/ResourceLoader.cs @@ -62,12 +62,24 @@ public partial class ResourceLoader { Dictionary symbols = new() { - { "Iron ore", GD.Load($"res://Assets/IronSymbol.png") }, - { "Tin ore", GD.Load($"res://Assets/TinSymbol.png") }, - { "Copper ore", GD.Load($"res://Assets/CopperSymbol.png") }, - { "Mushroom", GD.Load($"res://Assets/MushroomSymbol.png") }, - { "Spiderweb", GD.Load($"res://Assets/SpiderwebSymbol.png") }, + { "Iron ore", GD.Load($"res://Assets/Images/Resources/IronSymbol.png") }, + { "Tin ore", GD.Load($"res://Assets/Images/Resources/TinSymbol.png") }, + { "Copper ore", GD.Load($"res://Assets/Images/Resources/CopperSymbol.png") }, + { "Mushroom", GD.Load($"res://Assets/Images/Resources/MushroomSymbol.png") }, + { "Spiderweb", GD.Load($"res://Assets/Images/Resources/SpiderSilkSymbol.png") }, + { "Coal", GD.Load($"res://Assets/Images/Resources/CoalSymbol.png") }, + { "Water", GD.Load($"res://Assets/Images/Resources/WaterSymbol.png") }, + { "Stone", GD.Load($"res://Assets/Images/Resources/StoneSymbol.png") }, }; return symbols; } + + public static Dictionary LoadIngredients() + { + Dictionary ingredients = new() + { + + }; + return ingredients; + } }