Working on inventory and crafting system. Translated Excel-Itemlist to .json.

This commit is contained in:
2026-05-05 15:35:42 +02:00
parent 02ba36b665
commit fc26fa2a75
11 changed files with 829 additions and 10 deletions
+701
View File
@@ -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"
}
]
+6
View File
@@ -0,0 +1,6 @@
public enum CraftingResult
{
FAILED,
CRAFTING,
FINISHED
}
+1
View File
@@ -0,0 +1 @@
uid://bd7t0os166lu3
+6 -4
View File
@@ -1,12 +1,11 @@
using Godot; using Godot;
public class GameResource public class GameResource : Ingredient
{ {
int maxAmount; int maxAmount;
int currentAmount;
bool isEndless; bool isEndless;
float extractionSpeed; float extractionSpeed;
public string name; double timeSinceLastExtraction;
public GameResource(string name) public GameResource(string name)
{ {
@@ -17,8 +16,11 @@ public class GameResource
extractionSpeed = 1f; extractionSpeed = 1f;
} }
public bool Extract() public bool Extract(double delta)
{ {
timeSinceLastExtraction += delta;
if (timeSinceLastExtraction < extractionSpeed) return false;
timeSinceLastExtraction = 0;
if(isEndless) return true; if(isEndless) return true;
if (currentAmount > 0) if (currentAmount > 0)
{ {
+8
View File
@@ -0,0 +1,8 @@
using Godot;
public abstract class Ingredient
{
public string name;
public int currentAmount;
public int stackSize;
}
+1
View File
@@ -0,0 +1 @@
uid://dital81qfptdr
+45
View File
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using Godot;
public class Inventory
{
public List<Ingredient> 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<Ingredient, int> 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;
}
}
+1
View File
@@ -0,0 +1 @@
uid://dnbdfvox75hk8
+39 -1
View File
@@ -1,5 +1,43 @@
using System.Collections.Generic;
using Godot; using Godot;
public class Item public class Item : Ingredient
{ {
public Dictionary<Ingredient, int> ingredients;
public double craftTime;
public double elapsedCraftTime;
public int amountCrafted;
public Item(string name, Dictionary<Ingredient, int> 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;
}
} }
+4
View File
@@ -17,6 +17,7 @@ public partial class GameData
public static float robotSpeed = 20f; public static float robotSpeed = 20f;
public static float tileWidth = 6; public static float tileWidth = 6;
public static float tileHeight = 4; public static float tileHeight = 4;
public static Dictionary<Ingredient, Texture2D> availableIngredients = ResourceLoader.LoadIngredients();
//--- PLAYER ADJUSTABLE VALUES --- //--- PLAYER ADJUSTABLE VALUES ---
//Color used in primary objects (e.g. Robots) //Color used in primary objects (e.g. Robots)
@@ -29,5 +30,8 @@ public partial class GameData
public static int layerSize = 20; public static int layerSize = 20;
//Seed used for all random generation except WFC //Seed used for all random generation except WFC
public static int seed = 12345; public static int seed = 12345;
//--- PLAYER VALUES ---
public static Inventory inventory = new Inventory();
} }
+17 -5
View File
@@ -62,12 +62,24 @@ public partial class ResourceLoader
{ {
Dictionary<string, Texture2D> symbols = new() Dictionary<string, Texture2D> symbols = new()
{ {
{ "Iron ore", GD.Load<Texture2D>($"res://Assets/IronSymbol.png") }, { "Iron ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/IronSymbol.png") },
{ "Tin ore", GD.Load<Texture2D>($"res://Assets/TinSymbol.png") }, { "Tin ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/TinSymbol.png") },
{ "Copper ore", GD.Load<Texture2D>($"res://Assets/CopperSymbol.png") }, { "Copper ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/CopperSymbol.png") },
{ "Mushroom", GD.Load<Texture2D>($"res://Assets/MushroomSymbol.png") }, { "Mushroom", GD.Load<Texture2D>($"res://Assets/Images/Resources/MushroomSymbol.png") },
{ "Spiderweb", GD.Load<Texture2D>($"res://Assets/SpiderwebSymbol.png") }, { "Spiderweb", GD.Load<Texture2D>($"res://Assets/Images/Resources/SpiderSilkSymbol.png") },
{ "Coal", GD.Load<Texture2D>($"res://Assets/Images/Resources/CoalSymbol.png") },
{ "Water", GD.Load<Texture2D>($"res://Assets/Images/Resources/WaterSymbol.png") },
{ "Stone", GD.Load<Texture2D>($"res://Assets/Images/Resources/StoneSymbol.png") },
}; };
return symbols; return symbols;
} }
public static Dictionary<Ingredient, Texture2D> LoadIngredients()
{
Dictionary<Ingredient, Texture2D> ingredients = new()
{
};
return ingredients;
}
} }