using System.Diagnostics.CodeAnalysis;
namespace RhythmBase.Components.RichText
{
///
/// Enum representing the different types of rich string events.
///
public enum RDDialogueToneType
{
///
/// Static event type.
///
Static,
///
/// Flash event type.
///
Flash,
///
/// Very slow event type.
///
VerySlow,
///
/// Slow event type.
///
Slow,
///
/// Normal event type.
///
Normal,
///
/// Fast event type.
///
Fast,
///
/// Very fast event type.
///
VeryFast,
///
/// Very very fast event type.
///
VeryVeryFast,
///
/// Excited event type.
///
Excited,
///
/// Shout event type.
///
Shout,
///
/// Shake event type.
///
Shake,
///
/// Pause event type.
///
Pause,
}
///
/// Class representing a rich string event.
///
/// Rich string event type.
/// Rich string event index.
public record struct RDDialogueTone(RDDialogueToneType Type, int Index)
{
///
/// Gets the pause duration for the dialogue event.
///
public int? Pause { get; init; }
///
/// Serializes the rich string event type to its corresponding string representation.
///
/// A string representation of the rich string event type.
/// Thrown when the event type is not implemented.
public string Serialize() => "[" + Type switch
{
RDDialogueToneType.Static => "static",
RDDialogueToneType.Flash => "flash",
RDDialogueToneType.VerySlow => "vslow",
RDDialogueToneType.Slow => "slow",
RDDialogueToneType.Normal => "normal",
RDDialogueToneType.Fast => "fast",
RDDialogueToneType.VeryFast => "vfast",
RDDialogueToneType.VeryVeryFast => "vvvfast",
RDDialogueToneType.Excited => "excited",
RDDialogueToneType.Shout => "shout",
RDDialogueToneType.Shake => "shake",
RDDialogueToneType.Pause => Pause?.ToString(),
_ => throw new NotImplementedException(),
} + "]";
///
/// Creates a new instance of based on the provided type and index.
///
/// The string representation of the event type.
/// The index of the event.
/// The created instance if successful, otherwise null.
/// True if the event was successfully created, otherwise false.
public static bool Create(string type, int index, [NotNullWhen(true)] out RDDialogueTone? result)
{
RDDialogueToneType? eventType = type switch
{
"static" => RDDialogueToneType.Static,
"flash" => RDDialogueToneType.Flash,
"vslow" => RDDialogueToneType.VerySlow,
"slow" => RDDialogueToneType.Slow,
"normal" => RDDialogueToneType.Normal,
"fast" => RDDialogueToneType.Fast,
"vfast" => RDDialogueToneType.VeryFast,
"vvvfast" => RDDialogueToneType.VeryVeryFast,
"excited" => RDDialogueToneType.Excited,
"shout" => RDDialogueToneType.Shout,
"shake" => RDDialogueToneType.Shake,
_ => null,
};
if (eventType is null)
{
if (int.TryParse(type, out int pause))
{
result = new(RDDialogueToneType.Pause, index) { Pause = pause };
return true;
}
result = null;
return false;
}
result = new(eventType.Value, index);
return true;
}
}
}