78 lines
1.8 KiB
C#
78 lines
1.8 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)
|
|
{
|
|
|
|
}
|
|
|
|
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>();
|
|
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);
|
|
}
|
|
}
|