mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-06 06:11:45 +00:00
Convert subitems for Configuration and DipSwitch
This commit is contained in:
@@ -155,6 +155,8 @@ namespace SabreTools.Data.Extensions
|
||||
return chip.Clone() as Chip;
|
||||
else if (self is Condition condition)
|
||||
return condition.Clone() as Condition;
|
||||
else if (self is Configuration configuration)
|
||||
return configuration.Clone() as Configuration;
|
||||
else if (self is ConfLocation confLocation)
|
||||
return confLocation.Clone() as ConfLocation;
|
||||
else if (self is ConfSetting confSetting)
|
||||
@@ -165,6 +167,8 @@ namespace SabreTools.Data.Extensions
|
||||
return deviceRef.Clone() as DeviceRef;
|
||||
else if (self is DipLocation dipLocation)
|
||||
return dipLocation.Clone() as DipLocation;
|
||||
else if (self is DipSwitch dipSwitch)
|
||||
return dipSwitch.Clone() as DipSwitch;
|
||||
else if (self is DipValue dipValue)
|
||||
return dipValue.Clone() as DipValue;
|
||||
else if (self is Display display)
|
||||
@@ -212,12 +216,6 @@ namespace SabreTools.Data.Extensions
|
||||
{
|
||||
cloneArchive.Description = selfArchive.Description;
|
||||
}
|
||||
else if (self is Configuration selfConfiguration && clone is Configuration cloneConfiguration)
|
||||
{
|
||||
cloneConfiguration.Condition = selfConfiguration.Condition?.DeepClone() as Condition;
|
||||
cloneConfiguration.Mask = selfConfiguration.Mask;
|
||||
cloneConfiguration.Tag = selfConfiguration.Tag;
|
||||
}
|
||||
else if (self is DataArea selfDataArea && clone is DataArea cloneDataArea)
|
||||
{
|
||||
cloneDataArea.Endianness = selfDataArea.Endianness;
|
||||
@@ -232,13 +230,6 @@ namespace SabreTools.Data.Extensions
|
||||
cloneDevice.Mandatory = selfDevice.Mandatory;
|
||||
cloneDevice.Tag = selfDevice.Tag;
|
||||
}
|
||||
else if (self is DipSwitch selfDipSwitch && clone is DipSwitch cloneDipSwitch)
|
||||
{
|
||||
cloneDipSwitch.Condition = selfDipSwitch.Condition?.DeepClone() as Condition;
|
||||
cloneDipSwitch.Default = selfDipSwitch.Default;
|
||||
cloneDipSwitch.Mask = selfDipSwitch.Mask;
|
||||
cloneDipSwitch.Tag = selfDipSwitch.Tag;
|
||||
}
|
||||
else if (self is Disk selfDisk && clone is Disk cloneDisk)
|
||||
{
|
||||
cloneDisk.Optional = selfDisk.Optional;
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
[JsonObject("configuration"), XmlRoot("configuration")]
|
||||
public class Configuration : DatItem
|
||||
public class Configuration : DatItem, ICloneable, IEquatable<Configuration>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
public ConfLocation[]? ConfLocation { get; set; }
|
||||
|
||||
public ConfSetting[]? ConfSetting { get; set; }
|
||||
|
||||
public string? Mask { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
@@ -18,18 +23,57 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>ConfLocation[]</remarks>
|
||||
[NoFilter]
|
||||
public const string ConfLocationKey = "conflocation";
|
||||
|
||||
/// <remarks>ConfSetting[]</remarks>
|
||||
[NoFilter]
|
||||
public const string ConfSettingKey = "confsetting";
|
||||
|
||||
#endregion
|
||||
|
||||
public Configuration() => ItemType = ItemType.Configuration;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Clone()
|
||||
{
|
||||
var obj = new Configuration();
|
||||
|
||||
obj.Condition = Condition?.Clone() as Condition;
|
||||
if (ConfLocation is not null)
|
||||
obj.ConfLocation = Array.ConvertAll(ConfLocation, i => (ConfLocation)i.Clone());
|
||||
if (ConfSetting is not null)
|
||||
obj.ConfSetting = Array.ConvertAll(ConfSetting, i => (ConfSetting)i.Clone());
|
||||
obj.Mask = Mask;
|
||||
obj.Name = Name;
|
||||
obj.Tag = Tag;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(Configuration? other)
|
||||
{
|
||||
// Null never matches
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
// Properties
|
||||
if ((Mask is null) ^ (other.Mask is null))
|
||||
return false;
|
||||
else if (Mask is not null && !Mask.Equals(other.Mask, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Name is null) ^ (other.Name is null))
|
||||
return false;
|
||||
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Tag is null) ^ (other.Tag is null))
|
||||
return false;
|
||||
else if (Tag is not null && !Tag.Equals(other.Tag, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
// Sub-items
|
||||
if ((Condition is null) ^ (other.Condition is null))
|
||||
return false;
|
||||
else if (Condition is not null && other.Condition is not null && Condition.Equals(other.Condition))
|
||||
return false;
|
||||
|
||||
// TODO: Figure out how to properly check arrays
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
[JsonObject("dipswitch"), XmlRoot("dipswitch")]
|
||||
public class DipSwitch : DatItem
|
||||
public class DipSwitch : DatItem, ICloneable, IEquatable<DipSwitch>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
@@ -13,6 +14,12 @@ namespace SabreTools.Data.Models.Metadata
|
||||
/// <remarks>(yes|no) "no"</remarks>
|
||||
public bool? Default { get; set; }
|
||||
|
||||
public DipLocation[]? DipLocation { get; set; }
|
||||
|
||||
public DipValue[]? DipValue { get; set; }
|
||||
|
||||
public string[]? Entry { get; set; }
|
||||
|
||||
public string? Mask { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
@@ -21,21 +28,60 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>DipLocation[]</remarks>
|
||||
[NoFilter]
|
||||
public const string DipLocationKey = "diplocation";
|
||||
|
||||
/// <remarks>DipValue[]</remarks>
|
||||
[NoFilter]
|
||||
public const string DipValueKey = "dipvalue";
|
||||
|
||||
/// <remarks>string[]</remarks>
|
||||
public const string EntryKey = "entry";
|
||||
|
||||
#endregion
|
||||
|
||||
public DipSwitch() => ItemType = ItemType.DipSwitch;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Clone()
|
||||
{
|
||||
var obj = new DipSwitch();
|
||||
|
||||
obj.Condition = Condition?.Clone() as Condition;
|
||||
obj.Default = Default;
|
||||
if (DipLocation is not null)
|
||||
obj.DipLocation = Array.ConvertAll(DipLocation, i => (DipLocation)i.Clone());
|
||||
if (DipValue is not null)
|
||||
obj.DipValue = Array.ConvertAll(DipValue, i => (DipValue)i.Clone());
|
||||
if (Entry is not null)
|
||||
obj.Entry = Array.ConvertAll(Entry, i => i);
|
||||
obj.Mask = Mask;
|
||||
obj.Name = Name;
|
||||
obj.Tag = Tag;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(DipSwitch? other)
|
||||
{
|
||||
// Null never matches
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
// Properties
|
||||
if ((Mask is null) ^ (other.Mask is null))
|
||||
return false;
|
||||
else if (Mask is not null && !Mask.Equals(other.Mask, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Name is null) ^ (other.Name is null))
|
||||
return false;
|
||||
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Tag is null) ^ (other.Tag is null))
|
||||
return false;
|
||||
else if (Tag is not null && !Tag.Equals(other.Tag, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
// Sub-items
|
||||
if ((Condition is null) ^ (other.Condition is null))
|
||||
return false;
|
||||
else if (Condition is not null && other.Condition is not null && Condition.Equals(other.Condition))
|
||||
return false;
|
||||
|
||||
// TODO: Figure out how to properly check arrays
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
// All other fields are tested separately
|
||||
DipSwitch? partDipSwitch = Array.Find(datItems, item => item is DipSwitch dipSwitch && dipSwitch.PartSpecified) as DipSwitch;
|
||||
Assert.NotNull(partDipSwitch);
|
||||
Part? dipSwitchPart = partDipSwitch.Read<Part>(DipSwitch.PartKey);
|
||||
Part? dipSwitchPart = partDipSwitch.Part;
|
||||
ValidatePart(dipSwitchPart);
|
||||
|
||||
// All other fields are tested separately
|
||||
@@ -418,8 +418,8 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
return new Data.Models.Metadata.Configuration
|
||||
{
|
||||
Condition = CreateMetadataCondition(),
|
||||
[Data.Models.Metadata.Configuration.ConfLocationKey] = new Data.Models.Metadata.ConfLocation[] { CreateMetadataConfLocation() },
|
||||
[Data.Models.Metadata.Configuration.ConfSettingKey] = new Data.Models.Metadata.ConfSetting[] { CreateMetadataConfSetting() },
|
||||
ConfLocation = [CreateMetadataConfLocation()],
|
||||
ConfSetting = [CreateMetadataConfSetting()],
|
||||
Mask = "mask",
|
||||
Name = "name",
|
||||
Tag = "tag",
|
||||
@@ -515,9 +515,9 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
Condition = CreateMetadataCondition(),
|
||||
Default = true,
|
||||
[Data.Models.Metadata.DipSwitch.DipLocationKey] = new Data.Models.Metadata.DipLocation[] { CreateMetadataDipLocation() },
|
||||
[Data.Models.Metadata.DipSwitch.DipValueKey] = new Data.Models.Metadata.DipValue[] { CreateMetadataDipValue() },
|
||||
[Data.Models.Metadata.DipSwitch.EntryKey] = new string[] { "entry" },
|
||||
DipLocation = [CreateMetadataDipLocation()],
|
||||
DipValue = [CreateMetadataDipValue()],
|
||||
Entry = new string[] { "entry" },
|
||||
Mask = "mask",
|
||||
Name = "name",
|
||||
Tag = "tag",
|
||||
@@ -1182,12 +1182,12 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
ValidateCondition(configuration.Condition);
|
||||
|
||||
ConfLocation[]? confLocations = configuration.Read<ConfLocation[]>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
ConfLocation[]? confLocations = configuration.ConfLocation;
|
||||
Assert.NotNull(confLocations);
|
||||
ConfLocation? confLocation = Assert.Single(confLocations);
|
||||
ValidateConfLocation(confLocation);
|
||||
|
||||
ConfSetting[]? confSettings = configuration.Read<ConfSetting[]>(Data.Models.Metadata.Configuration.ConfSettingKey);
|
||||
ConfSetting[]? confSettings = configuration.ConfSetting;
|
||||
Assert.NotNull(confSettings);
|
||||
ConfSetting? confSetting = Assert.Single(confSettings);
|
||||
ValidateConfSetting(confSetting);
|
||||
@@ -1279,17 +1279,17 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
ValidateCondition(dipSwitch.Condition);
|
||||
|
||||
DipLocation[]? dipLocations = dipSwitch.Read<DipLocation[]>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
DipLocation[]? dipLocations = dipSwitch.DipLocation;
|
||||
Assert.NotNull(dipLocations);
|
||||
DipLocation? dipLocation = Assert.Single(dipLocations);
|
||||
ValidateDipLocation(dipLocation);
|
||||
|
||||
DipValue[]? dipValues = dipSwitch.Read<DipValue[]>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
DipValue[]? dipValues = dipSwitch.DipValue;
|
||||
Assert.NotNull(dipValues);
|
||||
DipValue? dipValue = Assert.Single(dipValues);
|
||||
ValidateDipValue(dipValue);
|
||||
|
||||
string[]? entries = dipSwitch.ReadStringArray(Data.Models.Metadata.DipSwitch.EntryKey);
|
||||
string[]? entries = dipSwitch.Entry;
|
||||
Assert.NotNull(entries);
|
||||
string entry = Assert.Single(entries);
|
||||
Assert.Equal("entry", entry);
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
DipSwitch item = new DipSwitch(CreateMetadataDipSwitch());
|
||||
item.CopyMachineInformation(machine);
|
||||
item.Write(DipSwitch.PartKey, CreatePart(machine));
|
||||
item.Part = CreatePart(machine);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -707,12 +707,12 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
ValidateMetadataCondition(configuration.Condition);
|
||||
|
||||
Data.Models.Metadata.ConfLocation[]? confLocations = configuration.ReadArray<Data.Models.Metadata.ConfLocation>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
Data.Models.Metadata.ConfLocation[]? confLocations = configuration.ConfLocation;
|
||||
Assert.NotNull(confLocations);
|
||||
Data.Models.Metadata.ConfLocation? confLocation = Assert.Single(confLocations);
|
||||
ValidateMetadataConfLocation(confLocation);
|
||||
|
||||
Data.Models.Metadata.ConfSetting[]? confSettings = configuration.ReadArray<Data.Models.Metadata.ConfSetting>(Data.Models.Metadata.Configuration.ConfSettingKey);
|
||||
Data.Models.Metadata.ConfSetting[]? confSettings = configuration.ConfSetting;
|
||||
Assert.NotNull(confSettings);
|
||||
Data.Models.Metadata.ConfSetting? confSetting = Assert.Single(confSettings);
|
||||
ValidateMetadataConfSetting(confSetting);
|
||||
@@ -809,17 +809,17 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
ValidateMetadataCondition(dipSwitch.Condition);
|
||||
|
||||
Data.Models.Metadata.DipLocation[]? dipLocations = dipSwitch.ReadArray<Data.Models.Metadata.DipLocation>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
Data.Models.Metadata.DipLocation[]? dipLocations = dipSwitch.DipLocation;
|
||||
Assert.NotNull(dipLocations);
|
||||
Data.Models.Metadata.DipLocation? dipLocation = Assert.Single(dipLocations);
|
||||
ValidateMetadataDipLocation(dipLocation);
|
||||
|
||||
Data.Models.Metadata.DipValue[]? dipValues = dipSwitch.ReadArray<Data.Models.Metadata.DipValue>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
Data.Models.Metadata.DipValue[]? dipValues = dipSwitch.DipValue;
|
||||
Assert.NotNull(dipValues);
|
||||
Data.Models.Metadata.DipValue? dipValue = Assert.Single(dipValues);
|
||||
ValidateMetadataDipValue(dipValue);
|
||||
|
||||
string[]? entries = dipSwitch.ReadStringArray(Data.Models.Metadata.DipSwitch.EntryKey);
|
||||
string[]? entries = dipSwitch.Entry;
|
||||
Assert.NotNull(entries);
|
||||
string entry = Assert.Single(entries);
|
||||
Assert.Equal("entry", entry);
|
||||
|
||||
@@ -673,8 +673,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
if (filterRunner is not null && !filterRunner.Run(dipSwitch))
|
||||
continue;
|
||||
|
||||
var dipSwitchItem = new DipSwitch(dipSwitch, machine, source);
|
||||
dipSwitchItem.Write<Part?>(DipSwitch.PartKey, partItem);
|
||||
var dipSwitchItem = new DipSwitch(dipSwitch, machine, source) { Part = partItem };
|
||||
|
||||
AddItem(dipSwitchItem, statsOnly);
|
||||
// AddItemDB(dipSwitchItem, machineIndex, sourceIndex, statsOnly);
|
||||
@@ -691,7 +690,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
continue;
|
||||
|
||||
var partFeatureItem = new PartFeature(partFeature);
|
||||
partFeatureItem.Write<Part?>(DipSwitch.PartKey, partItem);
|
||||
partFeatureItem.Write<Part?>(PartFeature.PartKey, partItem);
|
||||
partFeatureItem.Source = source;
|
||||
partFeatureItem.CopyMachineInformation(machine);
|
||||
|
||||
|
||||
@@ -154,13 +154,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
AppendToMachineKey(machine, Data.Models.Metadata.Machine.DipSwitchKey, dipSwitchItem);
|
||||
|
||||
// Add Part mapping
|
||||
bool dipSwitchContainsPart = dipSwitchItem.ContainsKey(DatItems.Formats.DipSwitch.PartKey);
|
||||
if (dipSwitchContainsPart)
|
||||
{
|
||||
var partItem = dipSwitchItem.Read<DatItems.Formats.Part>(DatItems.Formats.DipSwitch.PartKey);
|
||||
if (partItem is not null)
|
||||
partMappings[partItem.GetInternalClone()] = dipSwitchItem;
|
||||
}
|
||||
if (dipSwitch.Part is not null)
|
||||
partMappings[dipSwitch.Part.GetInternalClone()] = dipSwitchItem;
|
||||
|
||||
break;
|
||||
case DatItems.Formats.Disk disk:
|
||||
@@ -580,13 +575,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
AppendToMachineKey(machine, Data.Models.Metadata.Machine.DipSwitchKey, dipSwitchItem);
|
||||
|
||||
// Add Part mapping
|
||||
bool dipSwitchContainsPart = dipSwitchItem.ContainsKey(DatItems.Formats.DipSwitch.PartKey);
|
||||
if (dipSwitchContainsPart)
|
||||
{
|
||||
var partItem = dipSwitchItem.Read<DatItems.Formats.Part>(DatItems.Formats.DipSwitch.PartKey);
|
||||
if (partItem is not null)
|
||||
partMappings[partItem.GetInternalClone()] = dipSwitchItem;
|
||||
}
|
||||
if (dipSwitch.Part is not null)
|
||||
partMappings[dipSwitch.Part.GetInternalClone()] = dipSwitchItem;
|
||||
|
||||
break;
|
||||
case DatItems.Formats.Disk disk:
|
||||
|
||||
@@ -114,9 +114,9 @@ namespace SabreTools.Metadata.DatFiles.Formats
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(dipSwitch.Read<Part?>(DipSwitch.PartKey)!.Name))
|
||||
if (string.IsNullOrEmpty(dipSwitch.Part!.Name))
|
||||
missingFields.Add(nameof(Data.Models.Metadata.Part.Name));
|
||||
if (string.IsNullOrEmpty(dipSwitch.Read<Part?>(DipSwitch.PartKey)!.Interface))
|
||||
if (string.IsNullOrEmpty(dipSwitch.Part!.Interface))
|
||||
missingFields.Add(nameof(Data.Models.Metadata.Part.Interface));
|
||||
}
|
||||
|
||||
@@ -126,9 +126,9 @@ namespace SabreTools.Metadata.DatFiles.Formats
|
||||
missingFields.Add(nameof(Data.Models.Metadata.DipSwitch.Tag));
|
||||
if (string.IsNullOrEmpty(dipSwitch.Mask))
|
||||
missingFields.Add(nameof(Data.Models.Metadata.DipSwitch.Mask));
|
||||
if (dipSwitch.ValuesSpecified)
|
||||
if (dipSwitch.DipValueSpecified)
|
||||
{
|
||||
var dipValues = dipSwitch.Read<DipValue[]?>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
var dipValues = dipSwitch.DipValue;
|
||||
if (Array.Find(dipValues!, dv => string.IsNullOrEmpty(dv.Name)) is not null)
|
||||
missingFields.Add(nameof(Data.Models.Metadata.DipValue.Name));
|
||||
if (Array.Find(dipValues!, dv => string.IsNullOrEmpty(dv.Value)) is not null)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -94,21 +94,8 @@ namespace SabreTools.Metadata
|
||||
}
|
||||
else if (self is Configuration selfConfiguration && other is Configuration otherConfiguration)
|
||||
{
|
||||
if (selfConfiguration.Mask != otherConfiguration.Mask)
|
||||
if (!selfConfiguration.Equals(otherConfiguration))
|
||||
return false;
|
||||
if (selfConfiguration.Tag != otherConfiguration.Tag)
|
||||
return false;
|
||||
|
||||
if ((selfConfiguration.Condition is null) ^ (otherConfiguration.Condition is null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (selfConfiguration.Condition is not null
|
||||
&& otherConfiguration.Condition is not null
|
||||
&& selfConfiguration.Condition.EqualTo(otherConfiguration.Condition))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (self is ConfLocation selfConfLocation && other is ConfLocation otherConfLocation)
|
||||
{
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var dipswitch = new DipSwitch
|
||||
{
|
||||
Name = item.Name,
|
||||
Entry = item[Data.Models.Metadata.DipSwitch.EntryKey] as string[],
|
||||
Entry = item.Entry,
|
||||
Default = item.Default,
|
||||
};
|
||||
return dipswitch;
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var dipswitch = new Data.Models.Metadata.DipSwitch
|
||||
{
|
||||
Name = item.Name,
|
||||
[Data.Models.Metadata.DipSwitch.EntryKey] = item.Entry,
|
||||
Entry = item.Entry,
|
||||
Default = item.Default,
|
||||
};
|
||||
return dipswitch;
|
||||
|
||||
@@ -232,11 +232,11 @@ namespace SabreTools.Serialization.CrossModel
|
||||
if (condition is not null)
|
||||
configuration.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
var confLocations = item.Read<Data.Models.Metadata.ConfLocation[]>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
var confLocations = item.ConfLocation;
|
||||
if (confLocations is not null && confLocations.Length > 0)
|
||||
configuration.ConfLocation = Array.ConvertAll(confLocations, ConvertFromInternalModel);
|
||||
|
||||
var confSettings = item.Read<Data.Models.Metadata.ConfSetting[]>(Data.Models.Metadata.Configuration.ConfSettingKey);
|
||||
var confSettings = item.ConfSetting;
|
||||
if (confSettings is not null && confSettings.Length > 0)
|
||||
configuration.ConfSetting = Array.ConvertAll(confSettings, ConvertFromInternalModel);
|
||||
|
||||
@@ -366,11 +366,11 @@ namespace SabreTools.Serialization.CrossModel
|
||||
if (condition is not null)
|
||||
dipSwitch.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
var dipLocations = item.Read<Data.Models.Metadata.DipLocation[]>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
var dipLocations = item.DipLocation;
|
||||
if (dipLocations is not null && dipLocations.Length > 0)
|
||||
dipSwitch.DipLocation = Array.ConvertAll(dipLocations, ConvertFromInternalModel);
|
||||
|
||||
var dipValues = item.Read<Data.Models.Metadata.DipValue[]>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
var dipValues = item.DipValue;
|
||||
if (dipValues is not null && dipValues.Length > 0)
|
||||
dipSwitch.DipValue = Array.ConvertAll(dipValues, ConvertFromInternalModel);
|
||||
|
||||
|
||||
@@ -265,16 +265,10 @@ namespace SabreTools.Serialization.CrossModel
|
||||
configuration.Condition = ConvertToInternalModel(item.Condition);
|
||||
|
||||
if (item.ConfLocation is not null && item.ConfLocation.Length > 0)
|
||||
{
|
||||
configuration[Data.Models.Metadata.Configuration.ConfLocationKey]
|
||||
= Array.ConvertAll(item.ConfLocation, ConvertToInternalModel);
|
||||
}
|
||||
configuration.ConfLocation = Array.ConvertAll(item.ConfLocation, ConvertToInternalModel);
|
||||
|
||||
if (item.ConfSetting is not null && item.ConfSetting.Length > 0)
|
||||
{
|
||||
configuration[Data.Models.Metadata.Configuration.ConfSettingKey]
|
||||
= Array.ConvertAll(item.ConfSetting, ConvertToInternalModel);
|
||||
}
|
||||
configuration.ConfSetting = Array.ConvertAll(item.ConfSetting, ConvertToInternalModel);
|
||||
|
||||
return configuration;
|
||||
}
|
||||
@@ -402,16 +396,10 @@ namespace SabreTools.Serialization.CrossModel
|
||||
dipSwitch.Condition = ConvertToInternalModel(item.Condition);
|
||||
|
||||
if (item.DipLocation is not null && item.DipLocation.Length > 0)
|
||||
{
|
||||
dipSwitch[Data.Models.Metadata.DipSwitch.DipLocationKey]
|
||||
= Array.ConvertAll(item.DipLocation, ConvertToInternalModel);
|
||||
}
|
||||
dipSwitch.DipLocation = Array.ConvertAll(item.DipLocation, ConvertToInternalModel);
|
||||
|
||||
if (item.DipValue is not null && item.DipValue.Length > 0)
|
||||
{
|
||||
dipSwitch[Data.Models.Metadata.DipSwitch.DipValueKey]
|
||||
= Array.ConvertAll(item.DipValue, ConvertToInternalModel);
|
||||
}
|
||||
dipSwitch.DipValue = Array.ConvertAll(item.DipValue, ConvertToInternalModel);
|
||||
|
||||
return dipSwitch;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
Mask = item.Mask,
|
||||
};
|
||||
|
||||
var dipValues = item.Read<Data.Models.Metadata.DipValue[]>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
var dipValues = item.DipValue;
|
||||
if (dipValues is not null && dipValues.Length > 0)
|
||||
dipSwitch.DipValue = Array.ConvertAll(dipValues, ConvertFromInternalModel);
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
if (item.DipValue is not null && item.DipValue.Length > 0)
|
||||
dipSwitch[Data.Models.Metadata.DipSwitch.DipValueKey] = Array.ConvertAll(item.DipValue, ConvertToInternalModel);
|
||||
dipSwitch.DipValue = Array.ConvertAll(item.DipValue, ConvertToInternalModel);
|
||||
|
||||
return dipSwitch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user