Skip to content

Commit 1a60fe8

Browse files
committed
- using consistent naming
- improved YAML import/export
1 parent ac23f4b commit 1a60fe8

30 files changed

+255
-225
lines changed

GDT.Test/source/Tests/IOTests/YamlLoaderTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void TestParseChildren()
5151
Graph graph = YamlGraphStorage.LoadGraph(content);
5252

5353
Assert.AreEqual("LocationGraph", graph.Name, "Graph name not correct. Probably error in parser!");
54-
Entity? kalimdor = graph.GetNode("Kalimdor");
54+
Entity? kalimdor = graph.GetEntity("Kalimdor");
5555
Assert.NotNull(kalimdor, "Expected 'Kalimdor' to be in the node list!");
5656
Entity? orgrimmar = kalimdor?.GetChild("Orgrimmar");
5757
Assert.NotNull(orgrimmar, "Expected 'Orgrimmar' to be a child of Kalimdor!");
@@ -68,9 +68,9 @@ public void TestParseReferencedNodes()
6868
Assert.NotNull(zeppelin, "Expected 'Zeppelin Connections' to be a layer!");
6969
Relation? ogUCRelation = zeppelin?.GetRelation("OG-UC");
7070
Assert.NotNull(ogUCRelation, "Expected 'OG-UC' to be a relation in the Zeppelin Layer!");
71-
Entity? orgrimmar = ogUCRelation?.GetNode("Orgrimmar");
71+
Entity? orgrimmar = ogUCRelation?.GetEntity("Orgrimmar");
7272
Assert.NotNull(orgrimmar, "Expected Orgrimmar to be in the OG-UC relation");
73-
Entity? uc = ogUCRelation?.GetNode("Undercity");
73+
Entity? uc = ogUCRelation?.GetEntity("Undercity");
7474
Assert.NotNull(uc, "Expected Undercity to be in the OG-UC relation");
7575
}
7676

@@ -80,7 +80,7 @@ public void TestParseComponents()
8080
string content = FileUtilities.LoadFile("graph_with_layers.yaml");
8181
Graph graph = YamlGraphStorage.LoadGraph(content);
8282

83-
Entity? stormwind = graph.GetNode("Stormwind");
83+
Entity? stormwind = graph.GetEntity("Stormwind");
8484
Assert.NotNull(stormwind, "Expected to find 'Stormwind' in the graph");
8585

8686
EntityComponent? cityComponent = stormwind?.GetComponent("City");

GDT.Test/source/Tests/IOTests/YamlStorageTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,36 @@ public void TestSaveGraph()
7575
Assert.NotNull(zl, "Expected to find the zeppelin layer!");
7676
}
7777

78+
[Test]
79+
public void TestSaveAttributes()
80+
{
81+
Graph entityGraph = new ("ComponentGraphTest");
82+
Entity entity = new ("Entity with Component", entityGraph);
83+
EntityComponent entityComponent = new("TestComponent");
84+
entityComponent.SetProperty("int", 12);
85+
entityComponent.SetProperty("long", 15213L);
86+
entityComponent.SetProperty("enum", Biome.Forest);
87+
entityComponent.SetProperty("list", new List<int>() { 1,2,3,4,5,6});
88+
entity.Components.Add(entityComponent);
89+
90+
entityGraph.Entities.Add(entity);
91+
92+
93+
string content = YamlGraphStorage.SaveGraph(entityGraph);
94+
FileUtilities.WriteFile("graph_with_entity.yaml", "./", content);
95+
96+
// test save and load in the same order
97+
Graph g = YamlGraphStorage.LoadGraph(content);
98+
Entity? e = g.GetEntity("Entity with Component");
99+
Assert.NotNull(e, "Expected to find 'Entity with Component'");
100+
EntityComponent? comp = e?.GetComponent("TestComponent");
101+
Assert.NotNull(comp, "Expected to find 'TestComponent'");
102+
103+
Assert.AreEqual(comp?.Get<int>("int"), 12, "int property to be 12");
104+
Assert.AreEqual(comp?.Get<Biome>("enum"), Biome.Forest, "enum property to be Forest");
105+
Assert.AreEqual(comp?.Get<List<int>>("list"), new List<int>() { 1,2,3,4,5,6}, "list property to be 1,2,3,4,5,6");
106+
}
107+
78108
[Test]
79109
public void TestGenerateSimpleGraphSpace()
80110
{

GDT.Test/source/Tests/PipelineTests/IslandsGenerationTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void IslandPipelineTest()
2828
float voronoiRadius = islandSize * 0.15f;
2929
string zoneLayerName = "ZoneLayer";
3030

31-
pipeline.AddStep(new PoissonLocationsAsNodesPipelineStep(islandSize, new(islandSize / 2, islandSize / 2),
31+
pipeline.AddStep(new PoissonLocationsAsEntitiesPipelineStep(islandSize, new(islandSize / 2, islandSize / 2),
3232
worldRegion - new Vector2(islandSize, islandSize), null, 60));
3333
pipeline.AddStep(SetupIslandVisualizationStep(worldRegion, islandSize));
3434
pipeline.AddStep(new IslandTypeAssignment(worldRegion / 2));
@@ -66,7 +66,7 @@ private static Color MapBiomeToColor(Biome biome)
6666
case Biome.Grassland: return Color.LimeGreen;
6767
case Biome.Mountain: return Color.LightBlue;
6868
case Biome.Sea: return Color.DodgerBlue;
69-
case Biome.Forrest: return Color.DarkGreen;
69+
case Biome.Forest: return Color.DarkGreen;
7070
case Biome.Swamp: return Color.DarkGoldenrod;
7171
case Biome.Unassigned: return Color.Purple;
7272
}
@@ -121,7 +121,7 @@ private AreaVisualizationStep SetupIslandShapeVisualizationStep(Vector2 region,
121121
Layer? zoneLayer = graph.GetLayer(layerName);
122122
if(zoneLayer == null) throw new ArgumentNullException($"{zoneLayer} doesnt contain nodes");
123123

124-
return zoneLayer.GetNodesInLayer().ToList();
124+
return zoneLayer.GetEntitiesInLayer().ToList();
125125
},
126126
backgroundColor: MapBiomeToColor(Biome.Sea));
127127
}
@@ -143,7 +143,7 @@ private AreaVisualizationStep SetupIslandZonesVisualizationStep(Vector2 region,
143143
Layer? zoneLayer = graph.GetLayer(layerName);
144144
if(zoneLayer == null) throw new ArgumentNullException($"{zoneLayer} doesnt contain nodes");
145145

146-
return zoneLayer.GetNodesInLayer().ToList();
146+
return zoneLayer.GetEntitiesInLayer().ToList();
147147
},
148148
backgroundColor: MapBiomeToColor(Biome.Sea));
149149
}

GDT.Test/source/Tests/PipelineTests/Steps/AreaTileConnectorStep.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public Graph ExecuteStep(Graph graph)
3636

3737
private void ConnectChildren(Relation parentRelation, Layer childLayer)
3838
{
39-
var np0 = parentRelation.Nodes[0];
40-
var np1 = parentRelation.Nodes[1];
39+
var np0 = parentRelation.Entities[0];
40+
var np1 = parentRelation.Entities[1];
4141

4242
var cp0 = FindRandomUnconnectedChildNode(np0, childLayer);
4343
var cp1 = FindRandomUnconnectedChildNode(np1, childLayer);

GDT.Test/source/Tests/PipelineTests/Steps/AreaTilesStep.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Graph ExecuteStep(Graph graph)
2525

2626
var newLayer = graph.GetOrAddLayer(_newLayerName);
2727

28-
foreach (var node in parentLayer.GetNodesInLayer())
28+
foreach (var node in parentLayer.GetEntitiesInLayer())
2929
{
3030
var neighbors = parentLayer.CountNeighbors(node);
3131

GDT.Test/source/Tests/PipelineTests/Steps/GraphToGridLayoutStep.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private GeometryGraph MakeLayoutGraph(Layer layer)
4040
GeometryGraph geometryGraph = new GeometryGraph();
4141

4242
Dictionary<Entity, MSNode> nodeMapping = new Dictionary<Entity, MSNode>();
43-
foreach (var node in layer.GetNodesInLayer())
43+
foreach (var node in layer.GetEntitiesInLayer())
4444
{
4545
MSNode msNode = new MSNode()
4646
{
@@ -54,7 +54,7 @@ private GeometryGraph MakeLayoutGraph(Layer layer)
5454

5555
foreach (var relation in layer.Relations)
5656
{
57-
geometryGraph.Edges.Add(new Edge(nodeMapping[relation.Nodes[0]], nodeMapping[relation.Nodes[1]]));
57+
geometryGraph.Edges.Add(new Edge(nodeMapping[relation.Entities[0]], nodeMapping[relation.Entities[1]]));
5858
}
5959

6060
return geometryGraph;

GDT.Test/source/Tests/PipelineTests/Steps/IslandBiomeAssignmentStep.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class IslandBiomeAssignmentStep : BaseBiomeAssignmentPipelineStep
1313
private readonly float _islandRadius;
1414
private readonly Random _random;
1515

16-
public IslandBiomeAssignmentStep(Func<List<Entity>> nodesToEvaluate, Vector2 islandCenter, float islandRadius) : base(nodesToEvaluate)
16+
public IslandBiomeAssignmentStep(Func<List<Entity>> entitiesToEvaluate, Vector2 islandCenter, float islandRadius) : base(entitiesToEvaluate)
1717
{
1818
_random = new Random();
1919
_islandCenter = islandCenter;

GDT.Test/source/Tests/PipelineTests/Steps/IslandTypeAssignment.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static void SetupStartingIsland(List<KeyValuePair<Entity, float>> nodeDi
6565
{
6666
var (startingIslandNode, _) = nodeDistancePercentageList[0];
6767
nodeDistancePercentageList.RemoveAt(0);
68-
AddIslandTypeComponent(startingIslandNode, Biome.Grassland, Biome.Forrest);
68+
AddIslandTypeComponent(startingIslandNode, Biome.Grassland, Biome.Forest);
6969
}
7070

7171
private static void AddIslandTypeComponent(Entity entity, Biome baseBiome, Biome specialBiome)
@@ -83,7 +83,7 @@ private static List<Biome> GetAvailableBaseBiomes(float distancePercentage)
8383
List<Biome> biomes = new() { Biome.Grassland };
8484

8585
if (distancePercentage > 0.25f)
86-
biomes.Add(Biome.Forrest);
86+
biomes.Add(Biome.Forest);
8787

8888
if (distancePercentage > 0.45f)
8989
biomes.Add(Biome.Swamp);
@@ -95,7 +95,7 @@ private static List<Biome> GetAvailableSpecialBiomes(float distancePercentage, B
9595
{
9696
List<Biome> biomes = new();
9797

98-
if (SpecialIsNotBase(Biome.Forrest, baseBiome)) biomes.Add(Biome.Forrest);
98+
if (SpecialIsNotBase(Biome.Forest, baseBiome)) biomes.Add(Biome.Forest);
9999
else distancePercentage += 0.35f;
100100

101101
if (distancePercentage > 0.35f && SpecialIsNotBase(Biome.Swamp, baseBiome))

GDT.Test/source/Utility/Biome.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public enum Biome
55
Unassigned = 0,
66
Sea = 1,
77
Grassland = 2,
8-
Forrest = 3,
8+
Forest = 3,
99
Swamp = 4,
1010
Mountain = 5,
1111
}

GDT.Test/source/Utility/Debugging.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ namespace GDT.Utility.Visualization
1010
{
1111
public class Debugging
1212
{
13-
public static void PrintGraphNodes(IEnumerable<Entity> nodes, Func<Entity, int, string> toString, int depth = 0)
13+
public static void PrintGraphEntities(IEnumerable<Entity> entities, Func<Entity, int, string> toString, int depth = 0)
1414
{
15-
foreach (var node in nodes)
15+
foreach (var entity in entities)
1616
{
17-
Console.WriteLine(toString.Invoke(node, depth));
17+
Console.WriteLine(toString.Invoke(entity, depth));
1818

19-
PrintGraphNodes(node.Children, toString, depth + 1);
19+
PrintGraphEntities(entity.Children, toString, depth + 1);
2020
}
2121
}
2222

23-
public static void PrintWfcGraphModules<TTileData>(IEnumerable<Entity> nodes,
23+
public static void PrintWfcGraphModules<TTileData>(IEnumerable<Entity> entities,
2424
string wfcComponentName = "WfcComponent",
2525
string wfcCellName = "WfcCell") where TTileData: struct
2626
{
27-
PrintGraphNodes(nodes, (node, d) => DepthString(d) + WfcComponentToString<TTileData>(node, wfcComponentName, wfcCellName));
27+
PrintGraphEntities(entities, (entity, d) => DepthString(d) + WfcComponentToString<TTileData>(entity, wfcComponentName, wfcCellName));
2828
}
2929

30-
public static void PrintGraph(IEnumerable<Entity> nodes)
30+
public static void PrintGraph(IEnumerable<Entity> entities)
3131
{
32-
PrintGraphNodes(nodes, (node, d) => DepthString(d) + node.Name);
32+
PrintGraphEntities(entities, (entity, d) => DepthString(d) + entity.Name);
3333
}
3434

3535
private static string DepthString(int depth)
@@ -40,7 +40,7 @@ private static string DepthString(int depth)
4040
private static string WfcComponentToString<TTileData>(Entity entity, string wfcComponentName, string wfcCellName)
4141
where TTileData: struct
4242
{
43-
var cell = GetWfcCellFromNode<TTileData>(entity, wfcComponentName, wfcCellName);
43+
var cell = GetWfcCellFromEntity<TTileData>(entity, wfcComponentName, wfcCellName);
4444
if (cell == null) return "missing wfc component";
4545

4646
string modules = "NO AVAILABLE MODULES";
@@ -54,7 +54,7 @@ private static string WfcComponentToString<TTileData>(Entity entity, string wfcC
5454
return $"index: {cell.Position} modules: {modules}";
5555
}
5656

57-
private static WfcCell<WfcGraphTile<TTileData>, int> GetWfcCellFromNode<TTileData>(Entity entity, string wfcComponentName, string wfcCellName)
57+
private static WfcCell<WfcGraphTile<TTileData>, int> GetWfcCellFromEntity<TTileData>(Entity entity, string wfcComponentName, string wfcCellName)
5858
where TTileData: struct
5959
{
6060
var component = entity.GetComponent(wfcComponentName);

GDT.Test/source/Utility/PocketWorldGraphTiles.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static WfcGraphTile<WorldData> CreateRoadTile(string roadName, Blackboard
5959

6060
return isTileAvailable;
6161
});
62-
roadTile.TileDescriptor.AddBorderNode(roadEntity, 2, 2);
62+
roadTile.TileDescriptor.AddBorderEntity(roadEntity, 2, 2);
6363
roadTile.TileDescriptor.AdditionalTileData = new WorldData(TileType.Road);
6464

6565
return roadTile;
@@ -75,8 +75,8 @@ private static string IncrementBlackboardCount(string key, Blackboard initialBla
7575
public static WfcGraphTile<WorldData> CreateCityTile(string cityName, Blackboard initialBlackboard)
7676
{
7777
var cityGraph = Graph.CreatePlaceholder(cityName);
78-
var cityNode = new Entity(cityName, cityGraph);
79-
cityGraph.Entities.Add(cityNode);
78+
var cityEntity = new Entity(cityName, cityGraph);
79+
cityGraph.Entities.Add(cityEntity);
8080
var blackboardCityCountKey = IncrementBlackboardCount(cityName, initialBlackboard);
8181

8282
var cityTile = new WfcGraphTile<WorldData>(cityGraph, (thisModule, thisCell, wfcSpace) =>
@@ -93,7 +93,7 @@ public static WfcGraphTile<WorldData> CreateCityTile(string cityName, Blackboard
9393

9494
return true;
9595
});
96-
cityTile.TileDescriptor.AddBorderNode(cityNode, 1, 3);
96+
cityTile.TileDescriptor.AddBorderEntity(cityEntity, 1, 3);
9797
cityTile.TileDescriptor.AdditionalTileData = new WorldData(TileType.City);
9898

9999
return cityTile;
@@ -102,8 +102,8 @@ public static WfcGraphTile<WorldData> CreateCityTile(string cityName, Blackboard
102102
public static WfcGraphTile<WorldData> CreateSpecialTile(string tileName, Blackboard initialBlackboard, uint mandatoryConnections = 1, uint optionalConnections = 0)
103103
{
104104
var specialGraph = Graph.CreatePlaceholder(tileName);
105-
var specialNode = new Entity(tileName, specialGraph);
106-
specialGraph.Entities.Add(specialNode);
105+
var specialEntity = new Entity(tileName, specialGraph);
106+
specialGraph.Entities.Add(specialEntity);
107107
var blackboardTileCountKey = IncrementBlackboardCount(tileName, initialBlackboard);
108108

109109
var specialTile = new WfcGraphTile<WorldData>(specialGraph, (thisModule, thisCell, wfcSpace) =>
@@ -120,20 +120,20 @@ public static WfcGraphTile<WorldData> CreateSpecialTile(string tileName, Blackbo
120120

121121
return true;
122122
});
123-
specialTile.TileDescriptor.AddBorderNode(specialNode, mandatoryConnections, optionalConnections);
123+
specialTile.TileDescriptor.AddBorderEntity(specialEntity, mandatoryConnections, optionalConnections);
124124
specialTile.TileDescriptor.AdditionalTileData = new WorldData(TileType.City);
125125

126126
return specialTile;
127127
}
128128

129129
private static bool CanConnect(WfcGraphTile<WorldData> thisModule, List<WfcCell<WfcGraphTile<WorldData>, int>> neighbors)
130130
{
131-
uint availableTotalConnections = thisModule.TileDescriptor.BorderNodes
131+
uint availableTotalConnections = thisModule.TileDescriptor.BorderEntities
132132
.Select(bn => bn.TotalConnections)
133133
.Aggregate((c1, c2) => c1 + c2);
134134
if (neighbors.Count > availableTotalConnections) return false;
135135

136-
uint availableMandatoryConnections = thisModule.TileDescriptor.BorderNodes
136+
uint availableMandatoryConnections = thisModule.TileDescriptor.BorderEntities
137137
.Select(bn => bn.MandatoryConnections)
138138
.Aggregate((c1, c2) => c1 + c2);
139139
if (neighbors.Count < availableMandatoryConnections) return false;

GDT.Test/testdata/pocket_world_pipeline.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-- This method is called by the pipeline during initializationfunction Initialize () local areaName = "Zone" local layerName = areaName .. " Layer" local currentNodes = 6 local targetNodes = 10 local graph = GraphBuilder.BuildCircleGraph("Pocket World", currentNodes, layerName, areaName .. " {0}") local areaLayer = graph:GetLayer(layerName) while currentNodes < targetNodes do local relation = areaLayer:GetSomewhatRandomRelationWithDegreeSmaller(4) local newEntity = Entity(areaName .. " " .. tostring(currentNodes+1), graph) graph.Entities:Add(newEntity) areaLayer:AddRelation(relation.Nodes[0], newEntity, areaName .. " Connection '" .. relation.Nodes[0].Name .. "' <-> '" .. newEntity.Name .. "'") areaLayer:AddRelation(newEntity, relation.Nodes[1], areaName .. " Connection '" .. newEntity.Name .. "' <-> '" .. relation.Nodes[1].Name .. "'") currentNodes = currentNodes + 1 end return graphend-- This method is called by the pipeline in a stepfunction ExecuteStep (graph) local entity = Entity('Lua Test Node', graph) graph.Entities:Add(entity)end
1+
-- This method is called by the pipeline during initializationfunction Initialize () local areaName = "Zone" local layerName = areaName .. " Layer" local currentEntities = 6 local targetEntities = 10 local graph = GraphBuilder.BuildCircleGraph("Pocket World", currentEntities, layerName, areaName .. " {0}") local areaLayer = graph:GetLayer(layerName) while currentEntities < targetEntities do local relation = areaLayer:GetSomewhatRandomRelationWithDegreeSmaller(4) local newEntity = Entity(areaName .. " " .. tostring(currentEntities +1), graph) graph.Entities:Add(newEntity) areaLayer:AddRelation(relation.Entities[0], newEntity, areaName .. " Connection '" .. relation.Entities[0].Name .. "' <-> '" .. newEntity.Name .. "'") areaLayer:AddRelation(newEntity, relation.Entities[1], areaName .. " Connection '" .. newEntity.Name .. "' <-> '" .. relation.Entities[1].Name .. "'") currentEntities = currentEntities + 1 end return graphend-- This method is called by the pipeline in a stepfunction ExecuteStep (graph) local entity = Entity('Lua Test Entity', graph) graph.Entities:Add(entity)end

0 commit comments

Comments
 (0)