80 lines
1.9 KiB
C#
80 lines
1.9 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;
|
|
|
|
|
|
// 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>();
|
|
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()
|
|
{
|
|
bool didCompile;
|
|
|
|
for (int i = 0; i < editorWindow.GetChildCount(); i++)
|
|
{
|
|
if (i + 1 < editorWindow.GetChildCount())
|
|
{
|
|
editorWindow.GetChild<NodeDisplay>(i).node.LinkNode(editorWindow.GetChild<NodeDisplay>(i + 1).node);
|
|
}
|
|
editorWindow.GetChild<NodeDisplay>(i).node.ReadParameters(editorWindow.GetChild<NodeDisplay>(i));
|
|
}
|
|
|
|
ProgramInterpreter interpreter = new ProgramInterpreter(editorWindow.GetChild<NodeDisplay>(0).node);
|
|
didCompile = interpreter.Execute(GameData.robots[0]);
|
|
|
|
if (!didCompile)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|