PlayerDialogueCatalog.cs

The file implements a static class that stores player dialogue strings organized by a speech cue. It provides methods to retrieve specific dialogue phrases and aggregate all phrases into an enumerable collection.

using System;
using System.Collections.Generic;
using System.Linq;

namespace Socer;

// Each entry is authored for one football context. RU/EN are the same situation,
// not interchangeable sentence fragments or a cartesian product of templates.
public static partial class PlayerDialogueCatalog
{
    static readonly Dictionary<PlayerSpeechCue,PlayerDialogue.Phrase[]> Lines=new();
    static void Bank(PlayerSpeechCue cue,params string[] text)
    {
        var bank=new PlayerDialogue.Phrase[text.Length/2];
        for(int i=0;i<bank.Length;i++)bank[i]=new(10000+(int)cue*100+i,text[i*2],text[i*2+1]);
        Lines.Add(cue,bank);
    }
    public static PlayerDialogue.Phrase[] For(PlayerSpeechCue cue)=>Lines.TryGetValue(cue,out var lines)?lines:Array.Empty<PlayerDialogue.Phrase>();
    public static IEnumerable<PlayerDialogue.Phrase> All=>Lines.Values.SelectMany(v=>v).Concat(Exchanges.SelectMany(e=>new[]{e.Opening,e.Reply})).Concat(SpanishExtras.SelectMany(e=>new[]{e.Opening,e.Reply}));
    public static int PhraseCount=>Lines.Values.Sum(v=>v.Length)+(Exchanges.Length+SpanishExtras.Length)*2;
    static PlayerDialogueCatalog(){PopulateLines();}
    static partial void PopulateLines();
}