using Newtonsoft.Json; using RhythmBase.Components; using RhythmBase.Utils; namespace RhythmBase.Events { /// /// The base class of the event. /// All event types inherit directly or indirectly from this. /// public abstract class BaseEvent : IBaseEvent { /// /// The base class of the event. /// All event types inherit directly or indirectly from this. /// protected BaseEvent() { _beat = new RDBeat(1f); Active = true; } /// /// Event type. /// [JsonIgnore] public abstract EventType Type { get; } /// /// Column to which the event belongs. /// [JsonIgnore] public abstract Tabs Tab { get; } /// /// The beat of the event. /// [JsonIgnore] public virtual RDBeat Beat { get => _beat; set { if (_beat.BaseLevel == null) _beat = value.BaseLevel == null ? value : value.WithoutBinding(); else { value = new RDBeat(_beat.BaseLevel.Calculator, value); _beat.BaseLevel.Remove(this); value.BaseLevel?.Add(this); _beat = value; } } } /// /// The number of rows this event is on. /// public virtual int Y { get; set; } /// /// Event tag. /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string Tag { get; set; } = ""; /// /// Event conditions. /// [JsonProperty("if", DefaultValueHandling = DefaultValueHandling.Ignore)] public Condition? Condition { get; set; } /// /// Indicates whether this event is activated. /// public bool Active { get; set; } /// /// Clone this event and its basic properties. /// If it is of the same type as the source event, then it will be cloned. /// /// Type that will be generated. /// A new instance with the same base properties as the source instance. public virtual TEvent Clone() where TEvent : IBaseEvent, new() { if (EventTypeUtils.ToEnum() == Type) { TEvent e = (TEvent)MemberwiseClone(); ((BaseEvent)(object)e)._beat = Beat.WithoutBinding(); return e; } TEvent temp = new() { Beat = Beat.WithoutBinding(), Y = Y, Tag = Tag, Condition = Condition, Active = Active }; if (Condition != null) temp.Condition = new() { ConditionLists = [.. Condition.ConditionLists] }; return temp; } internal virtual TEvent Clone(RDLevel level) where TEvent : IBaseEvent, new() { TEvent temp = new() { Beat = Beat.WithoutBinding(), Y = Y, Tag = Tag, Condition = Condition, Active = Active }; if (Condition != null) temp.Condition = new() { ConditionLists = [.. Condition.ConditionLists] }; return temp; } /// public override string ToString() => $"{Beat} {Type}"; internal RDBeat _beat; } }