-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OndrejNepozitek
committed
Dec 15, 2023
1 parent
6013c60
commit 1755e55
Showing
7 changed files
with
341 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
Runtime/Grid2D/Common/Diagnostics/Checks/NotEnoughDoors.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Edgar.GraphBasedGenerator.Grid2D; | ||
using UnityEngine; | ||
|
||
namespace Edgar.Unity.Diagnostics | ||
{ | ||
public class NotEnoughDoors | ||
{ | ||
public Result Run(LevelDescriptionBase levelDescription) | ||
{ | ||
var roomTemplates = new List<RoomTemplateGrid2D>(); | ||
var levelDescriptionGrid2D = levelDescription.GetLevelDescription(); | ||
foreach (var room in levelDescription.GetGraph().Vertices) | ||
{ | ||
var roomDescription = levelDescriptionGrid2D.GetRoomDescription(room); | ||
if (!roomDescription.IsCorridor) | ||
{ | ||
roomTemplates.AddRange(roomDescription.RoomTemplates); | ||
} | ||
} | ||
roomTemplates = roomTemplates.Distinct().ToList(); | ||
|
||
var result = new Result | ||
{ | ||
Summary = "" | ||
}; | ||
|
||
var summaries = new List<string>() | ||
{ | ||
DoorsOnAllSides(roomTemplates, result), | ||
}; | ||
|
||
var summariesWithoutNulls = summaries.Where(x => x != null).ToList(); | ||
if (summariesWithoutNulls.Count == 0) | ||
{ | ||
return result; | ||
} | ||
|
||
var sb = new StringBuilder(); | ||
sb.AppendLine("For the performance of the generator, it is important to add many door positions to individual room templates."); | ||
sb.AppendLine("It is even more critical if you want to generate levels with cycles."); | ||
sb.AppendLine("A good starting point is to use the Simple door mode that provides many door positions."); | ||
sb.AppendLine(""); | ||
sb.AppendLine("We detected potential issues related to doors below:"); | ||
sb.AppendLine(""); | ||
|
||
result.IsPotentialProblem = true; | ||
|
||
result.Summary = sb.ToString(); | ||
result.Summary += string.Join("\n", summariesWithoutNulls); | ||
|
||
return result; | ||
} | ||
|
||
private string DoorsOnAllSides(List<RoomTemplateGrid2D> roomTemplates, Result result) | ||
{ | ||
var hasAllDirectionsDoors = false; | ||
foreach (var roomTemplate in roomTemplates) | ||
{ | ||
var doors = roomTemplate.Doors.GetDoors(roomTemplate.Outline); | ||
var distinctDirections = doors | ||
.Select(x => x.Line.GetDirection()) | ||
.Distinct() | ||
.Count(); | ||
|
||
if (distinctDirections >= 4) | ||
{ | ||
hasAllDirectionsDoors = true; | ||
break; | ||
} | ||
} | ||
|
||
if (hasAllDirectionsDoors) | ||
{ | ||
return null; | ||
} | ||
|
||
result.MissingDoorsOnAllSides = true; | ||
|
||
var sb = new StringBuilder(); | ||
sb.AppendLine("There are no room templates that have doors on all 4 sides."); | ||
sb.AppendLine("Such room templates are useful for the generator because they are often very versatile and can be used for rooms with many neighbors."); | ||
sb.AppendLine("They are also very useful if you want to have cycles in your level graph."); | ||
|
||
return sb.ToString(); | ||
} | ||
|
||
public class Result : IDiagnosticResult | ||
{ | ||
public string Name => "Not enough doors"; | ||
|
||
public string Summary { get; set; } | ||
|
||
public bool IsPotentialProblem { get; set; } | ||
|
||
public bool MissingDoorsOnAllSides { get; set; } | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Runtime/Grid2D/Common/Diagnostics/Checks/NotEnoughDoors.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
Tests/Runtime/Scenes/TimeoutDiagnostics/Level graphs/NotEnoughDoorsNoFourSides.asset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!114 &-7877986336414098987 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 8f692f83df7c1b5468af64edd22287dc, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
From: {fileID: -3829538508782324871} | ||
To: {fileID: 3289652443752732884} | ||
--- !u!114 &-7307270355954133241 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 8f692f83df7c1b5468af64edd22287dc, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
From: {fileID: -3649007993993380384} | ||
To: {fileID: 3289652443752732884} | ||
--- !u!114 &-3829538508782324871 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 8074dc491ddc34f4e83332d9eae76980, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
Position: {x: 240, y: 208} | ||
Name: Room | ||
IndividualRoomTemplates: [] | ||
RoomTemplateSets: [] | ||
--- !u!114 &-3649007993993380384 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 8074dc491ddc34f4e83332d9eae76980, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
Position: {x: 352, y: 144} | ||
Name: Room | ||
IndividualRoomTemplates: [] | ||
RoomTemplateSets: [] | ||
--- !u!114 &-3110113770019691134 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 8074dc491ddc34f4e83332d9eae76980, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
Position: {x: 464, y: 208} | ||
Name: Room | ||
IndividualRoomTemplates: [] | ||
RoomTemplateSets: [] | ||
--- !u!114 &11400000 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: b8400baee4cafd34091c865089a167b2, type: 3} | ||
m_Name: NotEnoughDoorsNoFourSides | ||
m_EditorClassIdentifier: | ||
Connections: | ||
- {fileID: -7307270355954133241} | ||
- {fileID: -7877986336414098987} | ||
- {fileID: 792699257021706418} | ||
CorridorIndividualRoomTemplates: [] | ||
CorridorRoomTemplateSets: [] | ||
DefaultIndividualRoomTemplates: | ||
- {fileID: 3020086594291796898, guid: 0e63bd7168493a94e9ffd4b0566f2965, type: 3} | ||
DefaultRoomTemplateSets: [] | ||
Rooms: | ||
- {fileID: -3829538508782324871} | ||
- {fileID: 3289652443752732884} | ||
- {fileID: -3110113770019691134} | ||
- {fileID: -3649007993993380384} | ||
EditorData: | ||
PanOffset: {x: 0, y: 0} | ||
Zoom: 1 | ||
RoomType: Edgar.Unity.Room | ||
ConnectionType: Edgar.Unity.Connection | ||
--- !u!114 &792699257021706418 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 8f692f83df7c1b5468af64edd22287dc, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
From: {fileID: 3289652443752732884} | ||
To: {fileID: -3110113770019691134} | ||
--- !u!114 &3289652443752732884 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 8074dc491ddc34f4e83332d9eae76980, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
Position: {x: 352, y: 208} | ||
Name: Room | ||
IndividualRoomTemplates: [] | ||
RoomTemplateSets: [] |
8 changes: 8 additions & 0 deletions
8
Tests/Runtime/Scenes/TimeoutDiagnostics/Level graphs/NotEnoughDoorsNoFourSides.asset.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters