using Godot; using System; using System.Collections.Generic; public partial class CodingWindow : PanelContainer { [Export] VBoxContainer codeBlocks; [Export] VBoxContainer editorWindow; public Dictionary DSLNodes; // 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) { //TODO: If robot that was pressed has a script, load script if (Input.IsActionJustPressed("codingwindow")) { Visible = !Visible; } } //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() { bool didCompile; for (int i = 0; i < editorWindow.GetChildCount(); i++) { if (i + 1 < editorWindow.GetChildCount()) { editorWindow.GetChild(i).node.LinkNode(editorWindow.GetChild(i + 1).node); } editorWindow.GetChild(i).node.ReadParameters(editorWindow.GetChild(i)); } ProgramInterpreter interpreter = new ProgramInterpreter(editorWindow.GetChild(0).node); didCompile = interpreter.Execute(GameData.robots[0]); if (!didCompile) { } } }