using Newtonsoft.Json; using RhythmBase.Converters; namespace RhythmBase.Components { /// /// Represents a single room that can be applied to one room only. /// [JsonConverter(typeof(RoomConverter))] public struct RDSingleRoom(RDRoomIndex index) : IEquatable { /// /// Gets a value indicating whether it can be used in the top room. /// public bool EnableTop { get; } /// /// Gets or sets the applied room. /// public RDRoomIndex Room { readonly get => _data; set => _data = value; } /// /// Gets or sets the applied room index as a byte. /// public byte Value { readonly get { for (int i = 0; i < 5; i++) { if (_data == (RDRoomIndex)(1 << i)) return (byte)i; } return byte.MaxValue; } set => _data = (RDRoomIndex)(1 << value); } /// /// Returns a string that represents the current object. /// /// A string that represents the current object. public override readonly string ToString() => string.Format("[{0}]", _data); /// /// Gets the default single room which represents room 0. /// public static RDSingleRoom Default => new((RDRoomIndex)255); /// /// Initializes a new instance of the struct with the specified room index. /// /// The room index. public RDSingleRoom(byte room) : this((RDRoomIndex)(1 << (int)room)) { } /// public static bool operator ==(RDSingleRoom R1, RDSingleRoom R2) => R1._data == R2._data; /// public static bool operator !=(RDSingleRoom R1, RDSingleRoom R2) => R1._data != R2._data; /// public static implicit operator RDSingleRoom(RDRoomIndex room) => new(room); /// public override readonly bool Equals(object? obj) => obj is RDSingleRoom e && Equals(e); /// public override readonly int GetHashCode() => HashCode.Combine(_data); /// public readonly bool Equals(RDSingleRoom other) => _data == other._data; private RDRoomIndex _data = index; } }