DungeonFlowIntegrityRule.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using DunGen.Graph;
  2. namespace DunGen.Editor.Validation.Rules
  3. {
  4. sealed class DungeonFlowIntegrityRule : IValidationRule
  5. {
  6. public void Validate(DungeonFlow flow, DungeonValidator validator)
  7. {
  8. // Check DungeonFlow
  9. if(flow == null)
  10. {
  11. validator.AddError("No DungeonFlow is assigned");
  12. return;
  13. }
  14. CheckLineSegments(flow, validator);
  15. CheckNodes(flow, validator);
  16. CheckArchetypes(flow, validator);
  17. CheckTileSets(flow, validator);
  18. }
  19. private void CheckLineSegments(DungeonFlow flow, DungeonValidator validator)
  20. {
  21. if (flow.Lines.Count < 1)
  22. validator.AddError("The dungeon flow must contain at least one line segment");
  23. foreach (var line in flow.Lines)
  24. {
  25. if (line.DungeonArchetypes.Count == 0)
  26. validator.AddError("A line segments in your dungeon flow graph has no archetype applied");
  27. foreach (var archetype in line.DungeonArchetypes)
  28. if (archetype == null)
  29. validator.AddError("A line segment in your dungeon flow graph has an unset archetype value");
  30. }
  31. }
  32. private void CheckNodes(DungeonFlow flow, DungeonValidator validator)
  33. {
  34. if (flow.Nodes.Count < 2)
  35. validator.AddError("The dungeon flow must contain at least two nodes");
  36. foreach (var node in flow.Nodes)
  37. {
  38. if (node.TileSets.Count == 0)
  39. validator.AddError("The node '{0}' in the dungeon flow graph has no tile sets applied", node.Label);
  40. else
  41. {
  42. foreach(var tileSet in node.TileSets)
  43. if(tileSet == null)
  44. validator.AddError("Node '{0}' in your dungeon flow graph has an unset tileset value", node.Label);
  45. }
  46. }
  47. }
  48. private void CheckArchetypes(DungeonFlow flow, DungeonValidator validator)
  49. {
  50. var archetypes = flow.GetUsedArchetypes();
  51. foreach(var archetype in archetypes)
  52. {
  53. if (archetype == null)
  54. continue;
  55. if (archetype.TileSets.Count == 0)
  56. validator.AddError("The archetype '{0}' has no tile sets assigned", archetype, archetype.name);
  57. else
  58. {
  59. foreach (var tileSet in archetype.TileSets)
  60. if (tileSet == null)
  61. validator.AddError("The archetype '{0}' has a missing tile set", archetype, archetype.name);
  62. }
  63. foreach (var tileSet in archetype.BranchCapTileSets)
  64. if (tileSet == null)
  65. validator.AddError("Archetype '{0}' has a missing branch cap tile set", archetype, archetype.name);
  66. }
  67. }
  68. private void CheckTileSets(DungeonFlow flow, DungeonValidator validator)
  69. {
  70. var tileSets = flow.GetUsedTileSets();
  71. foreach (var tileSet in tileSets)
  72. {
  73. if (tileSet == null)
  74. continue;
  75. foreach (var tileWeight in tileSet.TileWeights.Weights)
  76. {
  77. if (tileWeight.Value == null)
  78. validator.AddWarning("The tile set '{0}' has a missing tile", tileSet, tileSet.name);
  79. if (tileWeight.MainPathWeight <= 0f && tileWeight.BranchPathWeight <= 0f)
  80. validator.AddWarning("Tile set '{0}' has a tile ({1}) set up with a main path weight and branch path weight of zero. This tile will never appear in the dungeon", tileSet, tileSet.name, (tileWeight.Value == null) ? "NULL" : tileWeight.Value.name);
  81. if (tileWeight.DepthWeightScale != null)
  82. {
  83. bool hasNonZeroKeyframe = false;
  84. foreach (var key in tileWeight.DepthWeightScale.keys)
  85. {
  86. if (key.value > 0f)
  87. {
  88. hasNonZeroKeyframe = true;
  89. break;
  90. }
  91. }
  92. if (!hasNonZeroKeyframe)
  93. validator.AddWarning("Tile set '{0}' has a tile ({1}) set up with a depth curve that will always return zero. This tile will never appear in the dungeon", tileSet, tileSet.name, tileWeight.Value.name);
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }