2025-01-11 22:00:26 -05:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Xml.Serialization;
|
2020-09-01 13:36:32 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2025-01-11 22:00:26 -05:00
|
|
|
|
using SabreTools.Core;
|
|
|
|
|
|
using SabreTools.Core.Tools;
|
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")]
|
2024-03-10 20:39:54 -04:00
|
|
|
|
public sealed class DipSwitch : DatItem<Models.Metadata.DipSwitch>
|
2020-09-01 13:36:32 -07:00
|
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
|
#region Constants
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Non-standard key for inverted logic
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public const string PartKey = "PART";
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
#region Fields
|
|
|
|
|
|
|
2024-03-10 20:39:54 -04:00
|
|
|
|
/// <inheritdoc>/>
|
|
|
|
|
|
protected override ItemType ItemType => ItemType.DipSwitch;
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc>/>
|
|
|
|
|
|
protected override string? NameKey => Models.Metadata.DipSwitch.NameKey;
|
|
|
|
|
|
|
2024-03-09 21:34:26 -05:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool ConditionsSpecified
|
2023-08-14 13:17:51 -04:00
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var conditions = GetFieldValue<Condition[]?>(Models.Metadata.DipSwitch.ConditionKey);
|
|
|
|
|
|
return conditions != null && conditions.Length > 0;
|
|
|
|
|
|
}
|
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]
|
2024-03-09 21:34:26 -05:00
|
|
|
|
public bool LocationsSpecified
|
2023-08-14 13:17:51 -04:00
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var locations = GetFieldValue<DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey);
|
|
|
|
|
|
return locations != null && locations.Length > 0;
|
|
|
|
|
|
}
|
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]
|
2024-03-09 21:34:26 -05:00
|
|
|
|
public bool ValuesSpecified
|
2023-08-14 13:17:51 -04:00
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var values = GetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey);
|
|
|
|
|
|
return values != null && values.Length > 0;
|
|
|
|
|
|
}
|
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 PartSpecified
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
|
var part = GetFieldValue<Part?>(DipSwitch.PartKey);
|
2024-03-09 21:34:26 -05:00
|
|
|
|
return part != null
|
|
|
|
|
|
&& (!string.IsNullOrEmpty(part.GetName())
|
2024-03-11 15:46:44 -04:00
|
|
|
|
|| !string.IsNullOrEmpty(part.GetStringFieldValue(Models.Metadata.Part.InterfaceKey)));
|
2020-09-07 22:00:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-03 11:19:06 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
2024-03-10 20:39:54 -04:00
|
|
|
|
public DipSwitch() : base() { }
|
2025-01-11 22:00:26 -05:00
|
|
|
|
public DipSwitch(Models.Metadata.DipSwitch item) : base(item)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Process flag values
|
|
|
|
|
|
if (GetBoolFieldValue(Models.Metadata.DipSwitch.DefaultKey) != null)
|
|
|
|
|
|
SetFieldValue<string?>(Models.Metadata.DipSwitch.DefaultKey, GetBoolFieldValue(Models.Metadata.DipSwitch.DefaultKey).FromYesNo());
|
|
|
|
|
|
|
|
|
|
|
|
// Handle subitems
|
|
|
|
|
|
var condition = item.Read<Models.Metadata.Condition>(Models.Metadata.DipSwitch.ConditionKey);
|
|
|
|
|
|
if (condition != null)
|
|
|
|
|
|
SetFieldValue<Condition?>(Models.Metadata.DipSwitch.ConditionKey, new Condition(condition));
|
|
|
|
|
|
|
|
|
|
|
|
var dipLocations = item.ReadItemArray<Models.Metadata.DipLocation>(Models.Metadata.DipSwitch.DipLocationKey);
|
|
|
|
|
|
if (dipLocations != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DipLocation[] dipLocationItems = Array.ConvertAll(dipLocations, dipLocation => new DipLocation(dipLocation));
|
|
|
|
|
|
SetFieldValue<DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey, dipLocationItems);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var dipValues = item.ReadItemArray<Models.Metadata.DipValue>(Models.Metadata.DipSwitch.DipValueKey);
|
|
|
|
|
|
if (dipValues != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DipValue[] dipValueItems = Array.ConvertAll(dipValues, dipValue => new DipValue(dipValue));
|
|
|
|
|
|
SetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey, dipValueItems);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|