using System.Diagnostics.CodeAnalysis; namespace RhythmBase.Components.RichText { /// /// Represents the style of a rich string. /// public struct RDDialoguePhraseStyle : IRDRichStringStyle { /// /// Gets or sets the color of the text. /// public RDColor? Color { get; set; } /// /// Gets or sets the speed of the text animation. /// public float? Speed { get; set; } /// /// Gets or sets the volume of the text. /// public float? Volume { get; set; } /// /// Gets or sets the pitch of the text. /// public float? Pitch { get; set; } /// /// Gets or sets the pitch range of the text. /// public float? PitchRange { get; set; } /// /// Gets or sets a value indicating whether the text should shake. /// public bool Shake { get; set; } /// /// Gets or sets the radius of the shake effect. /// public float? ShakeRadius { get; set; } /// /// Gets or sets a value indicating whether the text should have a wave effect. /// public bool Wave { get; set; } /// /// Gets or sets the height of the wave effect. /// public float? WaveHeight { get; set; } /// /// Gets or sets the speed of the wave effect. /// public float? WaveSpeed { get; set; } /// /// Gets or sets a value indicating whether the text should have a swirl effect. /// public bool Swirl { get; set; } /// /// Gets or sets the radius of the swirl effect. /// public float? SwirlRadius { get; set; } /// /// Gets or sets the speed of the swirl effect. /// public float? SwirlSpeed { get; set; } /// /// Gets or sets a value indicating whether the text should be sticky. /// public bool Sticky { get; set; } /// /// Gets or sets a value indicating whether the text should be loud. /// public bool Loud { get; set; } /// /// Gets or sets a value indicating whether the text should be bold. /// public bool Bold { get; set; } /// /// Gets or sets a value indicating whether the text should be whispered. /// public bool Whisper { get; set; } /// public static bool HasPhrase => true; /// /// Sets the property of the rich string style based on the provided name and value. /// /// The name of the property to set. /// The value to set for the property. /// True if the property was successfully set; otherwise, false. public bool SetProperty(string name, string value) { switch (name) { case "color": if (RDColor.TryFromName(value, out RDColor color)) Color = color; else if (RDColor.TryFromRgba(value, out color)) Color = color; else return false; break; case "speed": Speed = float.Parse(value); break; case "volume": Volume = float.Parse(value); break; case "pitch": Pitch = float.Parse(value); break; case "pitchRange": PitchRange = float.Parse(value); break; case "shake": Shake = bool.Parse(value); break; case "shakeRadius": ShakeRadius = float.Parse(value); break; case "wave": Wave = bool.Parse(value); break; case "waveHeight": WaveHeight = float.Parse(value); break; case "waveSpeed": WaveSpeed = float.Parse(value); break; case "swirl": Swirl = bool.Parse(value); break; case "swirlRadius": SwirlRadius = float.Parse(value); break; case "swirlSpeed": SwirlSpeed = float.Parse(value); break; case "sticky": Sticky = bool.Parse(value); break; case "loud": Loud = bool.Parse(value); break; case "bold": Bold = bool.Parse(value); break; case "whisper": Whisper = bool.Parse(value); break; default: return false; } return true; } /// /// Removes the property of the rich string style based on the provided name. /// /// The name of the property to remove. /// True if the property was successfully removed; otherwise, false. public bool ResetProperty(string name) { switch (name) { case "color": Color = null; break; case "speed": Speed = null; break; case "volume": Volume = null; break; case "pitch": Pitch = null; break; case "pitchRange": PitchRange = null; break; case "shake": Shake = false; break; case "shakeRadius": ShakeRadius = null; break; case "wave": Wave = false; break; case "waveHeight": WaveHeight = null; break; case "waveSpeed": WaveSpeed = null; break; case "swirl": Swirl = false; break; case "swirlRadius": SwirlRadius = null; break; case "swirlSpeed": SwirlSpeed = null; break; case "sticky": Sticky = false; break; case "loud": Loud = false; break; case "bold": Bold = false; break; case "whisper": Whisper = false; break; default: return false; } return true; } /// public static string GetXmlTag(RDDialoguePhraseStyle before, RDDialoguePhraseStyle after) { string tag = ""; IRDRichStringStyle.TryAddTag(ref tag, "color", before.Color?.TryGetName(out string[] namesbefore) == true ? namesbefore[0].ToLower() : before.Color?.ToString(before.Color?.A == 255 ? "#RRGGBB" : "#RRGGBBAA"), after.Color?.TryGetName(out string[] namesafter) == true ? namesafter[0].ToLower() : after.Color?.ToString(after.Color?.A == 255 ? "#RRGGBB" : "#RRGGBBAA")); IRDRichStringStyle.TryAddTag(ref tag, "speed", before.Speed?.ToString(), after.Speed?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "volume", before.Volume?.ToString(), after.Volume?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "pitch", before.Pitch?.ToString(), after.Pitch?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "pitchRange", before.PitchRange?.ToString(), after.PitchRange?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "shake", before.Shake, after.Shake); IRDRichStringStyle.TryAddTag(ref tag, "shakeRadius", before.ShakeRadius?.ToString(), after.ShakeRadius?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "wave", before.Wave, after.Wave); IRDRichStringStyle.TryAddTag(ref tag, "waveHeight", before.WaveHeight?.ToString(), after.WaveHeight?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "waveSpeed", before.WaveSpeed?.ToString(), after.WaveSpeed?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "swirl", before.Swirl, after.Swirl); IRDRichStringStyle.TryAddTag(ref tag, "swirlRadius", before.SwirlRadius?.ToString(), after.SwirlRadius?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "swirlSpeed", before.SwirlSpeed?.ToString(), after.SwirlSpeed?.ToString()); IRDRichStringStyle.TryAddTag(ref tag, "sticky", before.Sticky, after.Sticky); IRDRichStringStyle.TryAddTag(ref tag, "loud", before.Loud, after.Loud); IRDRichStringStyle.TryAddTag(ref tag, "bold", before.Bold, after.Bold); IRDRichStringStyle.TryAddTag(ref tag, "whisper", before.Whisper, after.Whisper); return tag; } /// public static bool operator ==(RDDialoguePhraseStyle left, RDDialoguePhraseStyle right) => left.Color == right.Color && left.Speed == right.Speed && left.Volume == right.Volume && left.Pitch == right.Pitch && left.PitchRange == right.PitchRange && left.Shake == right.Shake && left.ShakeRadius == right.ShakeRadius && left.Wave == right.Wave && left.WaveHeight == right.WaveHeight && left.WaveSpeed == right.WaveSpeed && left.Swirl == right.Swirl && left.SwirlRadius == right.SwirlRadius && left.SwirlSpeed == right.SwirlSpeed && left.Sticky == right.Sticky && left.Loud == right.Loud && left.Bold == right.Bold && left.Whisper == right.Whisper; /// public static bool operator !=(RDDialoguePhraseStyle left, RDDialoguePhraseStyle right) => !(left == right); /// public readonly override bool Equals([NotNullWhen(true)] object? obj) => obj is RDDialoguePhraseStyle e && base.Equals(e); /// public readonly bool Equals(RDDialoguePhraseStyle other) => this == other; /// public readonly override int GetHashCode() { return base.GetHashCode(); } } }