102 lines
2.5 KiB
C#
102 lines
2.5 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public partial class TestRunner
|
|
{
|
|
private Layer CreateTestLayer(int level, string collapsedMesh)
|
|
{
|
|
Layer layer = new Layer
|
|
{
|
|
level = level,
|
|
currentResources = new List<string> { "stone" },
|
|
gateIngredients = new List<Ingredient>(),
|
|
tiles = new Tile[1, 1]
|
|
};
|
|
|
|
Tile tile = new Tile
|
|
{
|
|
GridPosition = new Vector2I(0, 0),
|
|
Position = Vector3.Zero,
|
|
collapsedMesh = collapsedMesh,
|
|
containsResource = true,
|
|
resource = new GameResource("stone")
|
|
};
|
|
|
|
layer.tiles[0, 0] = tile;
|
|
return layer;
|
|
}
|
|
|
|
private bool IsGeneratedLayerValid(Layer layer)
|
|
{
|
|
bool hasGate = false;
|
|
|
|
foreach (Tile tile in layer.tiles)
|
|
{
|
|
if (tile.collapsedMesh == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (tile.collapsedMesh == "gate")
|
|
{
|
|
hasGate = true;
|
|
}
|
|
}
|
|
|
|
if (!hasGate)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
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)
|
|
{
|
|
throw new Exception(message);
|
|
}
|
|
}
|
|
|
|
private void AssertFalse(bool value, string message)
|
|
{
|
|
if (value)
|
|
{
|
|
throw new Exception(message);
|
|
}
|
|
}
|
|
|
|
private void AssertEqual<T>(T expected, T actual, string message)
|
|
{
|
|
if (!EqualityComparer<T>.Default.Equals(expected, actual))
|
|
{
|
|
throw new Exception($"{message}: expected {expected}, got {actual}");
|
|
}
|
|
}
|
|
|
|
private void AssertClose(float expected, float actual, float tolerance, string message)
|
|
{
|
|
if (Math.Abs(expected - actual) > tolerance)
|
|
{
|
|
throw new Exception($"{message}: expected {expected}, got {actual}");
|
|
}
|
|
}
|
|
}
|