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 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(); 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("./Values"); } protected HBoxContainer GetValueContainer(NodeDisplay display) { return display.GetValueContainer(); } private static PackedScene GetPrefab(string nodeName, Dictionary DSLNodes) { foreach (ProgramNode programNode in DSLNodes.Keys) { if (programNode.DisplayText.ToLower() == nodeName) { return DSLNodes[programNode]; } } return null; } }