Reworked node display and worked on DSL interpretation

This commit is contained in:
=
2026-04-29 12:12:58 +02:00
parent 2cc6e31157
commit 2f922b5e04
14 changed files with 270 additions and 54 deletions
+26 -9
View File
@@ -9,6 +9,8 @@ public partial class CodingWindow : PanelContainer
[Export] VBoxContainer robotList;
[Signal]
public delegate void OnRobotClickedEventHandler(Robot robot);
[Signal]
public delegate void OnInformationEventHandler(string title, string text);
public Dictionary<ProgramNode, PackedScene> DSLNodes;
// Called when the node enters the scene tree for the first time.
@@ -35,19 +37,20 @@ public partial class CodingWindow : PanelContainer
//Move, Harvest, Craft
public void GenerateCodingBlocks()
{
Button button;
NodeDisplay nodeDisplay;
foreach (ProgramNode node in DSLNodes.Keys)
{
button = new Button
nodeDisplay = DSLNodes[node].Instantiate<NodeDisplay>();
nodeDisplay.node = node;
codeBlocks.AddChild(nodeDisplay);
nodeDisplay.ShowListDisplay();
nodeDisplay.listDisplay.Pressed += () =>
{
Text = node.DisplayText,
Name = node.DisplayText
NodeDisplay editorDisplay = DSLNodes[node].Instantiate<NodeDisplay>();
editorDisplay.node = node;
editorWindow.AddChild(editorDisplay);
editorDisplay.ShowEditorDisplay();
};
button.Pressed += () =>
{
editorWindow.AddChild(DSLNodes[node].Instantiate());
};
codeBlocks.AddChild(button);
}
}
@@ -86,6 +89,20 @@ public partial class CodingWindow : PanelContainer
public void CompileProgram()
{
string errorMessage = "";
bool didCompile;
for (int i = 1; i < editorWindow.GetChildCount(); i++)
{
editorWindow.GetChild<NodeDisplay>(i - 1).node.LinkNode(editorWindow.GetChild<NodeDisplay>(i).node);
}
ProgramInterpreter interpreter = new ProgramInterpreter(editorWindow.GetChild<NodeDisplay>(0).node);
didCompile = interpreter.Execute(GameData.robots[0]);
if (!didCompile)
{
EmitSignal(SignalName.OnInformation, "ERROR", "Compilation failed " + errorMessage);
}
}
}
+31 -20
View File
@@ -1,30 +1,41 @@
using System;
using Godot;
public partial class NodeDisplay : RichTextLabel
public partial class NodeDisplay : PanelContainer
{
ProgramNode node;
[Export] PanelContainer editorDisplay;
[Export] public Button listDisplay;
public ProgramNode node;
public void SetNode(ProgramNode node)
{
this.node = node;
}
public void SetNode(ProgramNode node)
{
this.node = node;
}
public void SetupUIElement()
{
}
public void SetupUIElement()
{
}
public override void _Ready()
{
public override void _Ready()
{
}
}
public override void _Process(double delta)
{
if (Input.IsActionJustPressed("left_click"))
{
public override void _Process(double delta)
{
}
}
}
}
public void ShowListDisplay()
{
editorDisplay.Visible = false;
listDisplay.Visible = true;
}
public void ShowEditorDisplay()
{
editorDisplay.Visible = true;
listDisplay.Visible = false;
}
}
+9 -2
View File
@@ -6,9 +6,16 @@ public class CraftNode : ProgramNode
{
DisplayText = "Craft";
}
public override void Execute(Robot robot)
public override bool Execute(Robot robot)
{
GD.Print("Craft");
nextNode.Execute(robot);
if (nextNode != null)
{
return nextNode.Execute(robot);
}
else
{
return true;
}
}
}
+9 -2
View File
@@ -6,9 +6,16 @@ public class HarvestNode : ProgramNode
{
DisplayText = "Harvest";
}
public override void Execute(Robot robot)
public override bool Execute(Robot robot)
{
GD.Print("Harvest");
nextNode.Execute(robot);
if (nextNode != null)
{
return nextNode.Execute(robot);
}
else
{
return true;
}
}
}
+9 -2
View File
@@ -8,9 +8,16 @@ public class MoveNode : ProgramNode
{
DisplayText = "Move";
}
public override void Execute(Robot robot)
public override bool Execute(Robot robot)
{
robot.Position = targetPosition;
nextNode.Execute(robot);
if (nextNode != null)
{
return nextNode.Execute(robot);
}
else
{
return true;
}
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ public abstract class ProgramNode
}
public abstract void Execute(Robot robot);
public abstract bool Execute(Robot robot);
public void LinkNode(ProgramNode nextNode)
{
this.nextNode = nextNode;
+18
View File
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using Godot;
public class ProgramInterpreter
{
ProgramNode startNode;
public ProgramInterpreter(ProgramNode startNode)
{
this.startNode = startNode;
}
public bool Execute(Robot robot)
{
return startNode.Execute(robot);
}
}