Improved recipes and added resources to it. Changed how ingredients and items work.

This commit is contained in:
=
2026-05-05 19:26:31 +02:00
parent fc26fa2a75
commit a320a86a2f
9 changed files with 248 additions and 135 deletions
+6 -1
View File
@@ -1,11 +1,14 @@
using Godot;
public class GameResource : Ingredient
public class GameResource
{
public string name;
int currentAmount;
int maxAmount;
bool isEndless;
float extractionSpeed;
double timeSinceLastExtraction;
ItemData item;
public GameResource(string name)
{
@@ -14,6 +17,7 @@ public class GameResource : Ingredient
currentAmount = maxAmount;
isEndless = false;
extractionSpeed = 1f;
item = GameData.availableItems[name];
}
public bool Extract(double delta)
@@ -25,6 +29,7 @@ public class GameResource : Ingredient
if (currentAmount > 0)
{
currentAmount--;
return true;
}
return false;
+3 -4
View File
@@ -1,8 +1,7 @@
using Godot;
public abstract class Ingredient
public class Ingredient
{
public string name;
public int currentAmount;
public int stackSize;
public string item;
public int amount;
}
+11 -11
View File
@@ -3,23 +3,23 @@ using Godot;
public class Inventory
{
public List<Ingredient> inventory = new();
public List<Item> inventory = new();
public int maxInventorySize = 8;
public bool AddIngredient(Ingredient ingredient, int amount)
public bool AddItem(Item item, int amount)
{
Ingredient ing = inventory.Find(x => x.name == ingredient.name && x.currentAmount + amount <= x.stackSize);
if (ing != null)
Item inventoryItem = inventory.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize);
if (inventoryItem != null)
{
ing.currentAmount += amount;
inventoryItem.currentAmount += amount;
return true;
}
else
{
if (inventory.Count < maxInventorySize)
{
inventory.Add(ingredient);
inventory.Add(item);
inventory[inventory.Count - 1].currentAmount += amount;
return true;
}
@@ -27,14 +27,14 @@ public class Inventory
return false;
}
public bool CanCraft(Dictionary<Ingredient, int> neededIngredients, int amount)
public bool CanCraft(List<Ingredient> neededIngredients, int amount)
{
bool canCraft = true;
Ingredient ingredient;
foreach(Ingredient key in neededIngredients.Keys)
Item item;
foreach(Ingredient ingredient in neededIngredients)
{
ingredient = inventory.Find(x => x.name == key.name && x.currentAmount >= neededIngredients[key] * amount);
if (ingredient == null)
item = inventory.Find(x => x.data.Id == ingredient.item && x.currentAmount >= ingredient.amount * amount);
if (item == null)
{
canCraft = false;
break;
+12 -20
View File
@@ -1,32 +1,23 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Godot;
public class Item : Ingredient
public class Item
{
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 ItemData data;
public int currentAmount = 0;
public double elapsedCraftTime = 0;
public int amountCrafted = 0;
public Texture2D display;
public CraftingResult Craft(int amount, double delta)
{
if (GameData.inventory.CanCraft(ingredients, amount-amountCrafted))
if (GameData.inventory.CanCraft(data.Inputs, amount - amountCrafted))
{
elapsedCraftTime += delta;
if (elapsedCraftTime >= craftTime)
if (elapsedCraftTime >= data.CraftTime)
{
elapsedCraftTime -= craftTime;
elapsedCraftTime -= data.CraftTime;
currentAmount += 1;
amountCrafted++;
if (amountCrafted >= amount)
@@ -40,4 +31,5 @@ public class Item : Ingredient
}
return CraftingResult.FAILED;
}
}
}
+30
View File
@@ -0,0 +1,30 @@
using Godot;
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class ItemData
{
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonPropertyName("inputs")]
public List<Ingredient> Inputs { get; set; }
[JsonPropertyName("output")]
public Ingredient Output { get; set; }
[JsonPropertyName("workstation")]
public string Workstation { get; set; }
[JsonPropertyName("texture")]
public string Texture { get; set; }
[JsonPropertyName("research")]
public string Research { get; set; }
[JsonPropertyName("crafttime")]
public double CraftTime { get; set; }
[JsonPropertyName("stacksize")]
public int StackSize { get; set; }
}
+1
View File
@@ -0,0 +1 @@
uid://cj8yubkrsdq70