Added research display to the game
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dj2epbu26v1nv
|
||||
@@ -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(" ", "_");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://duwl6bhiry6uh
|
||||
@@ -0,0 +1 @@
|
||||
uid://pxegmc5nenad
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://drscsrkfphpy7
|
||||
@@ -0,0 +1,6 @@
|
||||
public enum ResearchResult
|
||||
{
|
||||
FAILED,
|
||||
RESEARCHING,
|
||||
FINISHED
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cuav7j7m1td2h
|
||||
Reference in New Issue
Block a user