using System.Collections.Generic; using System.Linq; 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 #region Common /// /// Name of the item /// [JsonProperty("name"), XmlElement("name")] public string? Name { get => _internal.ReadString(Models.Internal.DipSwitch.NameKey); set => _internal[Models.Internal.DipSwitch.NameKey] = value; } /// /// Tag associated with the dipswitch /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")] public string? Tag { get => _internal.ReadString(Models.Internal.DipSwitch.TagKey); set => _internal[Models.Internal.DipSwitch.TagKey] = value; } /// /// Mask associated with the dipswitch /// [JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")] public string? Mask { get => _internal.ReadString(Models.Internal.DipSwitch.MaskKey); set => _internal[Models.Internal.DipSwitch.MaskKey] = value; } /// /// Conditions associated with the dipswitch /// [JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")] public List? Conditions { get => _internal.Read(Models.Internal.DipSwitch.ConditionKey)?.ToList(); set => _internal[Models.Internal.DipSwitch.ConditionKey] = value?.ToArray(); } [JsonIgnore] public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } } /// /// Locations associated with the dipswitch /// [JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("locations")] public List? Locations { get => _internal.Read(Models.Internal.DipSwitch.DipLocationKey)?.ToList(); set => _internal[Models.Internal.DipSwitch.DipLocationKey] = value?.ToArray(); } [JsonIgnore] public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } } /// /// Settings associated with the dipswitch /// [JsonProperty("values", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("values")] public List? Values { get => _internal.Read(Models.Internal.DipSwitch.DipValueKey)?.ToList(); set => _internal[Models.Internal.DipSwitch.DipValueKey] = value?.ToArray(); } [JsonIgnore] public bool ValuesSpecified { get { return Values != null && Values.Count > 0; } } #endregion #region SoftwareList /// /// Original hardware part associated with the item /// /// This is inverted from the internal model [JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("part")] public Part? Part { get; set; } [JsonIgnore] public bool PartSpecified { get { return Part != null && (!string.IsNullOrEmpty(Part.Name) || !string.IsNullOrEmpty(Part.Interface)); } } #endregion #endregion // Fields #region Accessors /// public override string? GetName() => Name; /// public override void SetName(string? name) => Name = name; #endregion #region Constructors /// /// Create a default, empty DipSwitch object /// public DipSwitch() { _internal = new Models.Internal.DipSwitch(); Machine = new Machine(); Name = string.Empty; 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.Internal.DipSwitch ?? new Models.Internal.DipSwitch(), Part = this.Part, }; } #endregion } }