Files
RuinAdventurer/Scripts/DSL/CodingWindow.cs
T
2026-05-05 20:21:05 +02:00

77 lines
1.7 KiB
C#

using Godot;
using System;
using System.Collections.Generic;
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.
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)
{
}
//Move, Harvest, Craft
public void GenerateCodingBlocks()
{
NodeDisplay nodeDisplay;
foreach (ProgramNode node in DSLNodes.Keys)
{
nodeDisplay = DSLNodes[node].Instantiate<NodeDisplay>();
nodeDisplay.node = node;
codeBlocks.AddChild(nodeDisplay);
nodeDisplay.ShowListDisplay();
nodeDisplay.listDisplay.Pressed += () =>
{
NodeDisplay editorDisplay = DSLNodes[node].Instantiate<NodeDisplay>();
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<ProgramNode> nodes = new List<ProgramNode>();
for (int i = 0; i < editorWindow.GetChildCount(); 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];
}
}
if(nodes.Count > 0) robot.SetupExecution(nodes);
}
public void SetRobot(Robot robot)
{
this.robot = robot;
}
}