Simplify D&D combat turn extraction contract
This commit is contained in:
@@ -60,39 +60,9 @@ func issuesFor(value dnd.CombatTurnList) []string {
|
||||
if !validTurnKind(turn.TurnKind) {
|
||||
issues = append(issues, prefix+".turn_kind is unsupported: "+diagnostics.Quote(string(turn.TurnKind)))
|
||||
}
|
||||
if turn.Round != nil && *turn.Round <= 0 {
|
||||
issues = append(issues, prefix+".round must be positive or null")
|
||||
}
|
||||
if len(turn.Actions) == 0 {
|
||||
issues = append(issues, prefix+".actions must contain at least one action")
|
||||
}
|
||||
if strings.TrimSpace(turn.Summary) == "" {
|
||||
issues = append(issues, prefix+".summary must not be empty: "+diagnostics.Quote(turn.Summary))
|
||||
}
|
||||
if len(turn.SourceRefs) == 0 {
|
||||
issues = append(issues, prefix+".source_refs must contain at least one reference")
|
||||
}
|
||||
for actionIndex, action := range turn.Actions {
|
||||
actionPrefix := fmt.Sprintf("%s.actions[%d]", prefix, actionIndex)
|
||||
if !validActionCategory(action.Category) {
|
||||
issues = append(issues, actionPrefix+".category is unsupported: "+diagnostics.Quote(string(action.Category)))
|
||||
}
|
||||
if strings.TrimSpace(action.Declaration) == "" {
|
||||
issues = append(issues, actionPrefix+".declaration must not be empty: "+diagnostics.Quote(action.Declaration))
|
||||
}
|
||||
if action.Targets == nil {
|
||||
issues = append(issues, actionPrefix+".targets must be present")
|
||||
} else {
|
||||
for targetIndex, target := range action.Targets {
|
||||
if strings.TrimSpace(target) == "" {
|
||||
issues = append(issues, fmt.Sprintf("%s.targets[%d] must not be empty: %s", actionPrefix, targetIndex, diagnostics.Quote(target)))
|
||||
}
|
||||
}
|
||||
}
|
||||
if action.Resolution != nil && strings.TrimSpace(*action.Resolution) == "" {
|
||||
issues = append(issues, actionPrefix+".resolution must not be empty or null: "+diagnostics.Quote(*action.Resolution))
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues
|
||||
}
|
||||
@@ -106,15 +76,6 @@ func validTurnKind(value dnd.CombatTurnKind) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func validActionCategory(value dnd.CombatActionCategory) bool {
|
||||
switch value {
|
||||
case dnd.CombatActionCategoryAttack, dnd.CombatActionCategorySpell, dnd.CombatActionCategoryMovement, dnd.CombatActionCategoryItem, dnd.CombatActionCategoryAbilityCheck, dnd.CombatActionCategorySavingThrow, dnd.CombatActionCategoryCondition, dnd.CombatActionCategoryOther:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func Spec() pipeline.ValidatorSpec {
|
||||
return pipeline.ValidatorSpec{Key: Key, ExecutionClass: contracts.ExecutionClassDeterministic}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user