67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package register
|
|
|
|
import (
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
|
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
|
)
|
|
|
|
func appendSpellLists(values []dnd.SpellList) (dnd.SpellList, error) {
|
|
count := 0
|
|
for _, value := range values {
|
|
count += len(value.SpellCasts)
|
|
}
|
|
combined := dnd.SpellList{SpellCasts: make([]dnd.SpellCast, 0, count)}
|
|
for _, value := range values {
|
|
combined.SpellCasts = append(combined.SpellCasts, value.SpellCasts...)
|
|
}
|
|
return combined, nil
|
|
}
|
|
|
|
func appendNPCLists(values []dnd.NPCList) (dnd.NPCList, error) {
|
|
count := 0
|
|
present := false
|
|
for _, value := range values {
|
|
if value.NPCs != nil {
|
|
present = true
|
|
}
|
|
count += len(value.NPCs)
|
|
}
|
|
if !present {
|
|
return dnd.NPCList{}, nil
|
|
}
|
|
combined := dnd.NPCList{NPCs: make([]dnd.NPC, 0, count)}
|
|
for _, value := range values {
|
|
combined.NPCs = append(combined.NPCs, value.NPCs...)
|
|
}
|
|
return combined, nil
|
|
}
|
|
|
|
func appendCombatTurnLists(values []dnd.CombatTurnList) (dnd.CombatTurnList, error) {
|
|
count := 0
|
|
present := false
|
|
for _, value := range values {
|
|
if value.CombatTurns != nil {
|
|
present = true
|
|
}
|
|
count += len(value.CombatTurns)
|
|
}
|
|
if !present {
|
|
return dnd.CombatTurnList{}, nil
|
|
}
|
|
combined := dnd.CombatTurnList{CombatTurns: make([]dnd.CombatTurn, 0, count)}
|
|
for _, value := range values {
|
|
for _, turn := range value.CombatTurns {
|
|
combined.CombatTurns = append(combined.CombatTurns, cloneCombatTurn(turn))
|
|
}
|
|
}
|
|
return combined, nil
|
|
}
|
|
|
|
func cloneCombatTurn(value dnd.CombatTurn) dnd.CombatTurn {
|
|
clone := value
|
|
if value.SourceRefs != nil {
|
|
clone.SourceRefs = append([]source.SourceRef(nil), value.SourceRefs...)
|
|
}
|
|
return clone
|
|
}
|