Index enemy event duplicate identities
This commit is contained in:
@@ -112,8 +112,10 @@ func allSourceRefsValid(index source.DocumentIndex, value dnd.EnemyEventList) bo
|
||||
|
||||
func issuesFor(order shared.SourceRefOrder, value dnd.EnemyEventList, registry *npcregistry.Registry) []string {
|
||||
issues := make([]string, 0)
|
||||
canonicalEvidence := make([]bool, len(value.Events))
|
||||
for eventIndex, event := range value.Events {
|
||||
prefix := fmt.Sprintf("events[%d]", eventIndex)
|
||||
canonicalEvidence[eventIndex] = true
|
||||
if normalized := enemyeventmodel.NormalizeDisplay(event.Name); event.Name != normalized {
|
||||
issues = append(issues, prefix+".name is not whitespace-normalized: "+diagnostics.Quote(event.Name))
|
||||
}
|
||||
@@ -125,8 +127,10 @@ func issuesFor(order shared.SourceRefOrder, value dnd.EnemyEventList, registry *
|
||||
current := event.SourceRefs[refIndex]
|
||||
if order.Less(current, previous) {
|
||||
issues = append(issues, fmt.Sprintf("%s.source_refs are not in canonical order at index %d", prefix, refIndex))
|
||||
canonicalEvidence[eventIndex] = false
|
||||
} else if current == previous {
|
||||
issues = append(issues, fmt.Sprintf("%s.source_refs[%d] duplicates the previous reference", prefix, refIndex))
|
||||
canonicalEvidence[eventIndex] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,13 +139,19 @@ func issuesFor(order shared.SourceRefOrder, value dnd.EnemyEventList, registry *
|
||||
}) {
|
||||
issues = append(issues, "events are not in canonical order")
|
||||
}
|
||||
firstByIdentity := make(map[string][]int, len(value.Events))
|
||||
for eventIndex, event := range value.Events {
|
||||
for previousIndex := 0; previousIndex < eventIndex; previousIndex++ {
|
||||
if enemyeventmodel.ExactEqual(order, value.Events[previousIndex], event) {
|
||||
if !canonicalEvidence[eventIndex] {
|
||||
continue
|
||||
}
|
||||
identity := enemyeventmodel.CanonicalIdentity(event)
|
||||
for _, previousIndex := range firstByIdentity[identity] {
|
||||
if enemyeventmodel.CanonicalExactEqual(value.Events[previousIndex], event) {
|
||||
issues = append(issues, fmt.Sprintf("events[%d] duplicates event %d", eventIndex, previousIndex))
|
||||
break
|
||||
}
|
||||
}
|
||||
firstByIdentity[identity] = append(firstByIdentity[identity], eventIndex)
|
||||
}
|
||||
return issues
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user