Validate recommended class availability
This commit is contained in:
@@ -272,10 +272,17 @@ function validateSortie(errors, scenario, classKeys, formationRoles, terrainRule
|
||||
sortie.recommendedClasses.forEach((recommendation) => {
|
||||
assertNonEmptyString(errors, recommendation.label, `${context}: recommended class label`);
|
||||
assertNonEmptyString(errors, recommendation.reason, `${context}/${recommendation.label}: recommended class reason`);
|
||||
const recommendedClassKeys = Array.isArray(recommendation.classKeys) ? recommendation.classKeys : [];
|
||||
if (!Array.isArray(recommendation.classKeys) || recommendation.classKeys.length === 0) {
|
||||
errors.push(`${context}/${recommendation.label}: recommended class must include at least one classKey`);
|
||||
}
|
||||
recommendation.classKeys.forEach((classKey) => {
|
||||
const availableRecommendedUnits = scenario.units.filter(
|
||||
(unit) => unit.faction === 'ally' && !excludedUnitIds.has(unit.id) && recommendedClassKeys.includes(unit.classKey)
|
||||
);
|
||||
if (availableRecommendedUnits.length === 0) {
|
||||
errors.push(`${context}/${recommendation.label}: recommended class has no available allied unit`);
|
||||
}
|
||||
recommendedClassKeys.forEach((classKey) => {
|
||||
if (!classKeys.has(classKey)) {
|
||||
errors.push(`${context}: recommended class "${recommendation.label}" references unknown classKey "${classKey}"`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user