using Newtonsoft.Json; using Newtonsoft.Json.Linq; using RhythmBase.Components; using RhythmBase.Exceptions; using RhythmBase.Extensions; using RhythmBase.Settings; namespace RhythmBase.Events { /// /// Represents a custom row event in the rhythm base. /// public class CustomRowEvent : BaseRowAction { /// /// Gets the type of the event. /// public override EventType Type { get; } /// /// Gets the actual type of the event from the data. /// [JsonIgnore] public string ActureType => Data["Type".ToLowerCamelCase()]?.ToString() ?? ""; /// /// Gets the tab associated with the event. /// public override Tabs Tab { get; } /// /// Initializes a new instance of the class. /// public CustomRowEvent() { Data = []; Type = EventType.CustomRowEvent; Tab = Tabs.Rows; } /// /// Initializes a new instance of the class with the specified data. /// /// The data for the event. public CustomRowEvent(JObject data) { Type = EventType.CustomRowEvent; Tab = Tabs.Rows; Data = data; Beat = new RDBeat(Data["bar"]?.ToObject() ?? 1, Data["beat"]?.ToObject() ?? 1f); Tag = Data["tag"]?.ToObject() ?? ""; Condition = Data["condition"] == null ? null : Condition.Load(Data["condition"]?.ToObject() ?? ""); Active = Data["active"]?.ToObject() ?? true; } /// /// Returns a string that represents the current object. /// /// A string that represents the current object. public override string ToString() => $"{Beat} *{ActureType}"; /// /// Tries to convert the current event to a base event. /// /// The base event to convert to. /// The type of the event. /// true if the conversion was successful; otherwise, false. public virtual bool TryConvert(ref BaseEvent value, ref EventType? type) => TryConvert(ref value, ref type, new LevelReadOrWriteSettings()); /// /// Tries to convert the current event to a base event with the specified settings. /// /// The base event to convert to. /// The type of the event. /// The settings for the conversion. /// true if the conversion was successful; otherwise, false. public virtual bool TryConvert(ref BaseEvent value, ref EventType? type, LevelReadOrWriteSettings settings) => TryConvert(ref value, ref type, settings); /// /// Implicitly converts a to a . /// /// The custom row event to convert. public static implicit operator CustomEvent(CustomRowEvent e) => new(e.Data); /// /// Explicitly converts a to a . /// /// The custom event to convert. /// The converted custom row event. /// Thrown when the row field is missing from the data. public static explicit operator CustomRowEvent(CustomEvent e) { return e.Data["row"] != null ? new CustomRowEvent(e.Data) : throw new RhythmBaseException("The row field is missing from the field contained in this object."); } /// /// Gets or sets the data for the event. /// public JObject Data; } }