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

106 lines
2.8 KiB
C#
Raw Normal View History

2024-03-09 21:34:26 -05: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
2024-03-09 21:34:26 -05:00
[JsonIgnore]
public bool ConditionsSpecified
{
2024-03-09 21:34:26 -05:00
get
{
var conditions = GetFieldValue<Condition[]?>(Models.Metadata.DipSwitch.ConditionKey);
return conditions != null && conditions.Length > 0;
}
}
2020-09-01 13:36:32 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
2024-03-09 21:34:26 -05:00
public bool LocationsSpecified
{
2024-03-09 21:34:26 -05:00
get
{
var locations = GetFieldValue<DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey);
return locations != null && locations.Length > 0;
}
}
2020-09-01 13:36:32 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
2024-03-09 21:34:26 -05:00
public bool ValuesSpecified
{
2024-03-09 21:34:26 -05:00
get
{
var values = GetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey);
return values != null && values.Length > 0;
}
}
2020-09-01 13:36:32 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool PartSpecified
{
get
{
2024-03-09 21:34:26 -05:00
var part = GetFieldValue<Part?>("PART");
return part != null
&& (!string.IsNullOrEmpty(part.GetName())
|| !string.IsNullOrEmpty(part.GetFieldValue<string?>(Models.Metadata.Part.InterfaceKey)));
2020-09-07 22:00:02 -07:00
}
}
#endregion
2020-09-01 13:36:32 -07:00
#region Accessors
/// <inheritdoc/>
2024-03-08 15:31:21 -05:00
public override string? GetName() => GetFieldValue<string>(Models.Metadata.DipSwitch.NameKey);
2020-09-02 12:19:12 -07:00
/// <inheritdoc/>
2024-03-08 15:31:21 -05:00
public override void SetName(string? name) => SetFieldValue(Models.Metadata.DipSwitch.NameKey, 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();
2024-03-08 20:42:24 -05:00
SetName(string.Empty);
2020-09-01 13:36:32 -07:00
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 ?? [],
2020-09-01 13:36:32 -07:00
};
}
#endregion
}
}