/* Yarn Spinner is licensed to you under the terms found in the file LICENSE.md. */ using UnityEngine; #nullable enable namespace Yarn.Unity { /// /// Represents a line, ready to be presented to the user in the localisation /// they have specified. /// public class LocalizedLine { /// /// DialogueLine's ID /// public string TextID = ""; /// /// DialogueLine's inline expression's substitution /// public string[] Substitutions = System.Array.Empty(); /// /// DialogueLine's text /// public string? RawText; /// /// Any metadata associated with this line. /// public string[] Metadata = System.Array.Empty(); /// /// The name of the character, if present. /// /// /// This value will be if the line does not have /// a character name. /// public string? CharacterName { get { if (Text.TryGetAttributeWithName("character", out var characterNameAttribute)) { if (characterNameAttribute.Properties.TryGetValue("name", out var value)) { return value.StringValue; } } return null; } } /// /// The asset associated with this line, if any. /// public Object? Asset; /// /// The object that created this line. /// Most of the time will be the that passed the presenter the line. /// /// /// This exists for situations where you need the dialogue runner (or your custom equivalent) to send back messages. /// In particular this is used by the to get a reference to the dialogue runner to advance lines after playback is finished without needing a specific reference. /// Allowing the presenter to be reused across multiple runners. /// public object? Source; /// /// The underlying for this /// line. /// public Markup.MarkupParseResult Text { get; set; } /// /// The underlying for this /// line, with any `character` attribute removed. /// /// /// If the line has no `character` attribute, this method returns the /// same value as . /// public Markup.MarkupParseResult TextWithoutCharacterName { get { // If a 'character' attribute is present, remove its text if (Text.TryGetAttributeWithName("character", out var characterNameAttribute)) { // because of how we delete the text we also clear up the attributes // most of the time this is the right play // however the character feels important enough to add it back in var characterless = Text.DeleteRange(characterNameAttribute); characterless.Attributes.Add(characterNameAttribute); return characterless; } else { return Text; } } } /// /// A object that represents content not /// being found. /// public static readonly LocalizedLine InvalidLine = new LocalizedLine { Asset = null, Metadata = System.Array.Empty(), RawText = "!! ERROR: Missing line!", Substitutions = System.Array.Empty(), TextID = "", Text = new Markup.MarkupParseResult("!! ERROR: Missing line!", new System.Collections.Generic.List()) }; } }