qstbak/Questionable/Questionable.Validation.Validators/AethernetShortcutValidator.cs
2025-10-09 07:47:19 +10:00

49 lines
1.4 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Questionable.Data;
using Questionable.Model;
using Questionable.Model.Common;
using Questionable.Model.Questing;
namespace Questionable.Validation.Validators;
internal sealed class AethernetShortcutValidator : IQuestValidator
{
private readonly AetheryteData _aetheryteData;
public AethernetShortcutValidator(AetheryteData aetheryteData)
{
_aetheryteData = aetheryteData;
}
public IEnumerable<ValidationIssue> Validate(Quest quest)
{
return (from x in quest.AllSteps()
select Validate(quest.Id, x.Sequence.Sequence, x.StepId, x.Step.AethernetShortcut) into x
where x != null
select x).Cast<ValidationIssue>();
}
private ValidationIssue? Validate(ElementId elementId, int sequenceNo, int stepId, AethernetShortcut? aethernetShortcut)
{
if (aethernetShortcut == null)
{
return null;
}
ushort valueOrDefault = _aetheryteData.AethernetGroups.GetValueOrDefault(aethernetShortcut.From);
ushort valueOrDefault2 = _aetheryteData.AethernetGroups.GetValueOrDefault(aethernetShortcut.To);
if (valueOrDefault != valueOrDefault2)
{
return new ValidationIssue
{
ElementId = elementId,
Sequence = (byte)sequenceNo,
Step = stepId,
Type = EIssueType.InvalidAethernetShortcut,
Severity = EIssueSeverity.Error,
Description = $"Invalid aethernet shortcut: {aethernetShortcut.From} to {aethernetShortcut.To}"
};
}
return null;
}
}