61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Questionable.Model;
|
|
using Questionable.Model.Questing;
|
|
|
|
namespace Questionable.Validation.Validators;
|
|
|
|
internal sealed class LandingZoneValidator : IQuestValidator
|
|
{
|
|
public IEnumerable<ValidationIssue> Validate(Quest quest)
|
|
{
|
|
foreach (var stepInfo in quest.AllSteps().Where<(QuestSequence, int, QuestStep)>(delegate((QuestSequence Sequence, int StepId, QuestStep Step) x)
|
|
{
|
|
List<LandingZone> landingZones = x.Step.LandingZones;
|
|
return landingZones != null && landingZones.Count > 0;
|
|
}))
|
|
{
|
|
for (int z = 0; z < stepInfo.Item3.LandingZones.Count; z++)
|
|
{
|
|
LandingZone zone = stepInfo.Item3.LandingZones[z];
|
|
if (zone.Vertices.Count < 3)
|
|
{
|
|
yield return new ValidationIssue
|
|
{
|
|
ElementId = quest.Id,
|
|
Sequence = stepInfo.Item1.Sequence,
|
|
Step = stepInfo.Item2,
|
|
Type = EIssueType.InvalidLandingZone,
|
|
Severity = EIssueSeverity.Error,
|
|
Description = $"Landing zone {z} has fewer than 3 vertices"
|
|
};
|
|
continue;
|
|
}
|
|
if (!LandingZoneMath.IsConvex(zone.Vertices))
|
|
{
|
|
yield return new ValidationIssue
|
|
{
|
|
ElementId = quest.Id,
|
|
Sequence = stepInfo.Item1.Sequence,
|
|
Step = stepInfo.Item2,
|
|
Type = EIssueType.InvalidLandingZone,
|
|
Severity = EIssueSeverity.Error,
|
|
Description = $"Landing zone {z} is not convex"
|
|
};
|
|
}
|
|
if (LandingZoneMath.CalculatePolygonArea(zone.Vertices) < 0.01f)
|
|
{
|
|
yield return new ValidationIssue
|
|
{
|
|
ElementId = quest.Id,
|
|
Sequence = stepInfo.Item1.Sequence,
|
|
Step = stepInfo.Item2,
|
|
Type = EIssueType.InvalidLandingZone,
|
|
Severity = EIssueSeverity.Error,
|
|
Description = $"Landing zone {z} has zero area (collinear vertices)"
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|