Big project cleanup with overhaul of file responsibilities (KISS) and code (DRY, YAGNI)
This commit is contained in:
@@ -10,7 +10,6 @@ public partial class ResearchList : PanelContainer
|
||||
private bool hasArrangedNodes = false;
|
||||
|
||||
private List<Research> currentResearch = new List<Research>();
|
||||
private List<Research> toDelete = new List<Research>();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -18,30 +17,37 @@ public partial class ResearchList : PanelContainer
|
||||
if (Visible) SetupGraph();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if(currentResearch.Count > 0) toDelete = new List<Research>();
|
||||
if (currentResearch.Count <= 0) return;
|
||||
|
||||
List<Research> finishedResearch = new List<Research>();
|
||||
foreach (Research research in currentResearch)
|
||||
{
|
||||
ResearchResult result = research.Execute(delta);
|
||||
if (result == ResearchResult.FINISHED)
|
||||
{
|
||||
toDelete.Add(research);
|
||||
RecalculateResearchStates();
|
||||
SetupGraph();
|
||||
}
|
||||
else if (result == ResearchResult.FAILED)
|
||||
{
|
||||
research.state = ResearchState.AVAILABLE;
|
||||
toDelete.Add(research);
|
||||
RecalculateResearchStates();
|
||||
SetupGraph();
|
||||
}
|
||||
if (!IsResearchFinished(research, result)) continue;
|
||||
|
||||
finishedResearch.Add(research);
|
||||
}
|
||||
foreach (Research delete in toDelete)
|
||||
|
||||
if (finishedResearch.Count <= 0) return;
|
||||
|
||||
foreach (Research research in finishedResearch)
|
||||
{
|
||||
currentResearch.Remove(delete);
|
||||
currentResearch.Remove(research);
|
||||
}
|
||||
|
||||
RecalculateResearchStates();
|
||||
SetupGraph();
|
||||
}
|
||||
|
||||
private bool IsResearchFinished(Research research, ResearchResult result)
|
||||
{
|
||||
if (result == ResearchResult.FINISHED) return true;
|
||||
if (result != ResearchResult.FAILED) return false;
|
||||
|
||||
research.state = ResearchState.AVAILABLE;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetupGraph()
|
||||
@@ -83,11 +89,10 @@ public partial class ResearchList : PanelContainer
|
||||
|
||||
foreach (Node child in researchGraph.GetChildren())
|
||||
{
|
||||
if (child is GraphNode)
|
||||
{
|
||||
researchGraph.RemoveChild(child);
|
||||
child.QueueFree();
|
||||
}
|
||||
if (child is not GraphNode) continue;
|
||||
|
||||
researchGraph.RemoveChild(child);
|
||||
child.QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,9 +132,10 @@ public partial class ResearchList : PanelContainer
|
||||
|
||||
private GraphNode CreateResearchNode(string id, string texturePath, ResearchState state)
|
||||
{
|
||||
Research research = GameData.availableResearch[id];
|
||||
Texture2D texture = GD.Load<Texture2D>(texturePath);
|
||||
Color stateColor = GetColorByState(state);
|
||||
string tooltipText = GetResearchTooltip(GameData.availableResearch[id]);
|
||||
string tooltipText = GetResearchTooltip(research);
|
||||
|
||||
TextureRect icon = new TextureRect
|
||||
{
|
||||
@@ -141,8 +147,8 @@ public partial class ResearchList : PanelContainer
|
||||
|
||||
Button button = new Button
|
||||
{
|
||||
Text = GetResearchButtonText(GameData.availableResearch[id], state),
|
||||
Disabled = state != ResearchState.AVAILABLE || !GameData.availableResearch[id].CanStart(),
|
||||
Text = GetResearchButtonText(research, state),
|
||||
Disabled = state != ResearchState.AVAILABLE || !research.CanStart(),
|
||||
TooltipText = tooltipText
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user