using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RhythmBase.Components;
using RhythmBase.Exceptions;
using RhythmBase.Extensions;
using RhythmBase.Settings;
namespace RhythmBase.Events
{
///
public class CustomDecorationEvent : BaseDecorationAction
{
///
public override EventType Type { get; }
///
/// Gets the actual type of the decoration event.
///
[JsonIgnore]
public string ActureType
{
get
{
return Data["Type".ToLowerCamelCase()]?.ToString() ?? "";
}
}
///
public override Tabs Tab { get; }
///
/// Initializes a new instance of the class.
///
public CustomDecorationEvent()
{
Data = [];
Type = EventType.CustomDecorationEvent;
Tab = Tabs.Decorations;
}
///
/// Initializes a new instance of the class with the specified data.
///
/// The JSON data for the event.
public CustomDecorationEvent(JObject data)
{
Data = data ?? [];
Type = EventType.CustomDecorationEvent;
Tab = Tabs.Decorations;
Beat = new RDBeat(Data["bar"]?.ToObject() ?? 1, (Data["beat"]?.ToObject() ?? 1f));
Tag = Data["tag"]?.ToObject() ?? "";
Condition = Data["condition"] != null
? Data["condition"] is null ? null : Condition.Load(Data["condition"]!.ToObject() ?? "")
: null;
Active = Data["active"]?.ToObject() ?? true;
}
///
public override string ToString() => $"{Beat} *{ActureType}";
///
public virtual bool TryConvert(ref BaseEvent value, ref EventType? type) => TryConvert(ref value, ref type, new LevelReadOrWriteSettings());
///
public virtual bool TryConvert(ref BaseEvent value, ref EventType? type, LevelReadOrWriteSettings settings) => TryConvert(ref value, ref type, settings);
///
/// Explicit conversion from to .
///
/// The instance.
/// Thrown when the row field is missing from the data.
public static explicit operator CustomDecorationEvent(CustomEvent e)
{
return e.Data["row"] != null
? new CustomDecorationEvent(e.Data)
: throw new RhythmBaseException("The row field is missing from the field contained in this object.");
}
///
/// Gets or sets the JSON data for the event.
///
public JObject Data;
}
}