Finished new node approach

This commit is contained in:
2026-05-14 09:58:35 +02:00
parent 33a618b0b9
commit bd6cdeb97b
5 changed files with 332 additions and 48 deletions
+73 -1
View File
@@ -36,6 +36,8 @@ public partial class TestRunner : Node
Run("While node reports false conditions", TestWhileNodeReportsFalseConditions);
Run("For node stops after configured amount", TestForNodeStopsAfterConfiguredAmount);
Run("Start node succeeds immediately", TestStartNodeSucceedsImmediately);
Run("Split node connections restore both branches", TestSplitNodeConnectionsRestoreBothBranches);
Run("Linear node connection restores next node", TestLinearNodeConnectionRestoresNextNode);
Run("Paused world does not drain survival", TestPausedWorldDoesNotDrainSurvival);
Run("Open gate hides gate content", TestOpenGateHidesGateContent);
Run("Layer generation succeeds above threshold", TestLayerGenerationSuccessRate);
@@ -372,7 +374,7 @@ public partial class TestRunner : Node
private void TestSavedScriptsCanBeDeleted()
{
string scriptName = "delete_test_script";
FileHandler.SaveProgram(scriptName, "Name: Explore;");
FileHandler.SaveProgram(scriptName, "{\"Nodes\":[],\"Connections\":[]}");
AssertTrue(FileHandler.LoadProgramNames().Contains(scriptName), "script should be listed");
AssertTrue(FileHandler.DeleteProgram(scriptName), "delete should succeed");
@@ -485,6 +487,61 @@ public partial class TestRunner : Node
AssertEqual("Name: Start", node.Save(), "start save");
}
private void TestSplitNodeConnectionsRestoreBothBranches()
{
MoveNode successNode = new MoveNode();
MoveNode negativeNode = new MoveNode();
System.Collections.Generic.Dictionary<StringName, ProgramNode> availableNodes =
new System.Collections.Generic.Dictionary<StringName, ProgramNode>
{
{ new StringName("success"), successNode },
{ new StringName("negative"), negativeNode }
};
List<Godot.Collections.Dictionary> connections = new List<Godot.Collections.Dictionary>
{
CreateConnection("split", 0, "success", 0),
CreateConnection("split", 1, "negative", 0)
};
IfNode ifNode = new IfNode();
ifNode.SetNextNode(connections, availableNodes);
AssertTrue(ReferenceEquals(successNode, ifNode.nextNode), "if success branch");
AssertTrue(ReferenceEquals(negativeNode, ifNode.NegativeNode), "if negative branch");
WhileNode whileNode = new WhileNode();
whileNode.SetNextNode(connections, availableNodes);
AssertTrue(ReferenceEquals(successNode, whileNode.nextNode), "while success branch");
AssertTrue(ReferenceEquals(negativeNode, whileNode.NegativeNode), "while negative branch");
ForNode forNode = new ForNode();
forNode.SetNextNode(connections, availableNodes);
AssertTrue(ReferenceEquals(successNode, forNode.nextNode), "for success branch");
AssertTrue(ReferenceEquals(negativeNode, forNode.NegativeNode), "for negative branch");
}
private void TestLinearNodeConnectionRestoresNextNode()
{
MoveNode targetNode = new MoveNode();
StartNode startNode = new StartNode();
System.Collections.Generic.Dictionary<StringName, ProgramNode> availableNodes =
new System.Collections.Generic.Dictionary<StringName, ProgramNode>
{
{ new StringName("target"), targetNode }
};
List<Godot.Collections.Dictionary> connections = new List<Godot.Collections.Dictionary>
{
CreateConnection("start", 0, "target", 0)
};
startNode.SetNextNode(connections, availableNodes);
AssertTrue(ReferenceEquals(targetNode, startNode.nextNode), "linear next node");
AssertTrue(startNode.NegativeNode == null, "linear node should not have negative branch");
}
private void TestPausedWorldDoesNotDrainSurvival()
{
GameData.isPaused = true;
@@ -620,6 +677,21 @@ public partial class TestRunner : Node
return WFC.IsMapConnected(layer.tiles, 1f);
}
private Godot.Collections.Dictionary CreateConnection(
string fromNode,
int fromPort,
string toNode,
int toPort
)
{
Godot.Collections.Dictionary connection = new Godot.Collections.Dictionary();
connection["from_node"] = new StringName(fromNode);
connection["from_port"] = fromPort;
connection["to_node"] = new StringName(toNode);
connection["to_port"] = toPort;
return connection;
}
private void AssertTrue(bool value, string message)
{
if (!value)