Adopt registry-backed NPC occurrence artifacts

This commit is contained in:
2026-08-05 18:55:58 +00:00
parent 3f4a1f2647
commit 5e2ccffc0f
42 changed files with 676 additions and 528 deletions

View File

@@ -8,8 +8,8 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
)
type orderedInteractionResponse struct {
value interactionResponse
type orderedOccurrenceResponse struct {
value occurrenceResponse
earliest int
hasEvidence bool
}
@@ -18,11 +18,11 @@ func canonicalizeResponse(response *extractionResponse, order shared.SourceRefOr
if response == nil {
return
}
ordered := make([]orderedInteractionResponse, len(response.Interactions))
for index := range response.Interactions {
earliest, hasEvidence := canonicalizeInteraction(&response.Interactions[index], order, sourceID)
ordered[index] = orderedInteractionResponse{
value: response.Interactions[index],
ordered := make([]orderedOccurrenceResponse, len(response.Occurrences))
for index := range response.Occurrences {
earliest, hasEvidence := canonicalizeOccurrence(&response.Occurrences[index], order, sourceID)
ordered[index] = orderedOccurrenceResponse{
value: response.Occurrences[index],
earliest: earliest,
hasEvidence: hasEvidence,
}
@@ -37,32 +37,33 @@ func canonicalizeResponse(response *extractionResponse, order shared.SourceRefOr
return ordered[i].earliest < ordered[j].earliest
})
for index := range ordered {
response.Interactions[index] = ordered[index].value
response.Occurrences[index] = ordered[index].value
}
}
func canonicalizeInteraction(interaction *interactionResponse, order shared.SourceRefOrder, sourceID string) (int, bool) {
if interaction == nil {
func canonicalizeOccurrence(occurrence *occurrenceResponse, order shared.SourceRefOrder, sourceID string) (int, bool) {
if occurrence == nil {
return 0, false
}
refs := order.Canonicalize(canonicalSourceRefs(interaction.SourceRefs, sourceID))
interaction.SourceRefs = interactionResponseRefs(refs)
refs := order.Canonicalize(canonicalSourceRefs(occurrence.SourceRefs, sourceID))
occurrence.SourceRefs = occurrenceResponseRefs(refs)
return order.EarliestValid(refs)
}
func canonicalInteractionList(response extractionResponse, sourceID string) dnd.NPCInteractionList {
interactions := make([]dnd.NPCInteraction, len(response.Interactions))
for index, interaction := range response.Interactions {
interactions[index] = dnd.NPCInteraction{
Name: interaction.Name,
Kind: dnd.NPCInteractionKind(interaction.Kind),
SourceRefs: canonicalSourceRefs(interaction.SourceRefs, sourceID),
func canonicalOccurrenceList(response extractionResponse, sourceID string) dnd.NPCOccurrenceList {
occurrences := make([]dnd.NPCOccurrence, len(response.Occurrences))
for index, occurrence := range response.Occurrences {
occurrences[index] = dnd.NPCOccurrence{
NPCID: occurrence.NPCID,
Name: occurrence.Name,
Kind: dnd.NPCOccurrenceKind(occurrence.Kind),
SourceRefs: canonicalSourceRefs(occurrence.SourceRefs, sourceID),
}
}
if response.Interactions == nil {
interactions = nil
if response.Occurrences == nil {
occurrences = nil
}
return dnd.NPCInteractionList{Interactions: interactions}
return dnd.NPCOccurrenceList{Occurrences: occurrences}
}
func canonicalSourceRefs(refs []interactionSourceRefResponse, sourceID string) []source.SourceRef {
@@ -76,7 +77,7 @@ func canonicalSourceRefs(refs []interactionSourceRefResponse, sourceID string) [
return out
}
func interactionResponseRefs(refs []source.SourceRef) []interactionSourceRefResponse {
func occurrenceResponseRefs(refs []source.SourceRef) []interactionSourceRefResponse {
if refs == nil {
return nil
}