Reworked DSL for better architecture, implemented wall-phasing movement.

This commit is contained in:
=
2026-04-29 15:13:38 +02:00
parent 832fb47ec0
commit a0109891e1
14 changed files with 172 additions and 139 deletions
+15 -17
View File
@@ -7,6 +7,7 @@ public partial class CodingWindow : PanelContainer
[Export] VBoxContainer codeBlocks;
[Export] VBoxContainer editorWindow;
public Dictionary<ProgramNode, PackedScene> DSLNodes;
Robot robot;
// Called when the node enters the scene tree for the first time.
@@ -19,11 +20,13 @@ public partial class CodingWindow : PanelContainer
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
//TODO: If robot that was pressed has a script, load script
if (Input.IsActionJustPressed("codingwindow"))
{
Visible = !Visible;
}
}
public void ShowWindow(Robot robot)
{
Visible = true;
this.robot = robot;
}
//Move, Harvest, Craft
@@ -57,23 +60,18 @@ public partial class CodingWindow : PanelContainer
public void CompileProgram()
{
bool didCompile;
List<ProgramNode> nodes = new List<ProgramNode>();
for (int i = 0; i < editorWindow.GetChildCount(); i++)
{
if (i + 1 < editorWindow.GetChildCount())
{
editorWindow.GetChild<NodeDisplay>(i).node.LinkNode(editorWindow.GetChild<NodeDisplay>(i + 1).node);
}
editorWindow.GetChild<NodeDisplay>(i).node.ReadParameters(editorWindow.GetChild<NodeDisplay>(i));
nodes.Add(editorWindow.GetChild<NodeDisplay>(i).node.Duplicate());
if (i != 0)
{
nodes[i-1].nextNode = nodes[i];
}
}
ProgramInterpreter interpreter = new ProgramInterpreter(editorWindow.GetChild<NodeDisplay>(0).node);
didCompile = interpreter.Execute(GameData.robots[0]);
if (!didCompile)
{
}
robot.SetupExecution(nodes);
}
}
+8 -2
View File
@@ -6,12 +6,12 @@ public class CraftNode : ProgramNode
{
DisplayText = "Craft";
}
public override bool Execute(Robot robot)
public override bool Execute(Robot robot, double delta)
{
GD.Print("Craft");
if (nextNode != null)
{
return nextNode.Execute(robot);
return nextNode.Execute(robot, delta);
}
else
{
@@ -23,4 +23,10 @@ public class CraftNode : ProgramNode
{
//
}
public override ProgramNode Duplicate()
{
CraftNode duplicate = new CraftNode();
return duplicate;
}
}
+8 -2
View File
@@ -6,12 +6,12 @@ public class HarvestNode : ProgramNode
{
DisplayText = "Harvest";
}
public override bool Execute(Robot robot)
public override bool Execute(Robot robot, double delta)
{
GD.Print("Harvest");
if (nextNode != null)
{
return nextNode.Execute(robot);
return nextNode.Execute(robot, delta);
}
else
{
@@ -23,4 +23,10 @@ public class HarvestNode : ProgramNode
{
//
}
public override ProgramNode Duplicate()
{
HarvestNode duplicate = new HarvestNode();
return duplicate;
}
}
+17 -9
View File
@@ -8,19 +8,20 @@ public class MoveNode : ProgramNode
{
DisplayText = "Move";
}
public override bool Execute(Robot robot)
public override bool Execute(Robot robot, double delta)
{
Vector3 worldTarget = GameData.map[targetPosition.Y].tiles[targetPosition.X, targetPosition.Z].Position;
GD.Print(startPosition + "/" + worldTarget);
startPosition = robot.Position;
GD.Print(targetPosition);
robot.Position = GameData.map[targetPosition.Y].tiles[targetPosition.X, targetPosition.Z].Position;
if (nextNode != null)
{
return nextNode.Execute(robot);
}
else
Vector3 direction = worldTarget - startPosition;
robot.Translate(direction.Normalized() * (float)delta * GameData.robotSpeed);
float distance = direction.Length();
if (distance < 0.1f)
{
robot.Position = worldTarget;
return true;
}
return false;
}
public override void ReadParameters(NodeDisplay display)
@@ -34,5 +35,12 @@ public class MoveNode : ProgramNode
targetPosition = new Vector3I(posX, posY, posZ);
}
public override ProgramNode Duplicate()
{
MoveNode duplicate = new MoveNode
{
targetPosition = targetPosition
};
return duplicate;
}
}
+3 -10
View File
@@ -2,17 +2,10 @@ using Godot;
public abstract class ProgramNode
{
protected ProgramNode nextNode;
public ProgramNode nextNode;
public string DisplayText;
public ProgramNode()
{
}
public abstract bool Execute(Robot robot);
public abstract bool Execute(Robot robot, double delta);
public abstract void ReadParameters(NodeDisplay display);
public void LinkNode(ProgramNode nextNode)
{
this.nextNode = nextNode;
}
public abstract ProgramNode Duplicate();
}
-18
View File
@@ -1,18 +0,0 @@
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);
}
}
-1
View File
@@ -1 +0,0 @@
uid://hui5wolo5rbr