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
+1
View File
@@ -25,6 +25,7 @@ alignment = 1
[node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1994560318] [node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1994560318]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_stretch_ratio = 0.2
text = "Craft: " text = "Craft: "
fit_content = true fit_content = true
autowrap_mode = 0 autowrap_mode = 0
+4
View File
@@ -24,6 +24,8 @@ alignment = 1
[node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1393328640] [node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1393328640]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.2
text = "Harvest: " text = "Harvest: "
fit_content = true fit_content = true
autowrap_mode = 0 autowrap_mode = 0
@@ -32,9 +34,11 @@ vertical_alignment = 1
[node name="Item" type="OptionButton" parent="EditorDisplay/HBoxContainer" unique_id=912931137] [node name="Item" type="OptionButton" parent="EditorDisplay/HBoxContainer" unique_id=912931137]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3
[node name="Amount" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=1234084123] [node name="Amount" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=1234084123]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3
rounded = true rounded = true
alignment = 1 alignment = 1
prefix = "x" prefix = "x"
+85 -55
View File
@@ -30,10 +30,10 @@ bg_color = Color(0.053073194, 0.053073194, 0.053073194, 1)
bg_color = Color(0, 0, 0, 0.7647059) bg_color = Color(0, 0, 0, 0.7647059)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fgofq"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fgofq"]
bg_color = Color(0.64705884, 0.58431375, 0.79607844, 0.5176471) bg_color = Color(0.36567047, 0.46785766, 0.7000103, 0.5176471)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2irst"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2irst"]
bg_color = Color(0.58647984, 0.27039978, 0.75118285, 1) bg_color = Color(0.30085096, 0.39694247, 0.6216495, 0.5176471)
[node name="Main" type="Node3D" unique_id=234207355] [node name="Main" type="Node3D" unique_id=234207355]
@@ -54,7 +54,7 @@ environment = SubResource("Environment_sb48q")
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386] [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386]
follow_viewport_enabled = true follow_viewport_enabled = true
[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "robotNaming", "information", "mainCam")] [node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "information", "mainCam")]
layout_mode = 3 layout_mode = 3
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@@ -68,7 +68,6 @@ size_flags_vertical = 3
script = ExtResource("4_fgofq") script = ExtResource("4_fgofq")
codingWindow = NodePath("MainUI/Content/CodingWindow") codingWindow = NodePath("MainUI/Content/CodingWindow")
robotList = NodePath("MainUI/Content/RobotList") robotList = NodePath("MainUI/Content/RobotList")
robotNaming = NodePath("Popup/RobotNaming")
information = NodePath("Popup/Information") information = NodePath("Popup/Information")
mainCam = NodePath("../../Camera3D") mainCam = NodePath("../../Camera3D")
@@ -122,40 +121,77 @@ layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
[node name="CodingWindow" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1576652491 node_paths=PackedStringArray("codeBlocks", "editorWindow")] [node name="CodingWindow" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1576652491 node_paths=PackedStringArray("codeBlocks", "editorWindow")]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 11 anchors_preset = 11
anchor_left = 1.0 anchor_left = 1.0
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_left = -684.0 offset_left = -524.0
grow_horizontal = 0 grow_horizontal = 0
grow_vertical = 2 grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_7lihs") theme_override_styles/panel = SubResource("StyleBoxFlat_7lihs")
script = ExtResource("6_7lihs") script = ExtResource("6_7lihs")
codeBlocks = NodePath("HBoxContainer/CodeBlocks/VBoxContainer") codeBlocks = NodePath("VBoxContainer/Scripting/CodeBlocks/VBoxContainer")
editorWindow = NodePath("HBoxContainer/EditorWindow/CodeContainer/VBoxContainer") editorWindow = NodePath("VBoxContainer/Scripting/EditorWindow/CodeContainer/VBoxContainer")
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" unique_id=1934932205] [node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" unique_id=582741975]
layout_mode = 2
theme_override_constants/separation = 20
[node name="Title" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer" unique_id=90213926]
layout_mode = 2
bbcode_enabled = true
text = "[font_size=32]Script editor[/font_size]"
fit_content = true
autowrap_mode = 0
horizontal_alignment = 1
[node name="Renaming" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer" unique_id=408911504]
layout_mode = 2
theme_override_constants/separation = 20
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Renaming" unique_id=1964282829]
layout_mode = 2
size_flags_horizontal = 3
text = "Rename your robot:"
fit_content = true
autowrap_mode = 0
horizontal_alignment = 1
vertical_alignment = 1
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Renaming" unique_id=1713423672]
layout_mode = 2
size_flags_horizontal = 3
placeholder_text = "Name..."
max_length = 24
[node name="Button" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Renaming" unique_id=279251707]
layout_mode = 2
size_flags_horizontal = 3
text = "Submit"
[node name="Scripting" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer" unique_id=1934932205]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
[node name="CodeBlocks" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer" unique_id=1196874464] [node name="CodeBlocks" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting" unique_id=1196874464]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_fgofq") theme_override_styles/panel = SubResource("StyleBoxFlat_fgofq")
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/CodeBlocks" unique_id=1751038712] [node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/CodeBlocks" unique_id=1751038712]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
theme_override_constants/separation = 10 theme_override_constants/separation = 10
[node name="EditorWindow" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer" unique_id=919757187] [node name="EditorWindow" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting" unique_id=919757187]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0 size_flags_stretch_ratio = 2.0
[node name="CodeContainer" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=2045306791] [node name="CodeContainer" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow" unique_id=2045306791]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
@@ -163,54 +199,59 @@ size_flags_stretch_ratio = 2.0
theme_override_styles/panel = SubResource("StyleBoxFlat_2irst") theme_override_styles/panel = SubResource("StyleBoxFlat_2irst")
horizontal_scroll_mode = 0 horizontal_scroll_mode = 0
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/CodeContainer" unique_id=632191528] [node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/CodeContainer" unique_id=632191528]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
theme_override_constants/separation = 10 theme_override_constants/separation = 10
[node name="Buttons" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=265797151] [node name="Buttons" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow" unique_id=265797151]
layout_mode = 2 layout_mode = 2
theme_override_constants/separation = 20 theme_override_constants/separation = 20
[node name="Clear" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons" unique_id=1191148341] [node name="Clear" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons" unique_id=1191148341]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
text = "Clear" text = "Clear"
[node name="Compile" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons" unique_id=1559980287] [node name="Compile" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons" unique_id=1559980287]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
text = "Compile" text = "Compile"
[node name="Saving" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=404804163] [node name="Saving" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow" unique_id=404804163]
layout_mode = 2 layout_mode = 2
theme_override_constants/separation = 20 theme_override_constants/separation = 20
[node name="ScriptName" type="LineEdit" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Saving" unique_id=1831524214] [node name="ScriptName" type="LineEdit" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Saving" unique_id=1831524214]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
placeholder_text = "Name..." placeholder_text = "Name..."
max_length = 24 max_length = 24
[node name="Save" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Saving" unique_id=599810254] [node name="Save" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Saving" unique_id=599810254]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
text = "Save" text = "Save"
[node name="Load" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=2064954816] [node name="Load" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow" unique_id=2064954816]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
text = "Load script" text = "Load script"
[node name="Close" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer" unique_id=200541741]
layout_mode = 2
text = "Close"
[node name="RobotList" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1469962195 node_paths=PackedStringArray("robotList")] [node name="RobotList" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1469962195 node_paths=PackedStringArray("robotList")]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = -1 anchors_preset = 11
anchor_left = 0.25 anchor_left = 1.0
anchor_top = 0.25 anchor_right = 1.0
anchor_right = 0.75 anchor_bottom = 1.0
anchor_bottom = 0.75 offset_left = -525.0
grow_horizontal = 2 grow_horizontal = 0
grow_vertical = 2 grow_vertical = 2
script = ExtResource("7_2irst") script = ExtResource("7_2irst")
robotList = NodePath("VBoxContainer/ScrollContainer/VBoxContainer") robotList = NodePath("VBoxContainer/ScrollContainer/VBoxContainer")
@@ -238,6 +279,22 @@ size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
theme_override_constants/separation = 10 theme_override_constants/separation = 10
[node name="FooterContainer" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI" unique_id=1495029884]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/FooterContainer" unique_id=1782436702]
layout_mode = 2
theme_override_constants/separation = 20
alignment = 2
[node name="Robots" type="Button" parent="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer" unique_id=360269454]
layout_mode = 2
text = "Robots (R)"
[node name="Options" type="Button" parent="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer" unique_id=293744135]
layout_mode = 2
text = "Options (ESC)"
[node name="Popup" type="Control" parent="CanvasLayer/UIHandler" unique_id=1989677138] [node name="Popup" type="Control" parent="CanvasLayer/UIHandler" unique_id=1989677138]
layout_mode = 1 layout_mode = 1
anchors_preset = 8 anchors_preset = 8
@@ -252,33 +309,6 @@ offset_bottom = 19.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
[node name="RobotNaming" type="PanelContainer" parent="CanvasLayer/UIHandler/Popup" unique_id=311359170]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/Popup/RobotNaming" unique_id=39200128]
layout_mode = 2
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/UIHandler/Popup/RobotNaming/VBoxContainer" unique_id=1964282829]
layout_mode = 2
text = "Name your robot:"
fit_content = true
autowrap_mode = 0
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/UIHandler/Popup/RobotNaming/VBoxContainer" unique_id=1713423672]
layout_mode = 2
placeholder_text = "Name..."
max_length = 24
[node name="Button" type="Button" parent="CanvasLayer/UIHandler/Popup/RobotNaming/VBoxContainer" unique_id=279251707]
layout_mode = 2
text = "Submit"
[node name="Information" type="PanelContainer" parent="CanvasLayer/UIHandler/Popup" unique_id=1457118246 node_paths=PackedStringArray("title", "content")] [node name="Information" type="PanelContainer" parent="CanvasLayer/UIHandler/Popup" unique_id=1457118246 node_paths=PackedStringArray("title", "content")]
visible = false visible = false
layout_mode = 0 layout_mode = 0
@@ -310,6 +340,6 @@ layout_mode = 2
text = "OK" text = "OK"
[connection signal="color_changed" from="CanvasLayer/UIHandler/MainUI/HeaderContainer/Header/LightColor" to="CanvasLayer/UIHandler" method="ChangeColor"] [connection signal="color_changed" from="CanvasLayer/UIHandler/MainUI/HeaderContainer/Header/LightColor" to="CanvasLayer/UIHandler" method="ChangeColor"]
[connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons/Clear" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="ClearWindow"] [connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons/Clear" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="ClearWindow"]
[connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons/Compile" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="CompileProgram"] [connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons/Compile" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="CompileProgram"]
[connection signal="pressed" from="CanvasLayer/UIHandler/Popup/Information/VBoxContainer/Button" to="CanvasLayer/UIHandler/Popup/Information" method="HideInformation"] [connection signal="pressed" from="CanvasLayer/UIHandler/Popup/Information/VBoxContainer/Button" to="CanvasLayer/UIHandler/Popup/Information" method="HideInformation"]
+15 -17
View File
@@ -7,6 +7,7 @@ public partial class CodingWindow : PanelContainer
[Export] VBoxContainer codeBlocks; [Export] VBoxContainer codeBlocks;
[Export] VBoxContainer editorWindow; [Export] VBoxContainer editorWindow;
public Dictionary<ProgramNode, PackedScene> DSLNodes; public Dictionary<ProgramNode, PackedScene> DSLNodes;
Robot robot;
// Called when the node enters the scene tree for the first time. // 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. // Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) 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 //Move, Harvest, Craft
@@ -57,23 +60,18 @@ public partial class CodingWindow : PanelContainer
public void CompileProgram() public void CompileProgram()
{ {
bool didCompile; List<ProgramNode> nodes = new List<ProgramNode>();
for (int i = 0; i < editorWindow.GetChildCount(); i++) 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)); 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); robot.SetupExecution(nodes);
didCompile = interpreter.Execute(GameData.robots[0]);
if (!didCompile)
{
}
} }
} }
+8 -2
View File
@@ -6,12 +6,12 @@ public class CraftNode : ProgramNode
{ {
DisplayText = "Craft"; DisplayText = "Craft";
} }
public override bool Execute(Robot robot) public override bool Execute(Robot robot, double delta)
{ {
GD.Print("Craft"); GD.Print("Craft");
if (nextNode != null) if (nextNode != null)
{ {
return nextNode.Execute(robot); return nextNode.Execute(robot, delta);
} }
else 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"; DisplayText = "Harvest";
} }
public override bool Execute(Robot robot) public override bool Execute(Robot robot, double delta)
{ {
GD.Print("Harvest"); GD.Print("Harvest");
if (nextNode != null) if (nextNode != null)
{ {
return nextNode.Execute(robot); return nextNode.Execute(robot, delta);
} }
else 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"; 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; startPosition = robot.Position;
GD.Print(targetPosition); Vector3 direction = worldTarget - startPosition;
robot.Position = GameData.map[targetPosition.Y].tiles[targetPosition.X, targetPosition.Z].Position; robot.Translate(direction.Normalized() * (float)delta * GameData.robotSpeed);
if (nextNode != null) float distance = direction.Length();
{ if (distance < 0.1f)
return nextNode.Execute(robot);
}
else
{ {
robot.Position = worldTarget;
return true; return true;
} }
return false;
} }
public override void ReadParameters(NodeDisplay display) public override void ReadParameters(NodeDisplay display)
@@ -34,5 +35,12 @@ public class MoveNode : ProgramNode
targetPosition = new Vector3I(posX, posY, posZ); 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 public abstract class ProgramNode
{ {
protected ProgramNode nextNode; public ProgramNode nextNode;
public string DisplayText; 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 abstract void ReadParameters(NodeDisplay display);
public void LinkNode(ProgramNode nextNode) public abstract ProgramNode Duplicate();
{
this.nextNode = nextNode;
}
} }
-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
+1
View File
@@ -12,6 +12,7 @@ public partial class GameData
public static bool canMove = true; public static bool canMove = true;
public static int maxRobotCount = 1000; public static int maxRobotCount = 1000;
public static List<Robot> robots = new List<Robot>(); public static List<Robot> robots = new List<Robot>();
public static float robotSpeed = 5f;
//--- PLAYER ADJUSTABLE VALUES --- //--- PLAYER ADJUSTABLE VALUES ---
//Color used in primary objects (e.g. Robots) //Color used in primary objects (e.g. Robots)
+4 -21
View File
@@ -6,7 +6,6 @@ public partial class UIHandler : Control
{ {
[Export] CodingWindow codingWindow; [Export] CodingWindow codingWindow;
[Export] RobotList robotList; [Export] RobotList robotList;
[Export] PanelContainer robotNaming;
[Export] Information information; [Export] Information information;
[Export] Camera3D mainCam; [Export] Camera3D mainCam;
public override void _Ready() public override void _Ready()
@@ -19,7 +18,8 @@ public partial class UIHandler : Control
{ {
robotList.OnRobotJumpTo += (robot) => robotList.OnRobotJumpTo += (robot) =>
{ {
mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z); mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z + 3f);
ShowCodingWindow(robot);
}; };
} }
@@ -29,25 +29,8 @@ public partial class UIHandler : Control
LightHandler.RedrawLights(color); LightHandler.RedrawLights(color);
} }
public void ShowNamingPopup(Robot robot) public void ShowCodingWindow(Robot robot)
{ {
robotNaming.Visible = true; codingWindow.ShowWindow(robot);
GameData.canMove = false;
LineEdit name = robotNaming.GetNode<LineEdit>("./VBoxContainer/LineEdit");
name.Text = robot.Name;
Button button = robotNaming.GetNode<Button>("./VBoxContainer/Button");
Action handler = null;
handler = () =>
{
robot.Name = name.Text;
name.Text = "";
robotNaming.Visible = false;
GameData.canMove = true;
button.ButtonUp -= handler;
};
button.ButtonUp += handler;
} }
} }
+25 -4
View File
@@ -1,18 +1,32 @@
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Godot; using Godot;
public partial class Robot : Node3D public partial class Robot : Node3D
{ {
public ProgramInterpreter interpreter; List<ProgramNode> nodes;
bool isExecuting = false;
ProgramNode currentNode;
public override void _Ready() public override void _Ready()
{ {
} }
public override void _Process(double delta) public override void _Process(double delta)
{ {
if (isExecuting)
{
if (currentNode.Execute(this, delta))
{
currentNode = currentNode.nextNode;
if (currentNode == null)
{
isExecuting = false;
}
}
}
} }
public void Move() public void Move()
{ {
@@ -21,7 +35,14 @@ public partial class Robot : Node3D
public void OnClicked() public void OnClicked()
{ {
GetNode<UIHandler>("/root/Main/CanvasLayer/UIHandler").ShowNamingPopup(this); GetNode<UIHandler>("/root/Main/CanvasLayer/UIHandler").ShowCodingWindow(this);
}
public void SetupExecution(List<ProgramNode> nodes)
{
this.nodes = [.. nodes];
isExecuting = true;
currentNode = nodes[0];
} }
} }
+1
View File
@@ -40,6 +40,7 @@ public partial class RobotList : PanelContainer
display.OnRobotJumpTo += (robot) => display.OnRobotJumpTo += (robot) =>
{ {
EmitSignal(SignalName.OnRobotJumpTo, robot); EmitSignal(SignalName.OnRobotJumpTo, robot);
Visible = false;
}; };
robotList.AddChild(display); robotList.AddChild(display);
} }