115 lines
2.9 KiB
Go
115 lines
2.9 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 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 appendSceneDescriptionLists(values []dnd.SceneDescriptionList) (dnd.SceneDescriptionList, error) {
|
|
count := 0
|
|
present := false
|
|
for _, value := range values {
|
|
if value.Scenes != nil {
|
|
present = true
|
|
}
|
|
count += len(value.Scenes)
|
|
}
|
|
if !present {
|
|
return dnd.SceneDescriptionList{}, nil
|
|
}
|
|
combined := dnd.SceneDescriptionList{Scenes: make([]dnd.SceneDescription, 0, count)}
|
|
for _, value := range values {
|
|
combined.Scenes = append(combined.Scenes, value.Scenes...)
|
|
}
|
|
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
|
|
}
|
|
|
|
func cloneNPCInteraction(value dnd.NPCInteraction) dnd.NPCInteraction {
|
|
clone := value
|
|
if value.SourceRefs != nil {
|
|
clone.SourceRefs = append([]source.SourceRef(nil), value.SourceRefs...)
|
|
}
|
|
return clone
|
|
}
|