Finished first EA Version #1

Merged
Nicola merged 110 commits from dev into main 2026-05-19 20:01:13 +02:00
9 changed files with 248 additions and 135 deletions
Showing only changes of commit a320a86a2f - Show all commits
+155 -78
View File
@@ -1,9 +1,97 @@
[ [
{
"id": "iron_ore",
"inputs": [],
"output": {
"item": "iron_ore",
"amount": 1
},
"workstation": "",
"texture": "res://Assets/Images/Resources/IronSymbol.png",
"research": "bronzeage"
},
{
"id": "tin_ore",
"inputs": [],
"output": {
"item": "tin_ore",
"amount": 1
},
"workstation": "",
"texture": "res://Assets/Images/Resources/TinSymbol.png",
"research": "copperage"
},
{
"id": "copper_ore",
"inputs": [],
"output": {
"item": "copper_ore",
"amount": 1
},
"workstation": "",
"texture": "res://Assets/Images/Resources/CopperSymbol.png",
"research": "stoneage"
},
{
"id": "mushroom",
"inputs": [],
"output": {
"item": "mushroom",
"amount": 1
},
"workstation": "",
"texture": "res://Assets/Images/Resources/MushroomSymbol.png",
"research": "basics"
},
{
"id": "spider_silk",
"inputs": [],
"output": {
"item": "spider_silk",
"amount": 1
},
"workstation": "",
"texture": "res://Assets/Images/Resources/SpiderSilkSymbol.png",
"research": "basics"
},
{
"id": "coal",
"inputs": [],
"output": {
"item": "coal",
"amount": 1
},
"workstation": "",
"texture": "res://Assets/Images/Resources/CoalSymbol.png",
"research": "basics"
},
{
"id": "water",
"inputs": [],
"output": {
"item": "water",
"amount": 1
},
"workstation": "",
"texture": "res://Assets/Images/Resources/WaterSymbol.png",
"research": "basics"
},
{
"id": "stone",
"inputs": [],
"output": {
"item": "stone",
"amount": 1
},
"workstation": "",
"texture": "res://Assets/Images/Resources/StoneSymbol.png",
"research": "basics"
},
{ {
"id": "sand", "id": "sand",
"inputs": [ "inputs": [
{ {
"ingredient": "stone", "item": "stone",
"amount": 1 "amount": 1
} }
], ],
@@ -19,7 +107,7 @@
"id": "stone_gear", "id": "stone_gear",
"inputs": [ "inputs": [
{ {
"ingredient": "stone", "item": "stone",
"amount": 1 "amount": 1
} }
], ],
@@ -35,7 +123,7 @@
"id": "copper_gear", "id": "copper_gear",
"inputs": [ "inputs": [
{ {
"ingredient": "copper_ingot", "item": "copper_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -51,7 +139,7 @@
"id": "tin_gear", "id": "tin_gear",
"inputs": [ "inputs": [
{ {
"ingredient": "tin_ingot", "item": "tin_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -67,7 +155,7 @@
"id": "bronze_gear", "id": "bronze_gear",
"inputs": [ "inputs": [
{ {
"ingredient": "bronze_ingot", "item": "bronze_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -83,15 +171,15 @@
"id": "bronze_ingot", "id": "bronze_ingot",
"inputs": [ "inputs": [
{ {
"ingredient": "tin_ingot", "item": "tin_ingot",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "copper_ingot", "item": "copper_ingot",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "coal", "item": "coal",
"amount": 1 "amount": 1
} }
], ],
@@ -107,7 +195,7 @@
"id": "iron_gear", "id": "iron_gear",
"inputs": [ "inputs": [
{ {
"ingredient": "iron_ingot", "item": "iron_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -123,11 +211,11 @@
"id": "iron_ingot", "id": "iron_ingot",
"inputs": [ "inputs": [
{ {
"ingredient": "iron_ore", "item": "iron_ore",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "coal", "item": "coal",
"amount": 1 "amount": 1
} }
], ],
@@ -143,11 +231,11 @@
"id": "tin_ingot", "id": "tin_ingot",
"inputs": [ "inputs": [
{ {
"ingredient": "tin_ore", "item": "tin_ore",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "coal", "item": "coal",
"amount": 1 "amount": 1
} }
], ],
@@ -163,11 +251,11 @@
"id": "copper_ingot", "id": "copper_ingot",
"inputs": [ "inputs": [
{ {
"ingredient": "copper_ore", "item": "copper_ore",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "coal", "item": "coal",
"amount": 1 "amount": 1
} }
], ],
@@ -183,7 +271,7 @@
"id": "rope", "id": "rope",
"inputs": [ "inputs": [
{ {
"ingredient": "spider_silk", "item": "spider_silk",
"amount": 1 "amount": 1
} }
], ],
@@ -195,30 +283,19 @@
"texture": "res://Assets/Images/Items/RopeSymbol.png", "texture": "res://Assets/Images/Items/RopeSymbol.png",
"research": "stoneage" "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", "id": "stone_robot",
"inputs": [ "inputs": [
{ {
"ingredient": "stone", "item": "stone",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "rope", "item": "rope",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "stone_gear", "item": "stone_gear",
"amount": 1 "amount": 1
} }
], ],
@@ -234,19 +311,19 @@
"id": "copper_robot", "id": "copper_robot",
"inputs": [ "inputs": [
{ {
"ingredient": "copper_plate", "item": "copper_plate",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "rope", "item": "rope",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "copper_gear", "item": "copper_gear",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "battery_v1", "item": "battery_v1",
"amount": 1 "amount": 1
} }
], ],
@@ -262,19 +339,19 @@
"id": "tin_robot", "id": "tin_robot",
"inputs": [ "inputs": [
{ {
"ingredient": "tin_plate", "item": "tin_plate",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "rope", "item": "rope",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "tin_gear", "item": "tin_gear",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "battery_v1", "item": "battery_v1",
"amount": 1 "amount": 1
} }
], ],
@@ -290,19 +367,19 @@
"id": "bronze_robot", "id": "bronze_robot",
"inputs": [ "inputs": [
{ {
"ingredient": "bronze_plate", "item": "bronze_plate",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "rope", "item": "rope",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "bronze_gear", "item": "bronze_gear",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "battery_v1", "item": "battery_v1",
"amount": 1 "amount": 1
} }
], ],
@@ -318,19 +395,19 @@
"id": "iron_robot", "id": "iron_robot",
"inputs": [ "inputs": [
{ {
"ingredient": "iron_plate", "item": "iron_plate",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "rope", "item": "rope",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "iron_gear", "item": "iron_gear",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "battery_v2", "item": "battery_v2",
"amount": 1 "amount": 1
} }
], ],
@@ -346,11 +423,11 @@
"id": "glass", "id": "glass",
"inputs": [ "inputs": [
{ {
"ingredient": "sand", "item": "sand",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "coal", "item": "coal",
"amount": 1 "amount": 1
} }
], ],
@@ -366,11 +443,11 @@
"id": "fabric", "id": "fabric",
"inputs": [ "inputs": [
{ {
"ingredient": "rope", "item": "rope",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "spider_silk", "item": "spider_silk",
"amount": 1 "amount": 1
} }
], ],
@@ -386,7 +463,7 @@
"id": "copper_rod", "id": "copper_rod",
"inputs": [ "inputs": [
{ {
"ingredient": "copper_ingot", "item": "copper_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -402,7 +479,7 @@
"id": "tin_rod", "id": "tin_rod",
"inputs": [ "inputs": [
{ {
"ingredient": "tin_ingot", "item": "tin_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -418,7 +495,7 @@
"id": "bronze_rod", "id": "bronze_rod",
"inputs": [ "inputs": [
{ {
"ingredient": "bronze_ingot", "item": "bronze_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -434,7 +511,7 @@
"id": "iron_rod", "id": "iron_rod",
"inputs": [ "inputs": [
{ {
"ingredient": "iron_ingot", "item": "iron_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -450,15 +527,15 @@
"id": "battery_v1", "id": "battery_v1",
"inputs": [ "inputs": [
{ {
"ingredient": "copper_rod", "item": "copper_rod",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "tin_rod", "item": "tin_rod",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "water", "item": "water",
"amount": 1 "amount": 1
} }
], ],
@@ -474,15 +551,15 @@
"id": "dynamo_v1", "id": "dynamo_v1",
"inputs": [ "inputs": [
{ {
"ingredient": "battery_v1", "item": "battery_v1",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "tin_rod", "item": "tin_rod",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "copper_wire", "item": "copper_wire",
"amount": 1 "amount": 1
} }
], ],
@@ -498,7 +575,7 @@
"id": "copper_wire", "id": "copper_wire",
"inputs": [ "inputs": [
{ {
"ingredient": "copper_ingot", "item": "copper_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -514,7 +591,7 @@
"id": "heating_element_v1", "id": "heating_element_v1",
"inputs": [ "inputs": [
{ {
"ingredient": "stone", "item": "stone",
"amount": 1 "amount": 1
} }
], ],
@@ -530,7 +607,7 @@
"id": "stone_plate", "id": "stone_plate",
"inputs": [ "inputs": [
{ {
"ingredient": "stone", "item": "stone",
"amount": 1 "amount": 1
} }
], ],
@@ -546,7 +623,7 @@
"id": "copper_plate", "id": "copper_plate",
"inputs": [ "inputs": [
{ {
"ingredient": "copper_ingot", "item": "copper_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -562,7 +639,7 @@
"id": "iron_plate", "id": "iron_plate",
"inputs": [ "inputs": [
{ {
"ingredient": "iron_ingot", "item": "iron_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -578,7 +655,7 @@
"id": "bronze_plate", "id": "bronze_plate",
"inputs": [ "inputs": [
{ {
"ingredient": "bronze_ingot", "item": "bronze_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -594,7 +671,7 @@
"id": "tin_plate", "id": "tin_plate",
"inputs": [ "inputs": [
{ {
"ingredient": "tin_ingot", "item": "tin_ingot",
"amount": 1 "amount": 1
} }
], ],
@@ -610,15 +687,15 @@
"id": "battery_v2", "id": "battery_v2",
"inputs": [ "inputs": [
{ {
"ingredient": "iron_rod", "item": "iron_rod",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "copper_rod", "item": "copper_rod",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "water", "item": "water",
"amount": 1 "amount": 1
} }
], ],
@@ -634,19 +711,19 @@
"id": "dynamo_v2", "id": "dynamo_v2",
"inputs": [ "inputs": [
{ {
"ingredient": "battery_v2", "item": "battery_v2",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "iron_rod", "item": "iron_rod",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "copper_wire", "item": "copper_wire",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "tin_plate", "item": "tin_plate",
"amount": 1 "amount": 1
} }
], ],
@@ -662,11 +739,11 @@
"id": "steam", "id": "steam",
"inputs": [ "inputs": [
{ {
"ingredient": "water", "item": "water",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "coal", "item": "coal",
"amount": 1 "amount": 1
} }
], ],
@@ -682,11 +759,11 @@
"id": "glass_bottles", "id": "glass_bottles",
"inputs": [ "inputs": [
{ {
"ingredient": "glass", "item": "glass",
"amount": 1 "amount": 1
}, },
{ {
"ingredient": "coal", "item": "coal",
"amount": 1 "amount": 1
} }
], ],
+6 -1
View File
@@ -1,11 +1,14 @@
using Godot; using Godot;
public class GameResource : Ingredient public class GameResource
{ {
public string name;
int currentAmount;
int maxAmount; int maxAmount;
bool isEndless; bool isEndless;
float extractionSpeed; float extractionSpeed;
double timeSinceLastExtraction; double timeSinceLastExtraction;
ItemData item;
public GameResource(string name) public GameResource(string name)
{ {
@@ -14,6 +17,7 @@ public class GameResource : Ingredient
currentAmount = maxAmount; currentAmount = maxAmount;
isEndless = false; isEndless = false;
extractionSpeed = 1f; extractionSpeed = 1f;
item = GameData.availableItems[name];
} }
public bool Extract(double delta) public bool Extract(double delta)
@@ -25,6 +29,7 @@ public class GameResource : Ingredient
if (currentAmount > 0) if (currentAmount > 0)
{ {
currentAmount--; currentAmount--;
return true; return true;
} }
return false; return false;
+3 -4
View File
@@ -1,8 +1,7 @@
using Godot; using Godot;
public abstract class Ingredient public class Ingredient
{ {
public string name; public string item;
public int currentAmount; public int amount;
public int stackSize;
} }
+11 -11
View File
@@ -3,23 +3,23 @@ using Godot;
public class Inventory public class Inventory
{ {
public List<Ingredient> inventory = new(); public List<Item> inventory = new();
public int maxInventorySize = 8; 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); Item inventoryItem = inventory.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize);
if (ing != null) if (inventoryItem != null)
{ {
ing.currentAmount += amount; inventoryItem.currentAmount += amount;
return true; return true;
} }
else else
{ {
if (inventory.Count < maxInventorySize) if (inventory.Count < maxInventorySize)
{ {
inventory.Add(ingredient); inventory.Add(item);
inventory[inventory.Count - 1].currentAmount += amount; inventory[inventory.Count - 1].currentAmount += amount;
return true; return true;
} }
@@ -27,14 +27,14 @@ public class Inventory
return false; return false;
} }
public bool CanCraft(Dictionary<Ingredient, int> neededIngredients, int amount) public bool CanCraft(List<Ingredient> neededIngredients, int amount)
{ {
bool canCraft = true; bool canCraft = true;
Ingredient ingredient; Item item;
foreach(Ingredient key in neededIngredients.Keys) foreach(Ingredient ingredient in neededIngredients)
{ {
ingredient = inventory.Find(x => x.name == key.name && x.currentAmount >= neededIngredients[key] * amount); item = inventory.Find(x => x.data.Id == ingredient.item && x.currentAmount >= ingredient.amount * amount);
if (ingredient == null) if (item == null)
{ {
canCraft = false; canCraft = false;
break; break;
+11 -19
View File
@@ -1,32 +1,23 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.Json.Serialization;
using Godot; using Godot;
public class Item : Ingredient public class Item
{ {
public Dictionary<Ingredient, int> ingredients; public ItemData data;
public double craftTime; public int currentAmount = 0;
public double elapsedCraftTime; public double elapsedCraftTime = 0;
public int amountCrafted; public int amountCrafted = 0;
public Texture2D display;
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) public CraftingResult Craft(int amount, double delta)
{ {
if (GameData.inventory.CanCraft(ingredients, amount-amountCrafted)) if (GameData.inventory.CanCraft(data.Inputs, amount - amountCrafted))
{ {
elapsedCraftTime += delta; elapsedCraftTime += delta;
if (elapsedCraftTime >= craftTime) if (elapsedCraftTime >= data.CraftTime)
{ {
elapsedCraftTime -= craftTime; elapsedCraftTime -= data.CraftTime;
currentAmount += 1; currentAmount += 1;
amountCrafted++; amountCrafted++;
if (amountCrafted >= amount) if (amountCrafted >= amount)
@@ -41,3 +32,4 @@ public class Item : Ingredient
return CraftingResult.FAILED; 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
+1 -1
View File
@@ -17,7 +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(); public static Dictionary<string, ItemData> availableItems = ResourceLoader.LoadItems();
//--- PLAYER ADJUSTABLE VALUES --- //--- PLAYER ADJUSTABLE VALUES ---
//Color used in primary objects (e.g. Robots) //Color used in primary objects (e.g. Robots)
+27 -18
View File
@@ -2,6 +2,7 @@ using Godot;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.Json;
public partial class ResourceLoader public partial class ResourceLoader
{ {
@@ -49,37 +50,45 @@ public partial class ResourceLoader
public static Dictionary<ProgramNode, PackedScene> LoadDSLNodes() public static Dictionary<ProgramNode, PackedScene> LoadDSLNodes()
{ {
Dictionary<ProgramNode, PackedScene> nodes = new() Dictionary<ProgramNode, PackedScene> nodes = new()
{ {
{ new MoveNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/MoveNode.tscn") }, { new MoveNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/MoveNode.tscn") },
{ new HarvestNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/HarvestNode.tscn") }, { new HarvestNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/HarvestNode.tscn") },
{ new CraftNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/CraftNode.tscn") }, { new CraftNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/CraftNode.tscn") },
{ new ExploreNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/ExploreNode.tscn") } { new ExploreNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/ExploreNode.tscn") }
}; };
return nodes; return nodes;
} }
public static Dictionary<string, Texture2D> LoadResourceSymbols() public static Dictionary<string, Texture2D> LoadResourceSymbols()
{ {
Dictionary<string, Texture2D> symbols = new() Dictionary<string, Texture2D> symbols = new()
{ {
{ "Iron ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/IronSymbol.png") }, { "iron_ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/IronSymbol.png") },
{ "Tin ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/TinSymbol.png") }, { "tin_ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/TinSymbol.png") },
{ "Copper ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/CopperSymbol.png") }, { "copper_ore", GD.Load<Texture2D>($"res://Assets/Images/Resources/CopperSymbol.png") },
{ "Mushroom", GD.Load<Texture2D>($"res://Assets/Images/Resources/MushroomSymbol.png") }, { "mushroom", GD.Load<Texture2D>($"res://Assets/Images/Resources/MushroomSymbol.png") },
{ "Spiderweb", GD.Load<Texture2D>($"res://Assets/Images/Resources/SpiderSilkSymbol.png") }, { "spider_silk", GD.Load<Texture2D>($"res://Assets/Images/Resources/SpiderSilkSymbol.png") },
{ "Coal", GD.Load<Texture2D>($"res://Assets/Images/Resources/CoalSymbol.png") }, { "coal", GD.Load<Texture2D>($"res://Assets/Images/Resources/CoalSymbol.png") },
{ "Water", GD.Load<Texture2D>($"res://Assets/Images/Resources/WaterSymbol.png") }, { "water", GD.Load<Texture2D>($"res://Assets/Images/Resources/WaterSymbol.png") },
{ "Stone", GD.Load<Texture2D>($"res://Assets/Images/Resources/StoneSymbol.png") }, { "stone", GD.Load<Texture2D>($"res://Assets/Images/Resources/StoneSymbol.png") },
}; };
return symbols; return symbols;
} }
public static Dictionary<Ingredient, Texture2D> LoadIngredients() public static Dictionary<string, ItemData> LoadItems()
{ {
Dictionary<Ingredient, Texture2D> ingredients = new()
{
}; FileAccess file = FileAccess.Open("res://Assets/Recipes.json", FileAccess.ModeFlags.Read);
return ingredients; string json = file.GetAsText();
Dictionary<string, ItemData> result = new();
List<ItemData> items = JsonSerializer.Deserialize<List<ItemData>>(json);
foreach (ItemData item in items)
{
result.Add(item.Id, item);
}
return result;
} }
} }