Add NPC interaction normalization
This commit is contained in:
@@ -57,6 +57,27 @@ func appendCombatTurnLists(values []dnd.CombatTurnList) (dnd.CombatTurnList, err
|
||||
return combined, nil
|
||||
}
|
||||
|
||||
func appendNPCInteractionLists(values []dnd.NPCInteractionList) (dnd.NPCInteractionList, error) {
|
||||
count := 0
|
||||
present := false
|
||||
for _, value := range values {
|
||||
if value.Interactions != nil {
|
||||
present = true
|
||||
}
|
||||
count += len(value.Interactions)
|
||||
}
|
||||
if !present {
|
||||
return dnd.NPCInteractionList{}, nil
|
||||
}
|
||||
combined := dnd.NPCInteractionList{Interactions: make([]dnd.NPCInteraction, 0, count)}
|
||||
for _, value := range values {
|
||||
for _, interaction := range value.Interactions {
|
||||
combined.Interactions = append(combined.Interactions, cloneNPCInteraction(interaction))
|
||||
}
|
||||
}
|
||||
return combined, nil
|
||||
}
|
||||
|
||||
func cloneCombatTurn(value dnd.CombatTurn) dnd.CombatTurn {
|
||||
clone := value
|
||||
if value.SourceRefs != nil {
|
||||
@@ -64,3 +85,11 @@ func cloneCombatTurn(value dnd.CombatTurn) dnd.CombatTurn {
|
||||
}
|
||||
return clone
|
||||
}
|
||||
|
||||
func cloneNPCInteraction(value dnd.NPCInteraction) dnd.NPCInteraction {
|
||||
clone := value
|
||||
if value.SourceRefs != nil {
|
||||
clone.SourceRefs = append([]source.SourceRef(nil), value.SourceRefs...)
|
||||
}
|
||||
return clone
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user