diff --git a/Scripts/Gameplay/Robots/Robot.cs b/Scripts/Gameplay/Robots/Robot.cs index 8dfadb6..d2b32b6 100644 --- a/Scripts/Gameplay/Robots/Robot.cs +++ b/Scripts/Gameplay/Robots/Robot.cs @@ -12,8 +12,8 @@ public partial class Robot : Node3D private const float MaintenanceLossPerSecond = 0.025f; private bool isExecuting = false; - private ProgramNode currentNode; + public ProgramNode currentNode; public string currentProgram; public string currentMessage = ""; public float heat = 0f; diff --git a/Scripts/UI/DSL/CodingWindow.cs b/Scripts/UI/DSL/CodingWindow.cs index c8cb9ff..9c1508c 100644 --- a/Scripts/UI/DSL/CodingWindow.cs +++ b/Scripts/UI/DSL/CodingWindow.cs @@ -34,6 +34,7 @@ public partial class CodingWindow : PanelContainer nameInput.Text = robot.Name; SetupScriptOptions(); ClearWindow(); + LoadTemporaryProgram(); } private void SetupScriptOptions() @@ -162,6 +163,50 @@ public partial class CodingWindow : PanelContainer availableScripts.Select(0); } + public void LoadTemporaryProgram() + { + if (robot == null) return; + if (robot.currentNode == null) return; + + ProgramNode firstNode = robot.currentNode; + while (firstNode.previousNode != null) + { + firstNode = firstNode.previousNode; + } + + HashSet loadedNodes = new HashSet(); + ProgramNode nodeToLoad = firstNode; + while (nodeToLoad != null && !loadedNodes.Contains(nodeToLoad)) + { + loadedNodes.Add(nodeToLoad); + + NodeDisplay nodeDisplay = NodeDisplay.Load(nodeToLoad.Save(), DSLNodes); + 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); + }; + } + + nodeToLoad = nodeToLoad.nextNode; + } + + scriptName.Text = robot.currentProgram ?? ""; + } + public void DeleteProgram() { string filename = scriptName.Text;