using System.Xml.Serialization; using Newtonsoft.Json; using SabreTools.Core; namespace SabreTools.DatItems.Formats { /// /// Represents which DIP Switch(es) is associated with a set /// [JsonObject("dipswitch"), XmlRoot("dipswitch")] public class DipSwitch : DatItem { #region Fields [JsonIgnore] public bool ConditionsSpecified { get { var conditions = GetFieldValue(Models.Metadata.DipSwitch.ConditionKey); return conditions != null && conditions.Length > 0; } } [JsonIgnore] public bool LocationsSpecified { get { var locations = GetFieldValue(Models.Metadata.DipSwitch.DipLocationKey); return locations != null && locations.Length > 0; } } [JsonIgnore] public bool ValuesSpecified { get { var values = GetFieldValue(Models.Metadata.DipSwitch.DipValueKey); return values != null && values.Length > 0; } } [JsonIgnore] public bool PartSpecified { get { var part = GetFieldValue("PART"); return part != null && (!string.IsNullOrEmpty(part.GetName()) || !string.IsNullOrEmpty(part.GetFieldValue(Models.Metadata.Part.InterfaceKey))); } } #endregion #region Accessors /// public override string? GetName() => GetFieldValue(Models.Metadata.DipSwitch.NameKey); /// public override void SetName(string? name) => SetFieldValue(Models.Metadata.DipSwitch.NameKey, name); #endregion #region Constructors /// /// Create a default, empty DipSwitch object /// public DipSwitch() { _internal = new Models.Metadata.DipSwitch(); Machine = new Machine(); SetName(string.Empty); ItemType = ItemType.DipSwitch; } /// /// Create a DipSwitch object from the internal model /// public DipSwitch(Models.Metadata.DipSwitch? item) { _internal = item ?? []; Machine = new Machine(); ItemType = ItemType.DipSwitch; } #endregion #region Cloning Methods /// public override object Clone() { return new DipSwitch() { ItemType = this.ItemType, DupeType = this.DupeType, Machine = this.Machine.Clone() as Machine ?? new Machine(), Source = this.Source?.Clone() as Source, Remove = this.Remove, _internal = this._internal?.Clone() as Models.Metadata.DipSwitch ?? [], }; } #endregion } }