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,7 +8,6 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/npcs/identity"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
)
@@ -26,8 +25,8 @@ func SourceRefsEqual(left, right []source.SourceRef) bool {
return true
}
// Less defines the canonical order for NPC interaction occurrences.
func Less(order shared.SourceRefOrder, left, right dnd.NPCInteraction) bool {
// Less defines the canonical order for NPC occurrences.
func Less(order shared.SourceRefOrder, left, right dnd.NPCOccurrence) bool {
leftPosition, leftHasEvidence := order.EarliestValid(left.SourceRefs)
rightPosition, rightHasEvidence := order.EarliestValid(right.SourceRefs)
if leftHasEvidence != rightHasEvidence {
@@ -36,8 +35,8 @@ func Less(order shared.SourceRefOrder, left, right dnd.NPCInteraction) bool {
if leftHasEvidence && leftPosition != rightPosition {
return leftPosition < rightPosition
}
leftKey := identity.ComparisonKey(left.Name)
rightKey := identity.ComparisonKey(right.Name)
leftKey := left.NPCID
rightKey := right.NPCID
if leftKey != rightKey {
return leftKey < rightKey
}
@@ -50,7 +49,7 @@ func Less(order shared.SourceRefOrder, left, right dnd.NPCInteraction) bool {
return sourceRefsLess(order, left.SourceRefs, right.SourceRefs)
}
// ValidSourceRefs reports whether an interaction has non-empty, valid
// ValidSourceRefs reports whether an occurrence has non-empty, valid
// current-document evidence.
func ValidSourceRefs(index source.DocumentIndex, refs []source.SourceRef) bool {
if len(refs) == 0 {
@@ -64,13 +63,14 @@ func ValidSourceRefs(index source.DocumentIndex, refs []source.SourceRef) bool {
return true
}
// ExactIdentity returns a collision-safe key over every durable interaction
// ExactIdentity returns a collision-safe key over every durable occurrence
// field. Callers decide whether the record is eligible for duplicate handling.
func ExactIdentity(interaction dnd.NPCInteraction) string {
func ExactIdentity(occurrence dnd.NPCOccurrence) string {
var key strings.Builder
writeKeyString(&key, interaction.Name)
writeKeyString(&key, string(interaction.Kind))
for _, ref := range interaction.SourceRefs {
writeKeyString(&key, occurrence.NPCID)
writeKeyString(&key, occurrence.Name)
writeKeyString(&key, string(occurrence.Kind))
for _, ref := range occurrence.SourceRefs {
writeKeyString(&key, ref.SourceID)
writeKeyInt(&key, ref.StartUnitID)
writeKeyInt(&key, ref.EndUnitID)