mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-23 23:35:09 +00:00
Convert subitems for Configuration and DipSwitch
This commit is contained in:
@@ -18,20 +18,20 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
[JsonIgnore]
|
||||
public bool ConditionSpecified => Condition is not null;
|
||||
|
||||
public ConfLocation[]? ConfLocation { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConfLocationSpecified => ConfLocation is not null && ConfLocation.Length > 0;
|
||||
|
||||
public ConfSetting[]? ConfSetting { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConfSettingSpecified => ConfSetting is not null && ConfSetting.Length > 0;
|
||||
|
||||
/// <inheritdoc>/>
|
||||
public override Data.Models.Metadata.ItemType ItemType
|
||||
=> Data.Models.Metadata.ItemType.Configuration;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool LocationsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var locations = Read<ConfLocation[]?>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
return locations is not null && locations.Length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public string? Mask
|
||||
{
|
||||
get => (_internal as Data.Models.Metadata.Configuration)?.Mask;
|
||||
@@ -44,16 +44,6 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
set => (_internal as Data.Models.Metadata.Configuration)?.Name = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SettingsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var settings = Read<ConfSetting[]?>(Data.Models.Metadata.Configuration.ConfSettingKey);
|
||||
return settings is not null && settings.Length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public string? Tag
|
||||
{
|
||||
get => (_internal as Data.Models.Metadata.Configuration)?.Tag;
|
||||
@@ -72,19 +62,11 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
if (item.Condition is not null)
|
||||
Condition = new Condition(item.Condition);
|
||||
|
||||
var confLocations = item.ReadArray<Data.Models.Metadata.ConfLocation>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
if (confLocations is not null)
|
||||
{
|
||||
ConfLocation[] confLocationItems = Array.ConvertAll(confLocations, confLocation => new ConfLocation(confLocation));
|
||||
Write<ConfLocation[]?>(Data.Models.Metadata.Configuration.ConfLocationKey, confLocationItems);
|
||||
}
|
||||
if (item.ConfLocation is not null)
|
||||
ConfLocation = Array.ConvertAll(item.ConfLocation, confLocation => new ConfLocation(confLocation));
|
||||
|
||||
var confSettings = item.ReadArray<Data.Models.Metadata.ConfSetting>(Data.Models.Metadata.Configuration.ConfSettingKey);
|
||||
if (confSettings is not null)
|
||||
{
|
||||
ConfSetting[] confSettingItems = Array.ConvertAll(confSettings, confSetting => new ConfSetting(confSetting));
|
||||
Write<ConfSetting[]?>(Data.Models.Metadata.Configuration.ConfSettingKey, confSettingItems);
|
||||
}
|
||||
if (item.ConfSetting is not null)
|
||||
ConfSetting = Array.ConvertAll(item.ConfSetting, confSetting => new ConfSetting(confSetting));
|
||||
}
|
||||
|
||||
public Configuration(Data.Models.Metadata.Configuration item, Machine machine, Source source) : this(item)
|
||||
@@ -108,19 +90,11 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
if (Condition is not null)
|
||||
configurationItem.Condition = Condition.GetInternalClone();
|
||||
|
||||
var confLocations = Read<ConfLocation[]?>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
if (confLocations is not null)
|
||||
{
|
||||
Data.Models.Metadata.ConfLocation[] confLocationItems = Array.ConvertAll(confLocations, confLocation => confLocation.GetInternalClone());
|
||||
configurationItem[Data.Models.Metadata.Configuration.ConfLocationKey] = confLocationItems;
|
||||
}
|
||||
if (ConfLocation is not null)
|
||||
configurationItem.ConfLocation = Array.ConvertAll(ConfLocation, confLocation => confLocation.GetInternalClone());
|
||||
|
||||
var confSettings = Read<ConfSetting[]?>(Data.Models.Metadata.Configuration.ConfSettingKey);
|
||||
if (confSettings is not null)
|
||||
{
|
||||
Data.Models.Metadata.ConfSetting[] confSettingItems = Array.ConvertAll(confSettings, confSetting => confSetting.GetInternalClone());
|
||||
configurationItem[Data.Models.Metadata.Configuration.ConfSettingKey] = confSettingItems;
|
||||
}
|
||||
if (ConfSetting is not null)
|
||||
configurationItem.ConfSetting = Array.ConvertAll(ConfSetting, confSetting => confSetting.GetInternalClone());
|
||||
|
||||
return configurationItem;
|
||||
}
|
||||
|
||||
@@ -11,15 +11,6 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
[JsonObject("dipswitch"), XmlRoot("dipswitch")]
|
||||
public sealed class DipSwitch : DatItem<Data.Models.Metadata.DipSwitch>
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Non-standard key for inverted logic
|
||||
/// </summary>
|
||||
public const string PartKey = "PART";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
@@ -27,27 +18,31 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
[JsonIgnore]
|
||||
public bool ConditionSpecified => Condition is not null;
|
||||
|
||||
[JsonIgnore]
|
||||
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;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool LocationsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var locations = Read<DipLocation[]?>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
return locations is not null && locations.Length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public string? Mask
|
||||
{
|
||||
get => (_internal as Data.Models.Metadata.DipSwitch)?.Mask;
|
||||
@@ -60,15 +55,16 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
set => (_internal as Data.Models.Metadata.DipSwitch)?.Name = value;
|
||||
}
|
||||
|
||||
public Part? Part { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool PartSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var part = Read<Part?>(PartKey);
|
||||
return part is not null
|
||||
&& (!string.IsNullOrEmpty(part.Name)
|
||||
|| !string.IsNullOrEmpty(part.Interface));
|
||||
return Part is not null
|
||||
&& (!string.IsNullOrEmpty(Part.Name)
|
||||
|| !string.IsNullOrEmpty(Part.Interface));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,16 +74,6 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
set => (_internal as Data.Models.Metadata.DipSwitch)?.Tag = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ValuesSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var values = Read<DipValue[]?>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
return values is not null && values.Length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -100,19 +86,14 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
if (item.Condition is not null)
|
||||
Condition = new Condition(item.Condition);
|
||||
|
||||
var dipLocations = item.ReadArray<Data.Models.Metadata.DipLocation>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
if (dipLocations is not null)
|
||||
{
|
||||
DipLocation[] dipLocationItems = Array.ConvertAll(dipLocations, dipLocation => new DipLocation(dipLocation));
|
||||
Write<DipLocation[]?>(Data.Models.Metadata.DipSwitch.DipLocationKey, dipLocationItems);
|
||||
}
|
||||
if (item.DipLocation is not null)
|
||||
DipLocation = Array.ConvertAll(item.DipLocation, dipLocation => new DipLocation(dipLocation));
|
||||
|
||||
var dipValues = item.ReadArray<Data.Models.Metadata.DipValue>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
if (dipValues is not null)
|
||||
{
|
||||
DipValue[] dipValueItems = Array.ConvertAll(dipValues, dipValue => new DipValue(dipValue));
|
||||
Write<DipValue[]?>(Data.Models.Metadata.DipSwitch.DipValueKey, dipValueItems);
|
||||
}
|
||||
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)
|
||||
@@ -136,19 +117,14 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
if (Condition is not null)
|
||||
dipSwitchItem.Condition = Condition.GetInternalClone();
|
||||
|
||||
var dipLocations = Read<DipLocation[]?>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
if (dipLocations is not null)
|
||||
{
|
||||
Data.Models.Metadata.DipLocation[] dipLocationItems = Array.ConvertAll(dipLocations, dipLocation => dipLocation.GetInternalClone());
|
||||
dipSwitchItem[Data.Models.Metadata.DipSwitch.DipLocationKey] = dipLocationItems;
|
||||
}
|
||||
if (DipLocation is not null)
|
||||
dipSwitchItem.DipLocation = Array.ConvertAll(DipLocation, dipLocation => dipLocation.GetInternalClone());
|
||||
|
||||
var dipValues = Read<DipValue[]?>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
if (dipValues is not null)
|
||||
{
|
||||
Data.Models.Metadata.DipValue[] dipValueItems = Array.ConvertAll(dipValues, dipValue => dipValue.GetInternalClone());
|
||||
dipSwitchItem[Data.Models.Metadata.DipSwitch.DipValueKey] = dipValueItems;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user