(WIP) switched from previous DSL System (UI order based) to a new DSL System (node connection based)
This commit is contained in:
@@ -71,8 +71,6 @@ public partial class ResourceLoader
|
||||
{ new CraftNode(), GD.Load<PackedScene>("res://Prefabs/DSL/CraftNode.tscn") },
|
||||
{ new ExploreNode(), GD.Load<PackedScene>("res://Prefabs/DSL/ExploreNode.tscn") },
|
||||
{ new IfNode(), GD.Load<PackedScene>("res://Prefabs/DSL/IfNode.tscn") },
|
||||
{ new ElseNode(), GD.Load<PackedScene>("res://Prefabs/DSL/ElseNode.tscn") },
|
||||
{ new UntilNode(), GD.Load<PackedScene>("res://Prefabs/DSL/UntilNode.tscn") },
|
||||
{ new ForNode(), GD.Load<PackedScene>("res://Prefabs/DSL/ForNode.tscn") },
|
||||
{ new WhileNode(), GD.Load<PackedScene>("res://Prefabs/DSL/WhileNode.tscn") },
|
||||
{ new MaintainNode(), GD.Load<PackedScene>("res://Prefabs/DSL/MaintainNode.tscn") },
|
||||
|
||||
@@ -40,18 +40,6 @@ public class CraftNode : ProgramNode
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
CraftNode duplicate = new CraftNode()
|
||||
@@ -62,32 +50,6 @@ public class CraftNode : ProgramNode
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
OptionButton options = display.GetNode<OptionButton>("./EditorDisplay/VBoxContainer/Values/Item");
|
||||
options.AddItem("Select item...");
|
||||
foreach (ItemData item in GameData.availableItems.Values)
|
||||
{
|
||||
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
if (item.Inputs.Count > 0)
|
||||
{
|
||||
options.AddItem(item.GetCraftingDisplay());
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Amount: {amount}";
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
public class ElseNode : ProgramNode
|
||||
{
|
||||
public ElseNode()
|
||||
{
|
||||
DisplayText = "Else";
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
ElseNode duplicate = new ElseNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://dxpf6nsijqq1d
|
||||
@@ -86,14 +86,6 @@ public class ExploreNode : ProgramNode
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
|
||||
@@ -20,12 +20,6 @@ public class ForNode : ProgramNode
|
||||
return amountExecuted < amount;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
ForNode duplicate = new ForNode()
|
||||
@@ -36,11 +30,6 @@ public class ForNode : ProgramNode
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, AmountExecuted: {amountExecuted}, Amount: {amount}";
|
||||
|
||||
@@ -39,20 +39,12 @@ public class HarvestNode : ProgramNode
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
HarvestNode duplicate = new HarvestNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
|
||||
@@ -41,21 +41,6 @@ public class IfNode : ProgramNode
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
comparator = comparators.GetItemText(comparators.GetSelectedId());
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
IfNode duplicate = new IfNode()
|
||||
@@ -67,43 +52,6 @@ public class IfNode : ProgramNode
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
OptionButton options = display.GetNode<OptionButton>("./EditorDisplay/VBoxContainer/Values/Item");
|
||||
options.AddItem("Select item...");
|
||||
foreach (ItemData item in GameData.availableItems.Values)
|
||||
{
|
||||
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
options.AddItem(item.GetReadableName());
|
||||
}
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OptionButton comparators = display.GetNode<OptionButton>("./EditorDisplay/VBoxContainer/Values/Comparator");
|
||||
|
||||
if (comparator != null)
|
||||
{
|
||||
for (int i = 0; i < comparators.ItemCount; i++)
|
||||
{
|
||||
if (comparators.GetItemText(i) == comparator)
|
||||
{
|
||||
comparators.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Comparator: {comparator}, Amount: {amount}";
|
||||
|
||||
@@ -24,20 +24,12 @@ public class MaintainNode : ProgramNode
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
MaintainNode duplicate = new MaintainNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
|
||||
@@ -64,15 +64,6 @@ public class MoveNode : ProgramNode
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
int posX = (int)valueContainer.GetNode<SpinBox>("./CoordinateX").Value;
|
||||
int posY = (int)valueContainer.GetNode<SpinBox>("./CoordinateY").Value;
|
||||
int posZ = (int)valueContainer.GetNode<SpinBox>("./CoordinateZ").Value;
|
||||
targetPosition = new Vector3I(posX, posY, posZ);
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
MoveNode duplicate = new MoveNode
|
||||
@@ -82,14 +73,6 @@ public class MoveNode : ProgramNode
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateX").MaxValue = GameData.layerSize;
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateY").MaxValue = GameData.ruinSize;
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateZ").MaxValue = GameData.layerSize;
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, Position: ({targetPosition.X}|{targetPosition.Y}|{targetPosition.Z})";
|
||||
|
||||
@@ -7,9 +7,7 @@ public abstract class ProgramNode
|
||||
public string DisplayText;
|
||||
public string lastExecutionMessage;
|
||||
|
||||
public abstract void Setup(NodeDisplay display);
|
||||
public abstract NodeResult Execute(Robot robot, double delta);
|
||||
public abstract void ReadParameters(NodeDisplay display);
|
||||
public abstract ProgramNode Duplicate();
|
||||
public abstract string Save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,20 +31,12 @@ public class SacrificeNode : ProgramNode
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
SacrificeNode duplicate = new SacrificeNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
public class UntilNode : ProgramNode
|
||||
{
|
||||
public UntilNode()
|
||||
{
|
||||
DisplayText = "Until";
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
UntilNode duplicate = new UntilNode();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}";
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://cq0j38wd84pc7
|
||||
@@ -42,22 +42,6 @@ public class WhileNode : ProgramNode
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = display.GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
comparator = comparators.GetItemText(comparators.GetSelectedId());
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
{
|
||||
WhileNode duplicate = new WhileNode()
|
||||
@@ -69,43 +53,6 @@ public class WhileNode : ProgramNode
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public override void Setup(NodeDisplay display)
|
||||
{
|
||||
OptionButton options = display.GetNode<OptionButton>("./EditorDisplay/VBoxContainer/Values/Item");
|
||||
options.AddItem("Select item...");
|
||||
foreach (ItemData item in GameData.availableItems.Values)
|
||||
{
|
||||
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
options.AddItem(item.GetReadableName());
|
||||
}
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OptionButton comparators = display.GetNode<OptionButton>("./EditorDisplay/VBoxContainer/Values/Comparator");
|
||||
|
||||
if (comparator != null)
|
||||
{
|
||||
for (int i = 0; i < comparators.ItemCount; i++)
|
||||
{
|
||||
if (comparators.GetItemText(i) == comparator)
|
||||
{
|
||||
comparators.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Save()
|
||||
{
|
||||
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Comparator: {comparator}, Amount: {amount}";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class CodingWindow : PanelContainer
|
||||
@@ -6,12 +7,12 @@ public partial class CodingWindow : PanelContainer
|
||||
private Robot robot;
|
||||
|
||||
[Export] VBoxContainer codeBlocks;
|
||||
[Export] VBoxContainer editorWindow;
|
||||
[Export] GraphEdit editorWindow;
|
||||
[Export] OptionButton availableScripts;
|
||||
[Export] LineEdit scriptName;
|
||||
[Export] LineEdit nameInput;
|
||||
|
||||
public Dictionary<ProgramNode, PackedScene> DSLNodes;
|
||||
public System.Collections.Generic.Dictionary<ProgramNode, PackedScene> DSLNodes;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -63,48 +64,57 @@ public partial class CodingWindow : PanelContainer
|
||||
|
||||
public void GenerateCodingBlocks()
|
||||
{
|
||||
NodeDisplay nodeDisplay;
|
||||
Button nodeListButton;
|
||||
foreach (ProgramNode nodeTemplate in DSLNodes.Keys)
|
||||
{
|
||||
nodeDisplay = DSLNodes[nodeTemplate].Instantiate<NodeDisplay>();
|
||||
nodeDisplay.node = nodeTemplate;
|
||||
codeBlocks.AddChild(nodeDisplay);
|
||||
nodeDisplay.ShowListDisplay();
|
||||
nodeDisplay.listDisplay.Pressed += () =>
|
||||
nodeListButton = new Button
|
||||
{
|
||||
AddEditorNode(DSLNodes[nodeTemplate], nodeTemplate.Duplicate());
|
||||
Name = nodeTemplate.DisplayText,
|
||||
Text = nodeTemplate.DisplayText
|
||||
};
|
||||
nodeListButton.Pressed += () =>
|
||||
{
|
||||
AddEditorNode(nodeTemplate);
|
||||
};
|
||||
codeBlocks.AddChild(nodeListButton);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddEditorNode(PackedScene prefab, ProgramNode node)
|
||||
private void AddEditorNode(ProgramNode node)
|
||||
{
|
||||
NodeDisplay editorDisplay = prefab.Instantiate<NodeDisplay>();
|
||||
editorDisplay.node = node;
|
||||
NodeDisplay editorDisplay = DSLNodes[node].Instantiate<NodeDisplay>();
|
||||
editorWindow.AddChild(editorDisplay);
|
||||
editorDisplay.ShowEditorDisplay();
|
||||
RegisterEditorNode(editorDisplay);
|
||||
}
|
||||
|
||||
private void RegisterEditorNode(NodeDisplay editorDisplay)
|
||||
{
|
||||
editorDisplay.OnDeleteNode += () =>
|
||||
{
|
||||
editorWindow.RemoveChild(editorDisplay);
|
||||
editorDisplay.QueueFree();
|
||||
};
|
||||
editorDisplay.OnMoveNode += (int direction) =>
|
||||
{
|
||||
int targetIndex = Mathf.Clamp(
|
||||
editorDisplay.GetIndex() + direction,
|
||||
0,
|
||||
editorWindow.GetChildCount() - 1
|
||||
);
|
||||
editorWindow.MoveChild(editorDisplay, targetIndex);
|
||||
};
|
||||
}
|
||||
|
||||
public void ClearWindow()
|
||||
{
|
||||
foreach (Node node in editorWindow.GetChildren())
|
||||
foreach (Dictionary connection in editorWindow.GetConnectionList())
|
||||
{
|
||||
editorWindow.RemoveChild(node);
|
||||
node.QueueFree();
|
||||
editorWindow.DisconnectNode(
|
||||
connection["from_node"].AsStringName(),
|
||||
(int)connection["from_port"],
|
||||
connection["to_node"].AsStringName(),
|
||||
(int)connection["to_port"]
|
||||
);
|
||||
}
|
||||
|
||||
foreach (Node child in editorWindow.GetChildren())
|
||||
{
|
||||
if (child is GraphNode)
|
||||
{
|
||||
editorWindow.RemoveChild(child);
|
||||
child.QueueFree();
|
||||
}
|
||||
}
|
||||
scriptName.Text = "";
|
||||
}
|
||||
@@ -115,16 +125,20 @@ public partial class CodingWindow : PanelContainer
|
||||
|
||||
for (int i = 0; i < editorWindow.GetChildCount(); i++)
|
||||
{
|
||||
NodeDisplay nodeDisplay = editorWindow.GetChild<NodeDisplay>(i);
|
||||
nodeDisplay.node.ReadParameters(nodeDisplay);
|
||||
nodes.Add(nodeDisplay.node.Duplicate());
|
||||
if (i != 0)
|
||||
NodeDisplay nodeDisplay = editorWindow.GetChild(i) as NodeDisplay;
|
||||
if (nodeDisplay == null) continue;
|
||||
|
||||
nodeDisplay.ReadParameters();
|
||||
ProgramNode executableNode = nodeDisplay.node.Duplicate();
|
||||
nodes.Add(executableNode);
|
||||
|
||||
if (nodes.Count > 1)
|
||||
{
|
||||
nodes[i - 1].nextNode = nodes[i];
|
||||
nodes[nodes.Count - 2].nextNode = executableNode;
|
||||
}
|
||||
if (i > 0)
|
||||
if (nodes.Count > 1)
|
||||
{
|
||||
nodes[i].previousNode = nodes[i-1];
|
||||
executableNode.previousNode = nodes[nodes.Count - 2];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,12 +165,7 @@ public partial class CodingWindow : PanelContainer
|
||||
if (nodeDisplay != null)
|
||||
{
|
||||
editorWindow.AddChild(nodeDisplay);
|
||||
nodeDisplay.ShowEditorDisplay();
|
||||
nodeDisplay.OnDeleteNode += () =>
|
||||
{
|
||||
editorWindow.RemoveChild(nodeDisplay);
|
||||
nodeDisplay.QueueFree();
|
||||
};
|
||||
RegisterEditorNode(nodeDisplay);
|
||||
}
|
||||
}
|
||||
scriptName.Text = availableScripts.GetItemText(index);
|
||||
@@ -184,21 +193,7 @@ public partial class CodingWindow : PanelContainer
|
||||
if (nodeDisplay != null)
|
||||
{
|
||||
editorWindow.AddChild(nodeDisplay);
|
||||
nodeDisplay.ShowEditorDisplay();
|
||||
nodeDisplay.OnDeleteNode += () =>
|
||||
{
|
||||
editorWindow.RemoveChild(nodeDisplay);
|
||||
nodeDisplay.QueueFree();
|
||||
};
|
||||
nodeDisplay.OnMoveNode += (int direction) =>
|
||||
{
|
||||
int targetIndex = Mathf.Clamp(
|
||||
nodeDisplay.GetIndex() + direction,
|
||||
0,
|
||||
editorWindow.GetChildCount() - 1
|
||||
);
|
||||
editorWindow.MoveChild(nodeDisplay, targetIndex);
|
||||
};
|
||||
RegisterEditorNode(nodeDisplay);
|
||||
}
|
||||
|
||||
nodeToLoad = nodeToLoad.nextNode;
|
||||
@@ -228,8 +223,10 @@ public partial class CodingWindow : PanelContainer
|
||||
string result = "";
|
||||
for (int i = 0; i < editorWindow.GetChildCount(); i++)
|
||||
{
|
||||
NodeDisplay nodeDisplay = editorWindow.GetChild<NodeDisplay>(i);
|
||||
nodeDisplay.node.ReadParameters(nodeDisplay);
|
||||
NodeDisplay nodeDisplay = editorWindow.GetChild(i) as NodeDisplay;
|
||||
if (nodeDisplay == null) continue;
|
||||
|
||||
nodeDisplay.ReadParameters();
|
||||
result += nodeDisplay.node.Save();
|
||||
result += ";\r\n";
|
||||
}
|
||||
@@ -238,4 +235,23 @@ public partial class CodingWindow : PanelContainer
|
||||
FileHandler.SaveProgram(filename, result);
|
||||
SetupScriptOptions();
|
||||
}
|
||||
|
||||
public void OnNodeConnect(StringName from, int fromPort, StringName to, int toPort)
|
||||
{
|
||||
GD.Print($"From {fromPort} to {toPort}");
|
||||
if (to == from) return;
|
||||
|
||||
foreach (Dictionary connection in editorWindow.GetConnectionList())
|
||||
{
|
||||
if (connection["to_node"].AsStringName() == to && (int)connection["to_port"] == toPort) return;
|
||||
if (connection["from_node"].AsStringName() == from && (int)connection["from_port"] == fromPort) return;
|
||||
}
|
||||
|
||||
editorWindow.ConnectNode(from, fromPort, to, toPort);
|
||||
}
|
||||
|
||||
public void OnNodeDisconnect(StringName from, int fromPort, StringName to, int toPort)
|
||||
{
|
||||
editorWindow.DisconnectNode(from, fromPort, to, toPort);
|
||||
}
|
||||
}
|
||||
|
||||
+22
-176
@@ -1,39 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
public partial class NodeDisplay : PanelContainer
|
||||
|
||||
public partial class NodeDisplay : GraphNode
|
||||
{
|
||||
[Export] PanelContainer editorDisplay;
|
||||
[Export] public Button listDisplay;
|
||||
public ProgramNode node;
|
||||
|
||||
[Signal]
|
||||
public delegate void OnDeleteNodeEventHandler();
|
||||
[Signal]
|
||||
public delegate void OnMoveNodeEventHandler(int direction);
|
||||
|
||||
public void SetNode(ProgramNode node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
node = CreateProgramNode();
|
||||
}
|
||||
|
||||
if (node == null) return;
|
||||
|
||||
node.Setup(this);
|
||||
}
|
||||
|
||||
public void ShowListDisplay()
|
||||
{
|
||||
editorDisplay.Visible = false;
|
||||
listDisplay.Visible = true;
|
||||
}
|
||||
|
||||
public void ShowEditorDisplay()
|
||||
{
|
||||
editorDisplay.Visible = true;
|
||||
listDisplay.Visible = false;
|
||||
SetupDisplay();
|
||||
}
|
||||
|
||||
public void DeleteNodePressed()
|
||||
@@ -51,119 +35,31 @@ public partial class NodeDisplay : PanelContainer
|
||||
if (prefab == null) return null;
|
||||
|
||||
NodeDisplay result = prefab.Instantiate<NodeDisplay>();
|
||||
|
||||
switch (nodeName)
|
||||
{
|
||||
case "move":
|
||||
result.node = new MoveNode();
|
||||
result.LoadMove(nodeSanitized);
|
||||
break;
|
||||
case "harvest":
|
||||
result.node = new HarvestNode();
|
||||
result.LoadHarvest(nodeSanitized);
|
||||
break;
|
||||
case "explore":
|
||||
result.node = new ExploreNode();
|
||||
result.LoadExplore(nodeSanitized);
|
||||
break;
|
||||
case "craft":
|
||||
result.node = new CraftNode();
|
||||
result.LoadCraft(nodeSanitized);
|
||||
break;
|
||||
case "while":
|
||||
result.node = new WhileNode();
|
||||
result.LoadWhile(nodeSanitized);
|
||||
break;
|
||||
case "until":
|
||||
result.node = new UntilNode();
|
||||
result.LoadUntil(nodeSanitized);
|
||||
break;
|
||||
case "for":
|
||||
result.node = new ForNode();
|
||||
result.LoadFor(nodeSanitized);
|
||||
break;
|
||||
case "if":
|
||||
result.node = new IfNode();
|
||||
result.LoadIf(nodeSanitized);
|
||||
break;
|
||||
case "else":
|
||||
result.node = new ElseNode();
|
||||
result.LoadElse(nodeSanitized);
|
||||
break;
|
||||
case "maintain":
|
||||
result.node = new MaintainNode();
|
||||
result.LoadMaintain(nodeSanitized);
|
||||
break;
|
||||
case "sacrifice":
|
||||
result.node = new SacrificeNode();
|
||||
result.LoadSacrifice(nodeSanitized);
|
||||
break;
|
||||
default:
|
||||
result.QueueFree();
|
||||
return null;
|
||||
}
|
||||
result.node = result.CreateProgramNode();
|
||||
result.LoadContent(result, nodeSanitized);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void LoadElse(string content) { }
|
||||
|
||||
private void LoadMaintain(string content) { }
|
||||
|
||||
private void LoadSacrifice(string content) { }
|
||||
|
||||
private void LoadIf(string content)
|
||||
protected virtual ProgramNode CreateProgramNode()
|
||||
{
|
||||
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
string[] parts = content.Split(",");
|
||||
string itemString = parts[1].Replace("Item:", "").Trim();
|
||||
string comparatorString = parts[2].Replace("Comparator:", "").Trim();
|
||||
if (itemString.ToLower() != "empty")
|
||||
{
|
||||
IfNode ifNode = node as IfNode;
|
||||
if (ifNode != null)
|
||||
{
|
||||
ifNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
||||
ifNode.comparator = comparatorString;
|
||||
}
|
||||
}
|
||||
string amountString = parts[3].Replace("Amount:", "").Trim();
|
||||
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void LoadFor(string content)
|
||||
protected virtual void LoadContent(NodeDisplay display, string content) { }
|
||||
|
||||
public virtual void SetupDisplay() { }
|
||||
|
||||
public virtual void ReadParameters() { }
|
||||
|
||||
public HBoxContainer GetValueContainer()
|
||||
{
|
||||
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
string[] parts = content.Split(",");
|
||||
string amountExecuted = parts[1].Replace("AmountExecuted:", "").Trim();
|
||||
ForNode forNode = node as ForNode;
|
||||
if (forNode != null)
|
||||
{
|
||||
forNode.amountExecuted = int.Parse(amountExecuted);
|
||||
}
|
||||
string amountString = parts[2].Replace("Amount:", "").Trim();
|
||||
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
||||
return GetNode<HBoxContainer>("./Values");
|
||||
}
|
||||
|
||||
private void LoadUntil(string content) { }
|
||||
|
||||
private void LoadWhile(string content)
|
||||
protected HBoxContainer GetValueContainer(NodeDisplay display)
|
||||
{
|
||||
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
string[] parts = content.Split(",");
|
||||
string itemString = parts[1].Replace("Item:", "").Trim();
|
||||
string comparatorString = parts[2].Replace("Comparator:", "").Trim();
|
||||
if (itemString.ToLower() != "empty")
|
||||
{
|
||||
WhileNode whileNode = node as WhileNode;
|
||||
if (whileNode != null)
|
||||
{
|
||||
whileNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
||||
whileNode.comparator = comparatorString;
|
||||
}
|
||||
}
|
||||
string amountString = parts[3].Replace("Amount:", "").Trim();
|
||||
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
||||
return display.GetValueContainer();
|
||||
}
|
||||
|
||||
private static PackedScene GetPrefab(string nodeName, Dictionary<ProgramNode, PackedScene> DSLNodes)
|
||||
@@ -178,54 +74,4 @@ public partial class NodeDisplay : PanelContainer
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void LoadHarvest(string content) { }
|
||||
|
||||
public void LoadMove(string content)
|
||||
{
|
||||
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
string[] parts = content.Split(",");
|
||||
string positionValues = parts[1].Replace("Position:", "").Replace("(", "").Replace(")", "").Trim();
|
||||
int posX = int.Parse(positionValues.Split("|")[0]);
|
||||
int posY = int.Parse(positionValues.Split("|")[1]);
|
||||
int posZ = int.Parse(positionValues.Split("|")[2]);
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateX").Value = posX;
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateY").Value = posY;
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateZ").Value = posZ;
|
||||
|
||||
MoveNode moveNode = node as MoveNode;
|
||||
if (moveNode != null)
|
||||
{
|
||||
moveNode.targetPosition = new Vector3I(posX, posY, posZ);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadExplore(string content) { }
|
||||
|
||||
public void LoadCraft(string content)
|
||||
{
|
||||
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
||||
string[] parts = content.Split(",");
|
||||
string itemString = parts[1].Replace("Item:", "").Trim();
|
||||
if (itemString.ToLower() != "empty")
|
||||
{
|
||||
CraftNode craftNode = node as CraftNode;
|
||||
if (craftNode != null)
|
||||
{
|
||||
craftNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
||||
}
|
||||
}
|
||||
string amountString = parts[2].Replace("Amount:", "").Trim();
|
||||
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
||||
}
|
||||
|
||||
public void MoveNodeUp()
|
||||
{
|
||||
EmitSignal(SignalName.OnMoveNode, -1);
|
||||
}
|
||||
|
||||
public void MoveNodeDown()
|
||||
{
|
||||
EmitSignal(SignalName.OnMoveNode, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
using Godot;
|
||||
|
||||
public partial class CraftNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new CraftNode();
|
||||
}
|
||||
|
||||
protected override void LoadContent(NodeDisplay display, string content)
|
||||
{
|
||||
HBoxContainer valueContainer = GetValueContainer(display);
|
||||
string[] parts = content.Split(",");
|
||||
string itemString = parts[1].Replace("Item:", "").Trim();
|
||||
if (itemString.ToLower() != "empty")
|
||||
{
|
||||
CraftNode craftNode = display.node as CraftNode;
|
||||
if (craftNode != null)
|
||||
{
|
||||
craftNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
||||
}
|
||||
}
|
||||
string amountString = parts[2].Replace("Amount:", "").Trim();
|
||||
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
||||
}
|
||||
|
||||
public override void ReadParameters()
|
||||
{
|
||||
CraftNode craftNode = node as CraftNode;
|
||||
if (craftNode == null) return;
|
||||
|
||||
HBoxContainer valueContainer = GetValueContainer();
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
craftNode.selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
craftNode.amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
}
|
||||
|
||||
public override void SetupDisplay()
|
||||
{
|
||||
CraftNode craftNode = node as CraftNode;
|
||||
if (craftNode == null) return;
|
||||
|
||||
OptionButton options = GetValueContainer().GetNode<OptionButton>("./Item");
|
||||
options.Clear();
|
||||
options.AddItem("Select item...");
|
||||
foreach (ItemData item in GameData.availableItems.Values)
|
||||
{
|
||||
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
if (item.Inputs.Count > 0)
|
||||
{
|
||||
options.AddItem(item.GetCraftingDisplay());
|
||||
}
|
||||
}
|
||||
|
||||
if (craftNode.selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == craftNode.selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bfosue8mejnr5
|
||||
@@ -0,0 +1,7 @@
|
||||
public partial class ExploreNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new ExploreNode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bbju8q0es5rcf
|
||||
@@ -0,0 +1,31 @@
|
||||
using Godot;
|
||||
|
||||
public partial class ForNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new ForNode();
|
||||
}
|
||||
|
||||
protected override void LoadContent(NodeDisplay display, string content)
|
||||
{
|
||||
HBoxContainer valueContainer = GetValueContainer(display);
|
||||
string[] parts = content.Split(",");
|
||||
string amountExecuted = parts[1].Replace("AmountExecuted:", "").Trim();
|
||||
ForNode forNode = display.node as ForNode;
|
||||
if (forNode != null)
|
||||
{
|
||||
forNode.amountExecuted = int.Parse(amountExecuted);
|
||||
}
|
||||
string amountString = parts[2].Replace("Amount:", "").Trim();
|
||||
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
||||
}
|
||||
|
||||
public override void ReadParameters()
|
||||
{
|
||||
ForNode forNode = node as ForNode;
|
||||
if (forNode == null) return;
|
||||
|
||||
forNode.amount = (int)GetValueContainer().GetNode<SpinBox>("./Amount").Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://gptqyjv5swwc
|
||||
@@ -0,0 +1,7 @@
|
||||
public partial class HarvestNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new HarvestNode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://u2y14qj6oxyy
|
||||
@@ -0,0 +1,88 @@
|
||||
using Godot;
|
||||
|
||||
public partial class IfNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new IfNode();
|
||||
}
|
||||
|
||||
protected override void LoadContent(NodeDisplay display, string content)
|
||||
{
|
||||
HBoxContainer valueContainer = GetValueContainer(display);
|
||||
string[] parts = content.Split(",");
|
||||
string itemString = parts[1].Replace("Item:", "").Trim();
|
||||
string comparatorString = parts[2].Replace("Comparator:", "").Trim();
|
||||
if (itemString.ToLower() != "empty")
|
||||
{
|
||||
IfNode ifNode = display.node as IfNode;
|
||||
if (ifNode != null)
|
||||
{
|
||||
ifNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
||||
ifNode.comparator = comparatorString;
|
||||
}
|
||||
}
|
||||
string amountString = parts[3].Replace("Amount:", "").Trim();
|
||||
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
||||
}
|
||||
|
||||
public override void ReadParameters()
|
||||
{
|
||||
IfNode ifNode = node as IfNode;
|
||||
if (ifNode == null) return;
|
||||
|
||||
HBoxContainer valueContainer = GetValueContainer();
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
ifNode.selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
ifNode.amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
ifNode.comparator = comparators.GetItemText(comparators.GetSelectedId());
|
||||
}
|
||||
|
||||
public override void SetupDisplay()
|
||||
{
|
||||
IfNode ifNode = node as IfNode;
|
||||
if (ifNode == null) return;
|
||||
|
||||
HBoxContainer valueContainer = GetValueContainer();
|
||||
OptionButton options = valueContainer.GetNode<OptionButton>("./Item");
|
||||
options.Clear();
|
||||
options.AddItem("Select item...");
|
||||
foreach (ItemData item in GameData.availableItems.Values)
|
||||
{
|
||||
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
options.AddItem(item.GetReadableName());
|
||||
}
|
||||
|
||||
if (ifNode.selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == ifNode.selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
|
||||
if (ifNode.comparator != null)
|
||||
{
|
||||
for (int i = 0; i < comparators.ItemCount; i++)
|
||||
{
|
||||
if (comparators.GetItemText(i) == ifNode.comparator)
|
||||
{
|
||||
comparators.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cngxwfcrim746
|
||||
@@ -0,0 +1,7 @@
|
||||
public partial class MaintainNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new MaintainNode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://wfsar5uiexvn
|
||||
@@ -0,0 +1,48 @@
|
||||
using Godot;
|
||||
|
||||
public partial class MoveNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new MoveNode();
|
||||
}
|
||||
|
||||
protected override void LoadContent(NodeDisplay display, string content)
|
||||
{
|
||||
HBoxContainer valueContainer = GetValueContainer(display);
|
||||
string[] parts = content.Split(",");
|
||||
string positionValues = parts[1].Replace("Position:", "").Replace("(", "").Replace(")", "").Trim();
|
||||
int posX = int.Parse(positionValues.Split("|")[0]);
|
||||
int posY = int.Parse(positionValues.Split("|")[1]);
|
||||
int posZ = int.Parse(positionValues.Split("|")[2]);
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateX").Value = posX;
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateY").Value = posY;
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateZ").Value = posZ;
|
||||
|
||||
MoveNode moveNode = display.node as MoveNode;
|
||||
if (moveNode != null)
|
||||
{
|
||||
moveNode.targetPosition = new Vector3I(posX, posY, posZ);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadParameters()
|
||||
{
|
||||
MoveNode moveNode = node as MoveNode;
|
||||
if (moveNode == null) return;
|
||||
|
||||
HBoxContainer valueContainer = GetValueContainer();
|
||||
int posX = (int)valueContainer.GetNode<SpinBox>("./CoordinateX").Value;
|
||||
int posY = (int)valueContainer.GetNode<SpinBox>("./CoordinateY").Value;
|
||||
int posZ = (int)valueContainer.GetNode<SpinBox>("./CoordinateZ").Value;
|
||||
moveNode.targetPosition = new Vector3I(posX, posY, posZ);
|
||||
}
|
||||
|
||||
public override void SetupDisplay()
|
||||
{
|
||||
HBoxContainer valueContainer = GetValueContainer();
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateX").MaxValue = GameData.layerSize;
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateY").MaxValue = GameData.ruinSize;
|
||||
valueContainer.GetNode<SpinBox>("./CoordinateZ").MaxValue = GameData.layerSize;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bucamlwjs0mm2
|
||||
@@ -0,0 +1,7 @@
|
||||
public partial class SacrificeNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new SacrificeNode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cu1nghtcsenfs
|
||||
@@ -0,0 +1,88 @@
|
||||
using Godot;
|
||||
|
||||
public partial class WhileNodeDisplay : NodeDisplay
|
||||
{
|
||||
protected override ProgramNode CreateProgramNode()
|
||||
{
|
||||
return new WhileNode();
|
||||
}
|
||||
|
||||
protected override void LoadContent(NodeDisplay display, string content)
|
||||
{
|
||||
HBoxContainer valueContainer = GetValueContainer(display);
|
||||
string[] parts = content.Split(",");
|
||||
string itemString = parts[1].Replace("Item:", "").Trim();
|
||||
string comparatorString = parts[2].Replace("Comparator:", "").Trim();
|
||||
if (itemString.ToLower() != "empty")
|
||||
{
|
||||
WhileNode whileNode = display.node as WhileNode;
|
||||
if (whileNode != null)
|
||||
{
|
||||
whileNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
||||
whileNode.comparator = comparatorString;
|
||||
}
|
||||
}
|
||||
string amountString = parts[3].Replace("Amount:", "").Trim();
|
||||
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
||||
}
|
||||
|
||||
public override void ReadParameters()
|
||||
{
|
||||
WhileNode whileNode = node as WhileNode;
|
||||
if (whileNode == null) return;
|
||||
|
||||
HBoxContainer valueContainer = GetValueContainer();
|
||||
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
||||
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
||||
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
||||
{
|
||||
whileNode.selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
||||
}
|
||||
whileNode.amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
whileNode.comparator = comparators.GetItemText(comparators.GetSelectedId());
|
||||
}
|
||||
|
||||
public override void SetupDisplay()
|
||||
{
|
||||
WhileNode whileNode = node as WhileNode;
|
||||
if (whileNode == null) return;
|
||||
|
||||
HBoxContainer valueContainer = GetValueContainer();
|
||||
OptionButton options = valueContainer.GetNode<OptionButton>("./Item");
|
||||
options.Clear();
|
||||
options.AddItem("Select item...");
|
||||
foreach (ItemData item in GameData.availableItems.Values)
|
||||
{
|
||||
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
options.AddItem(item.GetReadableName());
|
||||
}
|
||||
|
||||
if (whileNode.selectedItem != null)
|
||||
{
|
||||
for (int i = 0; i < options.ItemCount; i++)
|
||||
{
|
||||
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == whileNode.selectedItem.data.Id)
|
||||
{
|
||||
options.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
|
||||
if (whileNode.comparator != null)
|
||||
{
|
||||
for (int i = 0; i < comparators.ItemCount; i++)
|
||||
{
|
||||
if (comparators.GetItemText(i) == whileNode.comparator)
|
||||
{
|
||||
comparators.Select(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://d3npiur46icru
|
||||
Reference in New Issue
Block a user