using Godot; using System; using System.Collections.Generic; public partial class CodingWindow : PanelContainer { [Export] VBoxContainer codeBlocks; [Export] VBoxContainer editorWindow; public Dictionary DSLNodes; Robot robot; // Called when the node enters the scene tree for the first time. public override void _Ready() { DSLNodes = ResourceLoader.LoadDSLNodes(); GenerateCodingBlocks(); } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { } public void ShowWindow(Robot robot) { Visible = true; this.robot = robot; } //Move, Harvest, Craft public void GenerateCodingBlocks() { NodeDisplay nodeDisplay; foreach (ProgramNode node in DSLNodes.Keys) { nodeDisplay = DSLNodes[node].Instantiate(); nodeDisplay.node = node; codeBlocks.AddChild(nodeDisplay); nodeDisplay.ShowListDisplay(); nodeDisplay.listDisplay.Pressed += () => { NodeDisplay editorDisplay = DSLNodes[node].Instantiate(); editorDisplay.node = node; editorWindow.AddChild(editorDisplay); editorDisplay.ShowEditorDisplay(); }; } } public void ClearWindow() { foreach (Node node in editorWindow.GetChildren()) { editorWindow.RemoveChild(node); node.QueueFree(); } } public void CompileProgram() { List nodes = new List(); for (int i = 0; i < editorWindow.GetChildCount(); i++) { editorWindow.GetChild(i).node.ReadParameters(editorWindow.GetChild(i)); nodes.Add(editorWindow.GetChild(i).node.Duplicate()); if (i != 0) { nodes[i-1].nextNode = nodes[i]; } } if(nodes.Count > 0) robot.SetupExecution(nodes); } }