Files
SabreTools/SabreTools.DatItems/Formats/DipSwitch.cs

163 lines
5.0 KiB
C#
Raw Normal View History

2020-09-01 13:36:32 -07:00
using System.Collections.Generic;
using System.Linq;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-09-01 13:36:32 -07:00
using Newtonsoft.Json;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2020-09-01 13:36:32 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
2020-09-01 13:36:32 -07:00
{
/// <summary>
/// Represents which DIP Switch(es) is associated with a set
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("dipswitch"), XmlRoot("dipswitch")]
2020-09-01 13:36:32 -07:00
public class DipSwitch : DatItem
{
#region Fields
#region Common
2020-09-02 12:19:12 -07:00
/// <summary>
/// Name of the item
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("name"), XmlElement("name")]
public string? Name
{
2023-09-04 23:51:37 -04:00
get => _internal.ReadString(Models.Metadata.DipSwitch.NameKey);
set => _internal[Models.Metadata.DipSwitch.NameKey] = value;
}
2020-09-02 12:19:12 -07:00
2020-09-01 13:36:32 -07:00
/// <summary>
/// Tag associated with the dipswitch
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
public string? Tag
{
2023-09-04 23:51:37 -04:00
get => _internal.ReadString(Models.Metadata.DipSwitch.TagKey);
set => _internal[Models.Metadata.DipSwitch.TagKey] = value;
}
2020-09-01 13:36:32 -07:00
/// <summary>
/// Mask associated with the dipswitch
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")]
public string? Mask
{
2023-09-04 23:51:37 -04:00
get => _internal.ReadString(Models.Metadata.DipSwitch.MaskKey);
set => _internal[Models.Metadata.DipSwitch.MaskKey] = value;
}
2020-09-01 13:36:32 -07:00
/// <summary>
/// Conditions associated with the dipswitch
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
public List<Condition>? Conditions
{
2023-09-04 23:51:37 -04:00
get => _internal.Read<Condition[]>(Models.Metadata.DipSwitch.ConditionKey)?.ToList();
set => _internal[Models.Metadata.DipSwitch.ConditionKey] = value?.ToArray();
}
2020-09-01 13:36:32 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
2020-09-01 13:36:32 -07:00
/// <summary>
/// Locations associated with the dipswitch
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("locations")]
public List<DipLocation>? Locations
{
2023-09-04 23:51:37 -04:00
get => _internal.Read<DipLocation[]>(Models.Metadata.DipSwitch.DipLocationKey)?.ToList();
set => _internal[Models.Metadata.DipSwitch.DipLocationKey] = value?.ToArray();
}
2020-09-01 13:36:32 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } }
2020-09-01 13:36:32 -07:00
/// <summary>
/// Settings associated with the dipswitch
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("values", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("values")]
public List<DipValue>? Values
{
2023-09-04 23:51:37 -04:00
get => _internal.Read<DipValue[]>(Models.Metadata.DipSwitch.DipValueKey)?.ToList();
set => _internal[Models.Metadata.DipSwitch.DipValueKey] = value?.ToArray();
}
2020-09-01 13:36:32 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ValuesSpecified { get { return Values != null && Values.Count > 0; } }
2020-09-01 13:36:32 -07:00
#endregion
#region SoftwareList
/// <summary>
/// Original hardware part associated with the item
/// </summary>
/// <remarks>This is inverted from the internal model</remarks>
2022-11-03 12:22:17 -07:00
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("part")]
public Part? Part { get; set; }
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool PartSpecified
{
get
{
2020-09-07 22:33:48 -07:00
return Part != null
&& (!string.IsNullOrEmpty(Part.Name)
|| !string.IsNullOrEmpty(Part.Interface));
2020-09-07 22:00:02 -07:00
}
}
#endregion
#endregion // Fields
2020-09-01 13:36:32 -07:00
#region Accessors
/// <inheritdoc/>
public override string? GetName() => Name;
2020-09-02 12:19:12 -07:00
/// <inheritdoc/>
public override void SetName(string? name) => Name = name;
2020-09-01 13:36:32 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty DipSwitch object
/// </summary>
public DipSwitch()
{
2023-09-04 23:51:37 -04:00
_internal = new Models.Metadata.DipSwitch();
2023-08-15 01:38:01 -04:00
Machine = new Machine();
2020-09-01 13:36:32 -07:00
Name = string.Empty;
ItemType = ItemType.DipSwitch;
}
#endregion
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-09-01 13:36:32 -07:00
public override object Clone()
{
return new DipSwitch()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
2023-08-15 01:38:01 -04:00
Machine = this.Machine.Clone() as Machine ?? new Machine(),
Source = this.Source?.Clone() as Source,
2020-09-01 13:36:32 -07:00
Remove = this.Remove,
2024-02-28 19:19:50 -05:00
_internal = this._internal?.Clone() as Models.Metadata.DipSwitch ?? [],
Part = this.Part,
2020-09-01 13:36:32 -07:00
};
}
#endregion
}
}