Compose D&D location tracking modules
This commit is contained in:
@@ -152,6 +152,48 @@ func appendSceneDescriptionLists(values []dnd.SceneDescriptionList) (dnd.SceneDe
|
||||
return combined, nil
|
||||
}
|
||||
|
||||
func appendLocationLists(values []dnd.LocationList) (dnd.LocationList, error) {
|
||||
count := 0
|
||||
present := false
|
||||
for _, value := range values {
|
||||
if value.Locations != nil {
|
||||
present = true
|
||||
}
|
||||
count += len(value.Locations)
|
||||
}
|
||||
if !present {
|
||||
return dnd.LocationList{}, nil
|
||||
}
|
||||
combined := dnd.LocationList{Locations: make([]dnd.Location, 0, count)}
|
||||
for _, value := range values {
|
||||
for _, location := range value.Locations {
|
||||
combined.Locations = append(combined.Locations, cloneLocation(location))
|
||||
}
|
||||
}
|
||||
return combined, nil
|
||||
}
|
||||
|
||||
func appendLocationOccurrenceLists(values []dnd.LocationOccurrenceList) (dnd.LocationOccurrenceList, error) {
|
||||
count := 0
|
||||
present := false
|
||||
for _, value := range values {
|
||||
if value.Occurrences != nil {
|
||||
present = true
|
||||
}
|
||||
count += len(value.Occurrences)
|
||||
}
|
||||
if !present {
|
||||
return dnd.LocationOccurrenceList{}, nil
|
||||
}
|
||||
combined := dnd.LocationOccurrenceList{Occurrences: make([]dnd.LocationOccurrence, 0, count)}
|
||||
for _, value := range values {
|
||||
for _, occurrence := range value.Occurrences {
|
||||
combined.Occurrences = append(combined.Occurrences, cloneLocationOccurrence(occurrence))
|
||||
}
|
||||
}
|
||||
return combined, nil
|
||||
}
|
||||
|
||||
func cloneCombatTurn(value dnd.CombatTurn) dnd.CombatTurn {
|
||||
clone := value
|
||||
clone.SourceRefs = cloneSourceRefs(value.SourceRefs)
|
||||
@@ -192,6 +234,18 @@ func cloneNPCInteraction(value dnd.NPCInteraction) dnd.NPCInteraction {
|
||||
return clone
|
||||
}
|
||||
|
||||
func cloneLocation(value dnd.Location) dnd.Location {
|
||||
clone := value
|
||||
clone.SourceRefs = cloneSourceRefs(value.SourceRefs)
|
||||
return clone
|
||||
}
|
||||
|
||||
func cloneLocationOccurrence(value dnd.LocationOccurrence) dnd.LocationOccurrence {
|
||||
clone := value
|
||||
clone.SourceRefs = cloneSourceRefs(value.SourceRefs)
|
||||
return clone
|
||||
}
|
||||
|
||||
func cloneSourceRefs(refs []source.SourceRef) []source.SourceRef {
|
||||
return slices.Clone(refs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user