Cleaned up project with better structure.

This commit is contained in:
2026-05-09 11:29:48 +02:00
parent 1ad3454f6a
commit 6708aa277f
95 changed files with 711 additions and 700 deletions
+3
View File
@@ -0,0 +1,3 @@
public class Building
{
}
@@ -0,0 +1 @@
uid://cl2yvllo35qbb
@@ -0,0 +1,6 @@
public enum CraftingResult
{
FAILED,
CRAFTING,
FINISHED
}
@@ -0,0 +1 @@
uid://bd7t0os166lu3
+43
View File
@@ -0,0 +1,43 @@
public class GameResource
{
public string name;
public ItemData item;
private int currentAmount;
private int maxAmount;
private bool isEndless;
private float extractionSpeed;
private double timeSinceLastExtraction;
public GameResource(string name)
{
this.name = name;
maxAmount = GameData.rand.Next(1000, 10000);
currentAmount = maxAmount;
isEndless = false;
extractionSpeed = 1f;
item = GameData.availableItems[name];
}
public bool Extract(double delta)
{
timeSinceLastExtraction += delta;
if (timeSinceLastExtraction < extractionSpeed) return false;
timeSinceLastExtraction = 0;
if (isEndless) return true;
if (currentAmount > 0)
{
currentAmount--;
return true;
}
return false;
}
public bool CanExtract()
{
return (isEndless || currentAmount > 0) && GameData.availableResearch[item.Research].state == ResearchState.RESEARCHED;
}
}
@@ -0,0 +1 @@
uid://bh4m8ufiv5kt8
+10
View File
@@ -0,0 +1,10 @@
using System.Text.Json.Serialization;
public class Ingredient
{
[JsonPropertyName("item")]
public string Item { get; set; }
[JsonPropertyName("amount")]
public int Amount { get; set; }
}
@@ -0,0 +1 @@
uid://dital81qfptdr
+60
View File
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
public class Inventory
{
public List<Item> items = new List<Item>();
public int maxInventorySize = 8;
public event EventHandler OnInventoryUpdate;
public bool AddItem(Item item, int amount)
{
Item inventoryItem = items.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize);
if (inventoryItem != null)
{
inventoryItem.currentAmount += amount;
NotifyInventoryChanged();
return true;
}
if (items.Count < maxInventorySize)
{
items.Add(item);
items[items.Count - 1].currentAmount += amount;
NotifyInventoryChanged();
return true;
}
return false;
}
public bool CanCraft(List<Ingredient> neededIngredients, int amount)
{
foreach (Ingredient ingredient in neededIngredients)
{
Item item = items.Find(x => x.data.Id == ingredient.Item && x.currentAmount >= ingredient.Amount * amount);
if (item == null)
{
return false;
}
}
return true;
}
public void RemoveItem(string id, int amount)
{
Item item = items.Find(x => x.data.Id == id && x.currentAmount >= amount);
if (item != null)
{
item.currentAmount -= amount;
NotifyInventoryChanged();
}
}
private void NotifyInventoryChanged()
{
OnInventoryUpdate?.Invoke(this, EventArgs.Empty);
}
}
@@ -0,0 +1 @@
uid://dnbdfvox75hk8
+35
View File
@@ -0,0 +1,35 @@
public class Item
{
public ItemData data;
public int currentAmount = 0;
public double elapsedCraftTime = 0;
public int amountCrafted = 0;
public CraftingResult Craft(int amount, double delta)
{
elapsedCraftTime += delta;
if (elapsedCraftTime >= data.CraftTime)
{
elapsedCraftTime -= data.CraftTime;
if (!GameData.inventory.AddItem(this, 1))
{
return CraftingResult.FAILED;
}
foreach (Ingredient ingredient in data.Inputs)
{
GameData.inventory.RemoveItem(ingredient.Item, ingredient.Amount);
}
amountCrafted++;
if (amountCrafted >= amount)
{
amountCrafted = 0;
elapsedCraftTime = 0;
return CraftingResult.FINISHED;
}
}
return CraftingResult.CRAFTING;
}
}
+1
View File
@@ -0,0 +1 @@
uid://dpq18vk7hbakh
+61
View File
@@ -0,0 +1,61 @@
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; }
public string GetReadableName()
{
string noUnderscore = Id.Replace("_", " ").ToLower();
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
}
public static string GetReadableName(string input)
{
string noUnderscore = input.Replace("_", " ").ToLower();
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
}
public static string GetIndex(string readable)
{
return readable.ToLower().Replace(" ", "_");
}
public string GetCraftingDisplay()
{
string result = GetReadableName() + ": \r";
foreach (Ingredient ingredient in Inputs)
{
result += $"{GetReadableName(ingredient.Item)} ({ingredient.Amount}),\r";
}
if (Inputs.Count <= 0) return result;
result = result.Remove(result.Length - 2);
return result;
}
}
@@ -0,0 +1 @@
uid://cj8yubkrsdq70
+34
View File
@@ -0,0 +1,34 @@
public class Research
{
public ResearchData data;
public double elapsedResearchTime = 0;
public bool paidResources = false;
public ResearchState state;
public Research(ResearchData data)
{
this.data = data;
state = ResearchState.UNDEFINED;
}
public ResearchResult Execute(double delta)
{
if (!paidResources)
{
foreach (Ingredient ingredient in data.Inputs)
{
GameData.inventory.RemoveItem(ingredient.Item, ingredient.Amount);
}
paidResources = true;
}
elapsedResearchTime += delta;
if (elapsedResearchTime >= data.CraftTime)
{
state = ResearchState.RESEARCHED;
return ResearchResult.FINISHED;
}
return ResearchResult.RESEARCHING;
}
}
@@ -0,0 +1 @@
uid://dj2epbu26v1nv
+31
View File
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class ResearchData
{
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonPropertyName("inputs")]
public List<Ingredient> Inputs { get; set; }
[JsonPropertyName("research")]
public string Research { get; set; }
[JsonPropertyName("crafttime")]
public double CraftTime { get; set; }
[JsonPropertyName("texture")]
public string Texture { get; set; }
public string GetReadableName()
{
string noUnderscore = Id.Replace("_", " ").ToLower();
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
}
public static string GetIndex(string readable)
{
return readable.ToLower().Replace(" ", "_");
}
}
@@ -0,0 +1 @@
uid://duwl6bhiry6uh
@@ -0,0 +1,6 @@
public enum ResearchResult
{
FAILED,
RESEARCHING,
FINISHED
}
@@ -0,0 +1 @@
uid://cuav7j7m1td2h
@@ -0,0 +1,7 @@
public enum ResearchState
{
UNDEFINED,
RESEARCHED,
AVAILABLE,
LOCKED
}
@@ -0,0 +1 @@
uid://b57yhucbav37c
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using Godot;
public partial class Robot : Node3D
{
private List<ProgramNode> nodes = new List<ProgramNode>();
private bool isExecuting = false;
private ProgramNode currentNode;
public string currentProgram;
public string currentMessage = "";
public override void _Process(double delta)
{
if (isExecuting)
{
switch (currentNode.Execute(this, delta))
{
case NodeResult.SUCCESS:
currentNode = currentNode.nextNode;
if (currentNode == null)
{
isExecuting = false;
}
break;
case NodeResult.FAILURE:
isExecuting = false;
currentMessage = "(FAILED)" + currentNode.lastExecutionMessage;
break;
case NodeResult.RUNNING:
currentMessage = "";
break;
}
}
else if (currentMessage.Length <= 0)
{
currentMessage = "No script executing";
}
Visible = Math.Round(Math.Abs(Position.Y / GameData.tileHeight), 0) == GameData.visibleLayer;
}
public void SetupExecution(List<ProgramNode> nodes)
{
if (nodes.Count <= 0) return;
this.nodes = new List<ProgramNode>(nodes);
isExecuting = true;
currentNode = nodes[0];
}
}
+1
View File
@@ -0,0 +1 @@
uid://e0pgy7jya41y