VoiceLines/VoiceLine.cs

A GameResource representing a localized voice line, holding per-language SoundEvent entries and subtitle strings, with convenience properties that return the sound and subtitle for the current selected language or fall back to DefaultLanguage. It validates presence of default language entries on PostLoad and logs an error if missing.

File Access
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Sandbox;

namespace BrickJam.VoiceLines;

/// <summary>
/// A localized voice line resource (sound + subtitle per language). Scene-System port of legacy
/// <c>VoiceLine</c> — the resource is unchanged; only the runtime player/subtitle UI is deferred.
/// </summary>
[AssetType( Name = "Voice Line", Extension = "voli", Category = "Audio" )]
public class VoiceLine : GameResource
{
	public string DefaultLanguage { get; set; }
	public Dictionary<string, SoundEvent> Sounds { get; set; }
	public Dictionary<string, string> Subtitles { get; set; }

	[JsonIgnore]
	public bool IsValidVoiceLine => DefaultLanguage != default
		&& (Sounds?.ContainsKey( DefaultLanguage ) ?? false)
		&& (Subtitles?.ContainsKey( DefaultLanguage ) ?? false);

	[Hide, JsonIgnore]
	public SoundEvent LocalizedSound => Sounds.TryGetValue( Language.SelectedCode, out var sound )
		? sound
		: Sounds[DefaultLanguage];

	[Hide, JsonIgnore]
	public string LocalizedSubtitle => Subtitles.TryGetValue( Language.SelectedCode, out var subtitle )
		? subtitle
		: Subtitles[DefaultLanguage];

	protected override void PostLoad()
	{
		base.PostLoad();

		if ( !IsValidVoiceLine )
			Log.Error( $"voice line \"{ResourceName}\" lacks a sound or a subtitle for the language {DefaultLanguage}" );
	}
}