Added research display to the game

This commit is contained in:
2026-05-06 21:10:04 +02:00
parent a9475aaaf9
commit ce99936298
31 changed files with 414 additions and 52 deletions
+28
View File
@@ -0,0 +1,28 @@
using Godot;
public class Research
{
public ResearchData data;
public bool isResearched = false;
public double elapsedResearchTime = 0;
public bool paidResources = false;
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)
{
isResearched = true;
return ResearchResult.FINISHED;
}
return ResearchResult.RESEARCHING;
}
}
+1
View File
@@ -0,0 +1 @@
uid://dj2epbu26v1nv
+32
View File
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Godot;
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(" ", "_");
}
}
+1
View File
@@ -0,0 +1 @@
uid://duwl6bhiry6uh
View File
+1
View File
@@ -0,0 +1 @@
uid://pxegmc5nenad
+57
View File
@@ -0,0 +1,57 @@
using Godot;
public partial class ResearchList : PanelContainer
{
[Export] GraphEdit researchGraph;
public override void _Ready()
{
foreach (ResearchData research in GameData.availableResearch.Values)
{
researchGraph.AddChild(CreateItemNode(research.Id, research.Texture));
}
foreach (ResearchData research in GameData.availableResearch.Values)
{
researchGraph.ConnectNode(
research.Research,
0,
research.Id,
0
);
}
}
public override void _Process(double delta)
{
}
private GraphNode CreateItemNode(string id, string texturePath)
{
TextureRect icon = new TextureRect
{
Texture = GD.Load<Texture2D>(texturePath),
StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered
};
GraphNode node = new GraphNode
{
Name = id,
Title = id,
PositionOffset = new Vector2(GameData.availableResearch.Count * -icon.Texture.GetWidth() + researchGraph.GetChildCount() * icon.Texture.GetWidth() * 10, 0)
};
node.SetSlot(
0,
true,
0,
Colors.White,
true,
0,
Colors.White
);
node.AddChild(icon);
return node;
}
}
+1
View File
@@ -0,0 +1 @@
uid://drscsrkfphpy7
+6
View File
@@ -0,0 +1,6 @@
public enum ResearchResult
{
FAILED,
RESEARCHING,
FINISHED
}
+1
View File
@@ -0,0 +1 @@
uid://cuav7j7m1td2h