Add campaign and session glossary selections
This commit is contained in:
@@ -8,11 +8,11 @@ import (
|
||||
)
|
||||
|
||||
type renderedCampaignInputs struct {
|
||||
SpeakersFile string `yaml:"speakers_file,omitempty"`
|
||||
AutocorrectFile string `yaml:"autocorrect_file,omitempty"`
|
||||
GlossaryFile string `yaml:"glossary_file,omitempty"`
|
||||
PartyFile string `yaml:"party_file,omitempty"`
|
||||
SpellCatalogFile string `yaml:"spell_catalog_file,omitempty"`
|
||||
SpeakersFile string `yaml:"speakers_file,omitempty"`
|
||||
AutocorrectFile string `yaml:"autocorrect_file,omitempty"`
|
||||
PartyFile string `yaml:"party_file,omitempty"`
|
||||
SpellCatalogFile string `yaml:"spell_catalog_file,omitempty"`
|
||||
Extra map[string]any `yaml:",inline"`
|
||||
}
|
||||
|
||||
// RenderCampaignDocument serializes the loaded effective campaign document.
|
||||
@@ -32,7 +32,7 @@ func RenderCampaignDocument(cfg *Config) ([]byte, error) {
|
||||
SessionTemplateFile string `yaml:"session_template_file,omitempty"`
|
||||
Inputs renderedCampaignInputs `yaml:"inputs"`
|
||||
}{doc.CampaignID, doc.SessionTemplateFile, renderedCampaignInputs{
|
||||
doc.Inputs.SpeakersFile, doc.Inputs.AutocorrectFile, doc.Inputs.GlossaryFile, doc.Inputs.PartyFile, doc.Inputs.SpellCatalogFile,
|
||||
doc.Inputs.SpeakersFile, doc.Inputs.AutocorrectFile, doc.Inputs.PartyFile, doc.Inputs.SpellCatalogFile, glossaryFields(doc.ConfigKitResult() != nil, campaignMetadata(doc), doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, false),
|
||||
}}
|
||||
return yaml.Marshal(value)
|
||||
}
|
||||
@@ -72,13 +72,12 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
AudioS3 *SessionAudioS3Input `yaml:"audio_s3,omitempty"`
|
||||
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
||||
AutocorrectFile *string `yaml:"autocorrect_file,omitempty"`
|
||||
GlossaryFile *string `yaml:"glossary_file,omitempty"`
|
||||
SpellCatalogFile *string `yaml:"spell_catalog_file,omitempty"`
|
||||
Extra map[string]any `yaml:",inline"`
|
||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3,
|
||||
inputValue("speakers_file", doc.Inputs.SpeakersFile),
|
||||
inputValue("autocorrect_file", doc.Inputs.AutocorrectFile),
|
||||
inputValue("glossary_file", doc.Inputs.GlossaryFile),
|
||||
inputValue("spell_catalog_file", doc.Inputs.SpellCatalogFile)}
|
||||
inputValue("spell_catalog_file", doc.Inputs.SpellCatalogFile), glossaryFields(result != nil, metadata, doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, true)}
|
||||
value := struct {
|
||||
SessionID string `yaml:"session_id"`
|
||||
PreviousSessionID string `yaml:"previous_session_id,omitempty"`
|
||||
@@ -89,3 +88,40 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
}{id, cfg.Session.PreviousSessionID, cfg.Session.Campaign, doc.Date, doc.Title, inputs}
|
||||
return yaml.Marshal(value)
|
||||
}
|
||||
|
||||
func campaignMetadata(cfg *CampaignConfig) configkit.Metadata {
|
||||
if r := cfg.ConfigKitResult(); r != nil {
|
||||
return r.Metadata()
|
||||
}
|
||||
return configkit.Metadata{}
|
||||
}
|
||||
|
||||
func glossaryFields(hasResult bool, metadata configkit.Metadata, setting, system, file *string, glossary map[string]any, authoredOnly bool) map[string]any {
|
||||
result := map[string]any{}
|
||||
for _, field := range []struct {
|
||||
name string
|
||||
value *string
|
||||
}{{"setting", setting}, {"system", system}, {"glossary_file", file}} {
|
||||
path := configkit.Keys("inputs", field.name)
|
||||
info, found := metadata.Lookup(path)
|
||||
explicit := hasResult && metadata.IsExplicit(path)
|
||||
if (authoredOnly && hasResult && !explicit) || (!explicit && field.value == nil) {
|
||||
continue
|
||||
}
|
||||
if found && info.Null {
|
||||
result[field.name] = nil
|
||||
} else {
|
||||
result[field.name] = OptionalString(field.value)
|
||||
}
|
||||
}
|
||||
path := configkit.Keys("inputs", "glossary")
|
||||
explicit := hasResult && metadata.IsExplicit(path)
|
||||
if !(authoredOnly && hasResult && !explicit) && (explicit || glossary != nil) {
|
||||
if glossary == nil {
|
||||
result["glossary"] = nil
|
||||
} else {
|
||||
result["glossary"] = glossary
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user