mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-25 15:49:51 +00:00
144 lines
4.3 KiB
C#
144 lines
4.3 KiB
C#
using System;
|
|
using System.Xml.Serialization;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace SabreTools.Metadata.DatItems.Formats
|
|
{
|
|
/// <summary>
|
|
/// Represents which DIP Switch(es) is associated with a set
|
|
/// </summary>
|
|
[JsonObject("dipswitch"), XmlRoot("dipswitch")]
|
|
public sealed class DipSwitch : DatItem<Data.Models.Metadata.DipSwitch>
|
|
{
|
|
#region Fields
|
|
|
|
public Condition? Condition { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool ConditionSpecified => Condition is not null;
|
|
|
|
public bool? Default
|
|
{
|
|
get => (_internal as Data.Models.Metadata.DipSwitch)?.Default;
|
|
set => (_internal as Data.Models.Metadata.DipSwitch)?.Default = value;
|
|
}
|
|
|
|
public DipLocation[]? DipLocation { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool DipLocationSpecified => DipLocation is not null && DipLocation.Length > 0;
|
|
|
|
public DipValue[]? DipValue { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool DipValueSpecified => DipValue is not null && DipValue.Length > 0;
|
|
|
|
public string[]? Entry { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool EntrySpecified => Entry is not null && Entry.Length > 0;
|
|
|
|
/// <inheritdoc>/>
|
|
public override Data.Models.Metadata.ItemType ItemType
|
|
=> Data.Models.Metadata.ItemType.DipSwitch;
|
|
|
|
public string? Mask
|
|
{
|
|
get => (_internal as Data.Models.Metadata.DipSwitch)?.Mask;
|
|
set => (_internal as Data.Models.Metadata.DipSwitch)?.Mask = value;
|
|
}
|
|
|
|
public string? Name
|
|
{
|
|
get => (_internal as Data.Models.Metadata.DipSwitch)?.Name;
|
|
set => (_internal as Data.Models.Metadata.DipSwitch)?.Name = value;
|
|
}
|
|
|
|
public Part? Part { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool PartSpecified
|
|
{
|
|
get
|
|
{
|
|
return Part is not null
|
|
&& (!string.IsNullOrEmpty(Part.Name)
|
|
|| !string.IsNullOrEmpty(Part.Interface));
|
|
}
|
|
}
|
|
|
|
public string? Tag
|
|
{
|
|
get => (_internal as Data.Models.Metadata.DipSwitch)?.Tag;
|
|
set => (_internal as Data.Models.Metadata.DipSwitch)?.Tag = value;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public DipSwitch() : base() { }
|
|
|
|
public DipSwitch(Data.Models.Metadata.DipSwitch item) : base(item)
|
|
{
|
|
// Handle subitems
|
|
if (item.Condition is not null)
|
|
Condition = new Condition(item.Condition);
|
|
|
|
if (item.DipLocation is not null)
|
|
DipLocation = Array.ConvertAll(item.DipLocation, dipLocation => new DipLocation(dipLocation));
|
|
|
|
if (item.DipValue is not null)
|
|
DipValue = Array.ConvertAll(item.DipValue, dipValue => new DipValue(dipValue));
|
|
|
|
if (item.Entry is not null)
|
|
Entry = Array.ConvertAll(item.Entry, entry => entry);
|
|
}
|
|
|
|
public DipSwitch(Data.Models.Metadata.DipSwitch item, Machine machine, Source source) : this(item)
|
|
{
|
|
Source = source;
|
|
CopyMachineInformation(machine);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Accessors
|
|
|
|
/// <inheritdoc/>
|
|
public override string? GetName() => Name;
|
|
|
|
/// <inheritdoc/>
|
|
public override void SetName(string? name) => Name = name;
|
|
|
|
#endregion
|
|
|
|
#region Cloning Methods
|
|
|
|
/// <inheritdoc/>
|
|
public override object Clone() => new DipSwitch(GetInternalClone());
|
|
|
|
/// <inheritdoc/>
|
|
public override Data.Models.Metadata.DipSwitch GetInternalClone()
|
|
{
|
|
var dipSwitchItem = (_internal as Data.Models.Metadata.DipSwitch)?.Clone() as Data.Models.Metadata.DipSwitch ?? [];
|
|
|
|
if (Condition is not null)
|
|
dipSwitchItem.Condition = Condition.GetInternalClone();
|
|
|
|
if (DipLocation is not null)
|
|
dipSwitchItem.DipLocation = Array.ConvertAll(DipLocation, dipLocation => dipLocation.GetInternalClone());
|
|
|
|
if (DipValue is not null)
|
|
dipSwitchItem.DipValue = Array.ConvertAll(DipValue, dipValue => dipValue.GetInternalClone());
|
|
|
|
if (Entry is not null)
|
|
dipSwitchItem.Entry = Array.ConvertAll(Entry, entry => entry);
|
|
|
|
return dipSwitchItem;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|