using System.Collections.Generic; using Godot; public partial class NodeDisplay : GraphNode { public ProgramNode node; [Signal] public delegate void OnDeleteNodeEventHandler(); public override void _Ready() { if (node == null) { node = CreateProgramNode(); } if (node == null) return; SetupDisplay(); } public void DeleteNodePressed() { EmitSignal(SignalName.OnDeleteNode); } public static NodeDisplay Load(string content, Dictionary DSLNodes) { string nodeSanitized = content.Replace("\r\n", "").Trim(); if (nodeSanitized.Length <= 0) return null; string nodeName = nodeSanitized.Split(",")[0].Replace("Name: ", "").ToLower(); PackedScene prefab = GetPrefab(nodeName, 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; } }