Files
SabreTools/SabreTools.DatItems/Formats/DipSwitch.cs
2024-07-17 15:46:42 -04:00

81 lines
2.2 KiB
C#

using System.Xml.Serialization;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which DIP Switch(es) is associated with a set
/// </summary>
[JsonObject("dipswitch"), XmlRoot("dipswitch")]
public sealed class DipSwitch : DatItem<Models.Metadata.DipSwitch>
{
#region Constants
/// <summary>
/// Non-standard key for inverted logic
/// </summary>
public const string PartKey = "PART";
#endregion
#region Fields
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.DipSwitch;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.DipSwitch.NameKey;
[JsonIgnore]
public bool ConditionsSpecified
{
get
{
var conditions = GetFieldValue<Condition[]?>(Models.Metadata.DipSwitch.ConditionKey);
return conditions != null && conditions.Length > 0;
}
}
[JsonIgnore]
public bool LocationsSpecified
{
get
{
var locations = GetFieldValue<DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey);
return locations != null && locations.Length > 0;
}
}
[JsonIgnore]
public bool ValuesSpecified
{
get
{
var values = GetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey);
return values != null && values.Length > 0;
}
}
[JsonIgnore]
public bool PartSpecified
{
get
{
var part = GetFieldValue<Part?>(DipSwitch.PartKey);
return part != null
&& (!string.IsNullOrEmpty(part.GetName())
|| !string.IsNullOrEmpty(part.GetStringFieldValue(Models.Metadata.Part.InterfaceKey)));
}
}
#endregion
#region Constructors
public DipSwitch() : base() { }
public DipSwitch(Models.Metadata.DipSwitch item) : base(item) { }
#endregion
}
}