Actors/Data/VoiceListResource.cs
namespace Opium;
/// <summary>
/// A list of keyvalues, pointing to sound events.
/// Game systems, instead of playing voice sounds, will point to a string which will check the actor
/// for a voice list and use sounds from there. So we can have different characters w/ different sounds/
/// </summary>
[GameResource( "Opium/Actors/Voice List", "opvoices", "", Icon = "settings_voice" )]
public partial class VoiceListResource : GameResource
{
public class Voice
{
[KeyProperty] public string Name { get; set; }
[KeyProperty] public SoundEvent Sound { get; set; }
}
/// <summary>
/// the voices
/// </summary>
[Property] public List<Voice> Voices { get; set; } = new();
/// <summary>
/// Try to find a sound, and fall back if we don't find one.
/// </summary>
/// <param name="key"></param>
/// <param name="fallback"></param>
/// <returns></returns>
public SoundEvent Find( string key, SoundEvent fallback = null )
{
if ( Voices.FirstOrDefault( x => x.Name.Equals( key ) ) is Voice voice )
{
return voice.Sound;
}
return fallback;
}
}