(WIP) switched from previous DSL System (UI order based) to a new DSL System (node connection based)
This commit is contained in:
+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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user