using Microsoft.VisualBasic.CompilerServices;
using Newtonsoft.Json;
using RhythmBase.Events;
using RhythmBase.Exceptions;
namespace RhythmBase.Components
{
///
/// A decoration.
///
[JsonObject]
public class DecorationEventCollection : OrderedEventCollection
{
///
/// Decorated ID.
///
[JsonProperty("id")]
public string Id
{
get => _id;
set => _id = value;
}
///
/// Decoration index.
///
[JsonProperty("row")]
public int Index => Parent?.Decorations.ToList().IndexOf(this) ?? throw new RhythmBaseException();
///
/// Room.
///
[JsonProperty("rooms")]
public RDSingleRoom Room { get; set; }
///
/// The file reference used by the decoration.
///
[JsonProperty("filename")]
public string Filename { get; set; } = "";
///
/// Decoration depth.
///
public int Depth { get; set; }
///
/// The filter used for this decoration.
///
public Filters Filter { get; set; }
///
/// The initial visibility of this decoration.
///
public bool Visible { get; set; }
///
/// Initializes a new instance of the class.
///
public DecorationEventCollection()
{
Room = new RDSingleRoom(RDRoomIndex.Room1);
}
/// Decoration room.
internal DecorationEventCollection(RDSingleRoom room)
{
Room = room;
_id = GetHashCode().ToString();
}
///
/// Add an event to decoration.
///
/// Decoration event.
public override void Add(BaseDecorationAction item)
{
item._parent?.Remove(item);
item._parent = this;
Parent?.Add(item);
}
internal void AddSafely(BaseDecorationAction item) => base.Add(item);
///
/// Remove an event from decoration.
///
/// A decoration event.
public override bool Remove(BaseDecorationAction item) => Parent?.Remove(item) ?? throw new RhythmBaseException();
internal bool RemoveSafely(BaseDecorationAction item) => base.Remove(item);
///
public override string ToString() => string.Format("{0}, {1}, {2}, {3}",
[
_id,
Index,
Room,
Filename
]);
internal DecorationEventCollection Clone() => (DecorationEventCollection)MemberwiseClone();
private string _id = "";
[JsonIgnore]
internal RDLevel? Parent = null;
}
}