588879951d
Readded node deletion.
74 lines
1.5 KiB
C#
74 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using Godot;
|
|
|
|
public partial class NodeDisplay : GraphNode
|
|
{
|
|
public ProgramNode node;
|
|
|
|
public override void _Ready()
|
|
{
|
|
if (node == null)
|
|
{
|
|
node = CreateProgramNode();
|
|
}
|
|
|
|
if (node == null) return;
|
|
|
|
SetupDisplay();
|
|
}
|
|
|
|
public static NodeDisplay Load(
|
|
string nodeName,
|
|
string content,
|
|
Dictionary<ProgramNode, PackedScene> DSLNodes
|
|
)
|
|
{
|
|
string nodeSanitized = content.Replace("\r\n", "").Trim();
|
|
if (nodeSanitized.Length <= 0) return null;
|
|
string normalizedNodeName = nodeName.Trim().ToLower();
|
|
|
|
PackedScene prefab = GetPrefab(normalizedNodeName, DSLNodes);
|
|
if (prefab == null) return null;
|
|
|
|
NodeDisplay result = prefab.Instantiate<NodeDisplay>();
|
|
result.node = result.CreateProgramNode();
|
|
result.LoadContent(result, nodeSanitized);
|
|
|
|
return result;
|
|
}
|
|
|
|
protected virtual ProgramNode CreateProgramNode()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
protected virtual void LoadContent(NodeDisplay display, string content) { }
|
|
|
|
public virtual void SetupDisplay() { }
|
|
|
|
public virtual void ReadParameters() { }
|
|
|
|
public HBoxContainer GetValueContainer()
|
|
{
|
|
return GetNode<HBoxContainer>("./Values");
|
|
}
|
|
|
|
protected HBoxContainer GetValueContainer(NodeDisplay display)
|
|
{
|
|
return display.GetValueContainer();
|
|
}
|
|
|
|
private static PackedScene GetPrefab(string nodeName, Dictionary<ProgramNode, PackedScene> DSLNodes)
|
|
{
|
|
foreach (ProgramNode programNode in DSLNodes.Keys)
|
|
{
|
|
if (programNode.DisplayText.ToLower() == nodeName)
|
|
{
|
|
return DSLNodes[programNode];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|