Added ability to delete nodes from editor, added complete node load and save for the DSL

This commit is contained in:
2026-05-06 09:29:28 +02:00
parent 44bfd7ce1d
commit 18b76f3cbc
20 changed files with 451 additions and 84 deletions
+95 -1
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Godot;
public partial class NodeDisplay : PanelContainer
@@ -7,6 +8,9 @@ public partial class NodeDisplay : PanelContainer
[Export] public Button listDisplay;
public ProgramNode node;
[Signal]
public delegate void OnDeleteNodeEventHandler();
public void SetNode(ProgramNode node)
{
this.node = node;
@@ -19,7 +23,7 @@ public partial class NodeDisplay : PanelContainer
public override void _Process(double delta)
{
}
public void ShowListDisplay()
@@ -33,4 +37,94 @@ public partial class NodeDisplay : PanelContainer
editorDisplay.Visible = true;
listDisplay.Visible = false;
}
public void DeleteNodePressed()
{
EmitSignal(SignalName.OnDeleteNode);
}
public static NodeDisplay Load(string content, Dictionary<ProgramNode, PackedScene> DSLNodes)
{
NodeDisplay result = null;
ProgramNode program;
string nodeName;
string nodeSanitized;
PackedScene prefab = null;
nodeSanitized = content.Replace("\r\n", "");
nodeName = nodeSanitized.Split(",")[0].Replace("Name: ", "").ToLower();
foreach (ProgramNode programNode in DSLNodes.Keys)
{
if (programNode.DisplayText.ToLower() == nodeName)
{
prefab = DSLNodes[programNode];
break;
}
}
switch (nodeName)
{
case "move":
program = new MoveNode();
result = prefab.Instantiate<NodeDisplay>();
result.node = program;
result.LoadMove(nodeSanitized);
break;
case "harvest":
program = new HarvestNode();
result = prefab.Instantiate<NodeDisplay>();
result.node = program;
result.LoadHarvest(nodeSanitized);
break;
case "explore":
program = new ExploreNode();
result = prefab.Instantiate<NodeDisplay>();
result.node = program;
result.LoadExplore(nodeSanitized);
break;
case "craft":
program = new CraftNode();
result = prefab.Instantiate<NodeDisplay>();
result.node = program;
result.LoadCraft(nodeSanitized);
break;
}
return result;
}
public void LoadHarvest(string content)
{
//Currently does nothing
}
public void LoadMove(string content)
{
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
string[] parts = content.Split(",");
string positionValues = parts[1].Replace("Position: ", "").Replace("(", "").Replace(")", "");
int posX = int.Parse(positionValues.Split("|")[0]);
int posY = int.Parse(positionValues.Split("|")[1]);
int posZ = int.Parse(positionValues.Split("|")[2]);
valueContainer.GetNode<SpinBox>("./CoordinateX").Value = posX;
valueContainer.GetNode<SpinBox>("./CoordinateY").Value = posY;
valueContainer.GetNode<SpinBox>("./CoordinateZ").Value = posZ;
(node as MoveNode).targetPosition = new Vector3I(posX, posY, posZ);
}
public void LoadExplore(string content)
{
//Currently does nothing
}
public void LoadCraft(string content)
{
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
string[] parts = content.Split(",");
string itemString = parts[1].Replace("Item: ", "").Replace(" ", "");
if (itemString.ToLower() != "empty")
{
(node as CraftNode).selectedItem = new Item { data = GameData.availableItems[itemString] };
}
string amountString = parts[2].Replace("Amount: ", "");
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
}
}