2020-09-01 13:36:32 -07:00
|
|
|
|
using System.Collections.Generic;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
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
|
|
|
|
|
|
|
2020-09-03 11:19:06 -07:00
|
|
|
|
#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")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Name
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.ReadString(Models.Internal.DipSwitch.NameKey);
|
|
|
|
|
|
set => _internal[Models.Internal.DipSwitch.NameKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
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")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Tag
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.ReadString(Models.Internal.DipSwitch.TagKey);
|
|
|
|
|
|
set => _internal[Models.Internal.DipSwitch.TagKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
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")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Mask
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.ReadString(Models.Internal.DipSwitch.MaskKey);
|
|
|
|
|
|
set => _internal[Models.Internal.DipSwitch.MaskKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
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")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public List<Condition>? Conditions
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.Read<Condition[]>(Models.Internal.DipSwitch.ConditionKey)?.ToList();
|
|
|
|
|
|
set => _internal[Models.Internal.DipSwitch.ConditionKey] = value?.ToArray();
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
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")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public List<DipLocation>? Locations
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.Read<DipLocation[]>(Models.Internal.DipSwitch.DipLocationKey)?.ToList();
|
|
|
|
|
|
set => _internal[Models.Internal.DipSwitch.DipLocationKey] = value?.ToArray();
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
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")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public List<DipValue>? Values
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.Read<DipValue[]>(Models.Internal.DipSwitch.DipValueKey)?.ToList();
|
|
|
|
|
|
set => _internal[Models.Internal.DipSwitch.DipValueKey] = value?.ToArray();
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
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
|
|
|
|
|
|
|
2020-09-03 11:19:06 -07:00
|
|
|
|
#region SoftwareList
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Original hardware part associated with the item
|
|
|
|
|
|
/// </summary>
|
2023-08-14 13:17:51 -04:00
|
|
|
|
/// <remarks>This is inverted from the internal model</remarks>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("part")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public Part? Part { get; set; }
|
2020-09-03 11:19:06 -07:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-03 11:19:06 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion // Fields
|
|
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
#region Accessors
|
|
|
|
|
|
|
2020-12-13 14:01:16 -08:00
|
|
|
|
/// <inheritdoc/>
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public override string? GetName() => Name;
|
2020-09-02 12:19:12 -07:00
|
|
|
|
|
2020-12-13 14:01:16 -08:00
|
|
|
|
/// <inheritdoc/>
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public override void SetName(string? name) => Name = name;
|
2020-12-13 14:01:16 -08:00
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a default, empty DipSwitch object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DipSwitch()
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
_internal = new Models.Internal.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(),
|
2023-08-14 13:17:51 -04:00
|
|
|
|
Source = this.Source?.Clone() as Source,
|
2020-09-01 13:36:32 -07:00
|
|
|
|
Remove = this.Remove,
|
|
|
|
|
|
|
2023-08-14 22:33:05 -04:00
|
|
|
|
_internal = this._internal?.Clone() as Models.Internal.DipSwitch ?? new Models.Internal.DipSwitch(),
|
2020-09-03 11:19:06 -07:00
|
|
|
|
|
|
|
|
|
|
Part = this.Part,
|
2020-09-01 13:36:32 -07:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|