Add D&D refactoring plan and isolate merger results
This commit is contained in:
@@ -7,12 +7,21 @@ import (
|
||||
|
||||
func appendSpellLists(values []dnd.SpellList) (dnd.SpellList, error) {
|
||||
count := 0
|
||||
present := false
|
||||
for _, value := range values {
|
||||
if value.SpellCasts != nil {
|
||||
present = true
|
||||
}
|
||||
count += len(value.SpellCasts)
|
||||
}
|
||||
if !present {
|
||||
return dnd.SpellList{}, nil
|
||||
}
|
||||
combined := dnd.SpellList{SpellCasts: make([]dnd.SpellCast, 0, count)}
|
||||
for _, value := range values {
|
||||
combined.SpellCasts = append(combined.SpellCasts, value.SpellCasts...)
|
||||
for _, spellCast := range value.SpellCasts {
|
||||
combined.SpellCasts = append(combined.SpellCasts, cloneSpellCast(spellCast))
|
||||
}
|
||||
}
|
||||
return combined, nil
|
||||
}
|
||||
@@ -31,7 +40,9 @@ func appendNPCLists(values []dnd.NPCList) (dnd.NPCList, error) {
|
||||
}
|
||||
combined := dnd.NPCList{NPCs: make([]dnd.NPC, 0, count)}
|
||||
for _, value := range values {
|
||||
combined.NPCs = append(combined.NPCs, value.NPCs...)
|
||||
for _, npc := range value.NPCs {
|
||||
combined.NPCs = append(combined.NPCs, cloneNPC(npc))
|
||||
}
|
||||
}
|
||||
return combined, nil
|
||||
}
|
||||
@@ -105,6 +116,22 @@ func cloneCombatTurn(value dnd.CombatTurn) dnd.CombatTurn {
|
||||
return clone
|
||||
}
|
||||
|
||||
func cloneSpellCast(value dnd.SpellCast) dnd.SpellCast {
|
||||
clone := value
|
||||
if value.SourceRefs != nil {
|
||||
clone.SourceRefs = append([]source.SourceRef(nil), value.SourceRefs...)
|
||||
}
|
||||
return clone
|
||||
}
|
||||
|
||||
func cloneNPC(value dnd.NPC) dnd.NPC {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user