Files
notarius/internal/modules/dnd/register/merge.go

84 lines
2.1 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.Round != nil {
round := *value.Round
clone.Round = &round
}
if value.Actions != nil {
clone.Actions = make([]dnd.CombatAction, len(value.Actions))
for index, action := range value.Actions {
clone.Actions[index] = action
if action.Targets != nil {
clone.Actions[index].Targets = append([]string(nil), action.Targets...)
}
if action.Resolution != nil {
resolution := *action.Resolution
clone.Actions[index].Resolution = &resolution
}
}
}
if value.SourceRefs != nil {
clone.SourceRefs = append([]source.SourceRef(nil), value.SourceRefs...)
}
return clone
}