mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Turn Condition keys into properties as a test
This commit is contained in:
@@ -143,7 +143,9 @@ namespace SabreTools.Data.Extensions
|
||||
public static DictionaryBase? DeepClone(this DictionaryBase self)
|
||||
{
|
||||
// Handle types that are cloneable
|
||||
if (self is Analog analog)
|
||||
if (self is Adjuster adjuster)
|
||||
return adjuster.Clone() as Adjuster;
|
||||
else if (self is Analog analog)
|
||||
return analog.Clone() as Analog;
|
||||
else if (self is BiosSet biosSet)
|
||||
return biosSet.Clone() as BiosSet;
|
||||
@@ -155,12 +157,16 @@ namespace SabreTools.Data.Extensions
|
||||
return condition.Clone() as Condition;
|
||||
else if (self is ConfLocation confLocation)
|
||||
return confLocation.Clone() as ConfLocation;
|
||||
else if (self is ConfSetting confSetting)
|
||||
return confSetting.Clone() as ConfSetting;
|
||||
else if (self is Control control)
|
||||
return control.Clone() as Control;
|
||||
else if (self is DeviceRef deviceRef)
|
||||
return deviceRef.Clone() as DeviceRef;
|
||||
else if (self is DipLocation dipLocation)
|
||||
return dipLocation.Clone() as DipLocation;
|
||||
else if (self is DipValue dipValue)
|
||||
return dipValue.Clone() as DipValue;
|
||||
else if (self is Display display)
|
||||
return display.Clone() as Display;
|
||||
else if (self is Driver driver)
|
||||
@@ -202,24 +208,16 @@ namespace SabreTools.Data.Extensions
|
||||
return null;
|
||||
|
||||
// Handle individual type properties
|
||||
if (self is Adjuster selfAdjuster && clone is Adjuster cloneAdjuster)
|
||||
{
|
||||
cloneAdjuster.Default = selfAdjuster.Default;
|
||||
}
|
||||
else if (self is Archive selfArchive && clone is Archive cloneArchive)
|
||||
if (self is Archive selfArchive && clone is Archive cloneArchive)
|
||||
{
|
||||
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 ConfSetting selfConfSetting && clone is ConfSetting cloneConfSetting)
|
||||
{
|
||||
cloneConfSetting.Default = selfConfSetting.Default;
|
||||
cloneConfSetting.Value = selfConfSetting.Value;
|
||||
}
|
||||
else if (self is DataArea selfDataArea && clone is DataArea cloneDataArea)
|
||||
{
|
||||
cloneDataArea.Endianness = selfDataArea.Endianness;
|
||||
@@ -236,15 +234,11 @@ namespace SabreTools.Data.Extensions
|
||||
}
|
||||
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 DipValue selfDipValue && clone is DipValue cloneDipValue)
|
||||
{
|
||||
cloneDipValue.Default = selfDipValue.Default;
|
||||
cloneDipValue.Value = selfDipValue.Value;
|
||||
}
|
||||
else if (self is Disk selfDisk && clone is Disk cloneDisk)
|
||||
{
|
||||
cloneDisk.Optional = selfDisk.Optional;
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
[JsonObject("adjuster"), XmlRoot("adjuster")]
|
||||
public class Adjuster : DatItem
|
||||
public class Adjuster : DatItem, ICloneable, IEquatable<Adjuster>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
/// <remarks>(yes|no) "no"</remarks>
|
||||
public bool? Default { get; set; }
|
||||
|
||||
@@ -15,14 +18,43 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keys
|
||||
|
||||
// <remarks>Condition</remarks>
|
||||
[NoFilter]
|
||||
public const string ConditionKey = "condition";
|
||||
|
||||
#endregion
|
||||
|
||||
public Adjuster() => ItemType = ItemType.Adjuster;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Clone()
|
||||
{
|
||||
var obj = new Adjuster();
|
||||
|
||||
obj.Condition = Condition?.Clone() as Condition;
|
||||
obj.Default = Default;
|
||||
obj.Name = Name;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(Adjuster? other)
|
||||
{
|
||||
// Null never matches
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
// Properties
|
||||
if (Default != other.Default)
|
||||
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;
|
||||
|
||||
// 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;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
[JsonObject("confsetting"), XmlRoot("confsetting")]
|
||||
public class ConfSetting : DatItem
|
||||
public class ConfSetting : DatItem, ICloneable, IEquatable<ConfSetting>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
/// <remarks>(yes|no) "no"</remarks>
|
||||
public bool? Default { get; set; }
|
||||
|
||||
@@ -17,14 +20,49 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>Condition</remarks>
|
||||
[NoFilter]
|
||||
public const string ConditionKey = "condition";
|
||||
|
||||
#endregion
|
||||
|
||||
public ConfSetting() => ItemType = ItemType.ConfSetting;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Clone()
|
||||
{
|
||||
var obj = new ConfSetting();
|
||||
|
||||
obj.Condition = Condition?.Clone() as Condition;
|
||||
obj.Default = Default;
|
||||
obj.Name = Name;
|
||||
obj.Value = Value;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(ConfSetting? other)
|
||||
{
|
||||
// Null never matches
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
// Properties
|
||||
if (Default != other.Default)
|
||||
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 ((Value is null) ^ (other.Value is null))
|
||||
return false;
|
||||
else if (Value is not null && !Value.Equals(other.Value, 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;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
public string? Mask { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
@@ -18,10 +20,6 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>Condition</remarks>
|
||||
[NoFilter]
|
||||
public const string ConditionKey = "condition";
|
||||
|
||||
/// <remarks>ConfLocation[]</remarks>
|
||||
[NoFilter]
|
||||
public const string ConfLocationKey = "conflocation";
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
/// <remarks>(yes|no) "no"</remarks>
|
||||
public bool? Default { get; set; }
|
||||
|
||||
@@ -21,10 +23,6 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>Condition</remarks>
|
||||
[NoFilter]
|
||||
public const string ConditionKey = "condition";
|
||||
|
||||
/// <remarks>DipLocation[]</remarks>
|
||||
[NoFilter]
|
||||
public const string DipLocationKey = "diplocation";
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
[JsonObject("dipvalue"), XmlRoot("dipvalue")]
|
||||
public class DipValue : DatItem
|
||||
public class DipValue : DatItem, ICloneable, IEquatable<DipValue>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
/// <remarks>(yes|no) "no"</remarks>
|
||||
public bool? Default { get; set; }
|
||||
|
||||
@@ -17,14 +20,49 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>Condition</remarks>
|
||||
[NoFilter]
|
||||
public const string ConditionKey = "condition";
|
||||
|
||||
#endregion
|
||||
|
||||
public DipValue() => ItemType = ItemType.DipValue;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Clone()
|
||||
{
|
||||
var obj = new DipValue();
|
||||
|
||||
obj.Condition = Condition?.Clone() as Condition;
|
||||
obj.Default = Default;
|
||||
obj.Name = Name;
|
||||
obj.Value = Value;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(DipValue? other)
|
||||
{
|
||||
// Null never matches
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
// Properties
|
||||
if (Default != other.Default)
|
||||
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 ((Value is null) ^ (other.Value is null))
|
||||
return false;
|
||||
else if (Value is not null && !Value.Equals(other.Value, 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;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
return new Data.Models.Metadata.Adjuster
|
||||
{
|
||||
[Data.Models.Metadata.Adjuster.ConditionKey] = CreateMetadataCondition(),
|
||||
Condition = CreateMetadataCondition(),
|
||||
Default = true,
|
||||
Name = "name",
|
||||
};
|
||||
@@ -417,7 +417,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
return new Data.Models.Metadata.Configuration
|
||||
{
|
||||
[Data.Models.Metadata.Configuration.ConditionKey] = CreateMetadataCondition(),
|
||||
Condition = CreateMetadataCondition(),
|
||||
[Data.Models.Metadata.Configuration.ConfLocationKey] = new Data.Models.Metadata.ConfLocation[] { CreateMetadataConfLocation() },
|
||||
[Data.Models.Metadata.Configuration.ConfSettingKey] = new Data.Models.Metadata.ConfSetting[] { CreateMetadataConfSetting() },
|
||||
Mask = "mask",
|
||||
@@ -451,7 +451,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
return new Data.Models.Metadata.ConfSetting
|
||||
{
|
||||
[Data.Models.Metadata.ConfSetting.ConditionKey] = CreateMetadataCondition(),
|
||||
Condition = CreateMetadataCondition(),
|
||||
Default = true,
|
||||
Name = "name",
|
||||
Value = "value",
|
||||
@@ -513,7 +513,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
return new Data.Models.Metadata.DipSwitch
|
||||
{
|
||||
[Data.Models.Metadata.DipSwitch.ConditionKey] = CreateMetadataCondition(),
|
||||
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() },
|
||||
@@ -528,7 +528,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
return new Data.Models.Metadata.DipValue
|
||||
{
|
||||
[Data.Models.Metadata.DipValue.ConditionKey] = CreateMetadataCondition(),
|
||||
Condition = CreateMetadataCondition(),
|
||||
Default = true,
|
||||
Name = "name",
|
||||
Value = "value",
|
||||
@@ -1130,8 +1130,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.True(adjuster.Default);
|
||||
Assert.Equal("name", adjuster.Name);
|
||||
|
||||
Condition? condition = adjuster.Read<Condition>(Data.Models.Metadata.Adjuster.ConditionKey);
|
||||
ValidateCondition(condition);
|
||||
ValidateCondition(adjuster.Condition);
|
||||
}
|
||||
|
||||
private static void ValidateAnalog(Analog? analog)
|
||||
@@ -1181,8 +1180,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", configuration.Name);
|
||||
Assert.Equal("tag", configuration.Tag);
|
||||
|
||||
Condition? condition = configuration.Read<Condition>(Data.Models.Metadata.Configuration.ConditionKey);
|
||||
ValidateCondition(condition);
|
||||
ValidateCondition(configuration.Condition);
|
||||
|
||||
ConfLocation[]? confLocations = configuration.Read<ConfLocation[]>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
Assert.NotNull(confLocations);
|
||||
@@ -1210,8 +1208,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", confSetting.Name);
|
||||
Assert.Equal("value", confSetting.Value);
|
||||
|
||||
Condition? condition = confSetting.Read<Condition>(Data.Models.Metadata.ConfSetting.ConditionKey);
|
||||
ValidateCondition(condition);
|
||||
ValidateCondition(confSetting.Condition);
|
||||
}
|
||||
|
||||
private static void ValidateControl(Control? control)
|
||||
@@ -1280,8 +1277,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", dipSwitch.Name);
|
||||
Assert.Equal("tag", dipSwitch.Tag);
|
||||
|
||||
Condition? condition = dipSwitch.Read<Condition>(Data.Models.Metadata.DipSwitch.ConditionKey);
|
||||
ValidateCondition(condition);
|
||||
ValidateCondition(dipSwitch.Condition);
|
||||
|
||||
DipLocation[]? dipLocations = dipSwitch.Read<DipLocation[]>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
Assert.NotNull(dipLocations);
|
||||
@@ -1306,8 +1302,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", dipValue.Name);
|
||||
Assert.Equal("value", dipValue.Value);
|
||||
|
||||
Condition? condition = dipValue.Read<Condition>(Data.Models.Metadata.DipValue.ConditionKey);
|
||||
ValidateCondition(condition);
|
||||
ValidateCondition(dipValue.Condition);
|
||||
}
|
||||
|
||||
private static void ValidateDisk(Disk? disk)
|
||||
|
||||
@@ -622,7 +622,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.True(adjuster.Default);
|
||||
Assert.Equal("name", adjuster.Name);
|
||||
|
||||
Data.Models.Metadata.Condition? condition = adjuster.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.Adjuster.ConditionKey);
|
||||
Data.Models.Metadata.Condition? condition = adjuster.Condition;
|
||||
ValidateMetadataCondition(condition);
|
||||
}
|
||||
|
||||
@@ -705,8 +705,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", configuration.Name);
|
||||
Assert.Equal("tag", configuration.Tag);
|
||||
|
||||
Data.Models.Metadata.Condition? condition = configuration.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.Configuration.ConditionKey);
|
||||
ValidateMetadataCondition(condition);
|
||||
ValidateMetadataCondition(configuration.Condition);
|
||||
|
||||
Data.Models.Metadata.ConfLocation[]? confLocations = configuration.ReadArray<Data.Models.Metadata.ConfLocation>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
Assert.NotNull(confLocations);
|
||||
@@ -734,8 +733,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", confSetting.Name);
|
||||
Assert.Equal("value", confSetting.Value);
|
||||
|
||||
Data.Models.Metadata.Condition? condition = confSetting.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.ConfSetting.ConditionKey);
|
||||
ValidateMetadataCondition(condition);
|
||||
ValidateMetadataCondition(confSetting.Condition);
|
||||
}
|
||||
|
||||
private static void ValidateMetadataControl(Data.Models.Metadata.Control? control)
|
||||
@@ -809,8 +807,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", dipSwitch.Name);
|
||||
Assert.Equal("tag", dipSwitch.Tag);
|
||||
|
||||
Data.Models.Metadata.Condition? condition = dipSwitch.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipSwitch.ConditionKey);
|
||||
ValidateMetadataCondition(condition);
|
||||
ValidateMetadataCondition(dipSwitch.Condition);
|
||||
|
||||
Data.Models.Metadata.DipLocation[]? dipLocations = dipSwitch.ReadArray<Data.Models.Metadata.DipLocation>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
Assert.NotNull(dipLocations);
|
||||
@@ -835,8 +832,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", dipValue.Name);
|
||||
Assert.Equal("value", dipValue.Value);
|
||||
|
||||
Data.Models.Metadata.Condition? condition = dipValue.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipValue.ConditionKey);
|
||||
ValidateMetadataCondition(condition);
|
||||
ValidateMetadataCondition(dipValue.Condition);
|
||||
}
|
||||
|
||||
private static void ValidateMetadataDisk(Data.Models.Metadata.Disk? disk)
|
||||
|
||||
@@ -12,15 +12,10 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
#region Fields
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var conditions = Read<Condition[]?>(Data.Models.Metadata.Adjuster.ConditionKey);
|
||||
return conditions is not null && conditions.Length > 0;
|
||||
}
|
||||
}
|
||||
public bool ConditionSpecified => Condition is not null;
|
||||
|
||||
public bool? Default
|
||||
{
|
||||
@@ -47,9 +42,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
public Adjuster(Data.Models.Metadata.Adjuster item) : base(item)
|
||||
{
|
||||
// Handle subitems
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.Adjuster.ConditionKey);
|
||||
if (condition is not null)
|
||||
Write(Data.Models.Metadata.Adjuster.ConditionKey, new Condition(condition));
|
||||
if (item.Condition is not null)
|
||||
Condition = new Condition(item.Condition);
|
||||
}
|
||||
|
||||
public Adjuster(Data.Models.Metadata.Adjuster item, Machine machine, Source source) : this(item)
|
||||
@@ -70,9 +64,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
var adjusterItem = base.GetInternalClone();
|
||||
|
||||
var condition = Read<Condition?>(Data.Models.Metadata.Adjuster.ConditionKey);
|
||||
if (condition is not null)
|
||||
adjusterItem[Data.Models.Metadata.Adjuster.ConditionKey] = condition.GetInternalClone();
|
||||
if (Condition is not null)
|
||||
adjusterItem.Condition = Condition.GetInternalClone();
|
||||
|
||||
return adjusterItem;
|
||||
}
|
||||
|
||||
@@ -12,15 +12,10 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
#region Fields
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var conditions = Read<Condition[]?>(Data.Models.Metadata.ConfSetting.ConditionKey);
|
||||
return conditions is not null && conditions.Length > 0;
|
||||
}
|
||||
}
|
||||
public bool ConditionSpecified => Condition is not null;
|
||||
|
||||
public bool? Default
|
||||
{
|
||||
@@ -53,9 +48,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
public ConfSetting(Data.Models.Metadata.ConfSetting item) : base(item)
|
||||
{
|
||||
// Handle subitems
|
||||
var condition = Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.ConfSetting.ConditionKey);
|
||||
if (condition is not null)
|
||||
Write<Condition?>(Data.Models.Metadata.ConfSetting.ConditionKey, new Condition(condition));
|
||||
if (item.Condition is not null)
|
||||
Condition = new Condition(item.Condition);
|
||||
}
|
||||
|
||||
public ConfSetting(Data.Models.Metadata.ConfSetting item, Machine machine, Source source) : this(item)
|
||||
@@ -76,10 +70,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
var confSettingItem = base.GetInternalClone();
|
||||
|
||||
// Handle subitems
|
||||
var condition = Read<Condition>(Data.Models.Metadata.ConfSetting.ConditionKey);
|
||||
if (condition is not null)
|
||||
confSettingItem[Data.Models.Metadata.ConfSetting.ConditionKey] = condition.GetInternalClone();
|
||||
if (Condition is not null)
|
||||
confSettingItem.Condition = Condition.GetInternalClone();
|
||||
|
||||
return confSettingItem;
|
||||
}
|
||||
|
||||
@@ -13,15 +13,10 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
#region Fields
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var conditions = Read<Condition[]?>(Data.Models.Metadata.Configuration.ConditionKey);
|
||||
return conditions is not null && conditions.Length > 0;
|
||||
}
|
||||
}
|
||||
public bool ConditionSpecified => Condition is not null;
|
||||
|
||||
/// <inheritdoc>/>
|
||||
public override Data.Models.Metadata.ItemType ItemType
|
||||
@@ -74,9 +69,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
public Configuration(Data.Models.Metadata.Configuration item) : base(item)
|
||||
{
|
||||
// Handle subitems
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.Configuration.ConditionKey);
|
||||
if (condition is not null)
|
||||
Write<Condition?>(Data.Models.Metadata.Configuration.ConditionKey, new Condition(condition));
|
||||
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)
|
||||
@@ -111,9 +105,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
var configurationItem = base.GetInternalClone();
|
||||
|
||||
var condition = Read<Condition?>(Data.Models.Metadata.Configuration.ConditionKey);
|
||||
if (condition is not null)
|
||||
configurationItem[Data.Models.Metadata.Configuration.ConditionKey] = condition.GetInternalClone();
|
||||
if (Condition is not null)
|
||||
configurationItem.Condition = Condition.GetInternalClone();
|
||||
|
||||
var confLocations = Read<ConfLocation[]?>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
if (confLocations is not null)
|
||||
|
||||
@@ -22,15 +22,10 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
|
||||
#region Fields
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var conditions = Read<Condition[]?>(Data.Models.Metadata.DipSwitch.ConditionKey);
|
||||
return conditions is not null && conditions.Length > 0;
|
||||
}
|
||||
}
|
||||
public bool ConditionSpecified => Condition is not null;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool? Default
|
||||
@@ -102,9 +97,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
public DipSwitch(Data.Models.Metadata.DipSwitch item) : base(item)
|
||||
{
|
||||
// Handle subitems
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipSwitch.ConditionKey);
|
||||
if (condition is not null)
|
||||
Write<Condition?>(Data.Models.Metadata.DipSwitch.ConditionKey, new Condition(condition));
|
||||
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)
|
||||
@@ -139,9 +133,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
var dipSwitchItem = base.GetInternalClone();
|
||||
|
||||
var condition = Read<Condition?>(Data.Models.Metadata.DipSwitch.ConditionKey);
|
||||
if (condition is not null)
|
||||
dipSwitchItem[Data.Models.Metadata.DipSwitch.ConditionKey] = condition.GetInternalClone();
|
||||
if (Condition is not null)
|
||||
dipSwitchItem.Condition = Condition.GetInternalClone();
|
||||
|
||||
var dipLocations = Read<DipLocation[]?>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
if (dipLocations is not null)
|
||||
|
||||
@@ -12,15 +12,10 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
#region Fields
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var conditions = Read<Condition[]?>(Data.Models.Metadata.DipValue.ConditionKey);
|
||||
return conditions is not null && conditions.Length > 0;
|
||||
}
|
||||
}
|
||||
public bool ConditionSpecified => Condition is not null;
|
||||
|
||||
public bool? Default
|
||||
{
|
||||
@@ -53,9 +48,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
public DipValue(Data.Models.Metadata.DipValue item) : base(item)
|
||||
{
|
||||
// Handle subitems
|
||||
var condition = Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipValue.ConditionKey);
|
||||
if (condition is not null)
|
||||
Write<Condition?>(Data.Models.Metadata.DipValue.ConditionKey, new Condition(condition));
|
||||
if (item.Condition is not null)
|
||||
Condition = new Condition(item.Condition);
|
||||
}
|
||||
|
||||
public DipValue(Data.Models.Metadata.DipValue item, Machine machine, Source source) : this(item)
|
||||
@@ -76,10 +70,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
var dipValueItem = base.GetInternalClone();
|
||||
|
||||
// Handle subitems
|
||||
var subCondition = Read<Condition>(Data.Models.Metadata.DipValue.ConditionKey);
|
||||
if (subCondition is not null)
|
||||
dipValueItem[Data.Models.Metadata.DipValue.ConditionKey] = subCondition.GetInternalClone();
|
||||
if (Condition is not null)
|
||||
dipValueItem.Condition = Condition.GetInternalClone();
|
||||
|
||||
return dipValueItem;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace SabreTools.Metadata
|
||||
// Handle individual type properties
|
||||
if (self is Adjuster selfAdjuster && other is Adjuster otherAdjuster)
|
||||
{
|
||||
if (selfAdjuster.Default != otherAdjuster.Default)
|
||||
if (!selfAdjuster.Equals(otherAdjuster))
|
||||
return false;
|
||||
}
|
||||
else if (self is Analog selfAnalog && other is Analog otherAnalog)
|
||||
@@ -98,6 +98,17 @@ namespace SabreTools.Metadata
|
||||
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)
|
||||
{
|
||||
@@ -106,9 +117,7 @@ namespace SabreTools.Metadata
|
||||
}
|
||||
else if (self is ConfSetting selfConfSetting && other is ConfSetting otherConfSetting)
|
||||
{
|
||||
if (selfConfSetting.Default != otherConfSetting.Default)
|
||||
return false;
|
||||
if (selfConfSetting.Value != otherConfSetting.Value)
|
||||
if (!selfConfSetting.Equals(otherConfSetting))
|
||||
return false;
|
||||
}
|
||||
else if (self is Control selfControl && other is Control otherControl)
|
||||
@@ -151,12 +160,21 @@ namespace SabreTools.Metadata
|
||||
return false;
|
||||
if (selfDipSwitch.Tag != otherDipSwitch.Tag)
|
||||
return false;
|
||||
|
||||
if ((selfDipSwitch.Condition is null) ^ (otherDipSwitch.Condition is null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (selfDipSwitch.Condition is not null
|
||||
&& otherDipSwitch.Condition is not null
|
||||
&& selfDipSwitch.Condition.EqualTo(otherDipSwitch.Condition))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (self is DipValue selfDipValue && other is DipValue otherDipValue)
|
||||
{
|
||||
if (selfDipValue.Default != otherDipValue.Default)
|
||||
return false;
|
||||
if (selfDipValue.Value != otherDipValue.Value)
|
||||
if (!selfDipValue.Equals(otherDipValue))
|
||||
return false;
|
||||
}
|
||||
else if (self is Disk selfDisk && other is Disk otherDisk)
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
Default = item.Default,
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.Adjuster.ConditionKey);
|
||||
var condition = item.Condition;
|
||||
if (condition is not null)
|
||||
adjuster.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
Mask = item.Mask,
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.Configuration.ConditionKey);
|
||||
var condition = item.Condition;
|
||||
if (condition is not null)
|
||||
configuration.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
@@ -269,7 +269,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
Default = item.Default,
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.ConfSetting.ConditionKey);
|
||||
var condition = item.Condition;
|
||||
if (condition is not null)
|
||||
confSetting.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
@@ -362,7 +362,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
Mask = item.Mask,
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipSwitch.ConditionKey);
|
||||
var condition = item.Condition;
|
||||
if (condition is not null)
|
||||
dipSwitch.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
@@ -389,7 +389,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
Default = item.Default,
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipValue.ConditionKey);
|
||||
var condition = item.Condition;
|
||||
if (condition is not null)
|
||||
dipValue.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
if (item.Condition is not null)
|
||||
adjuster[Data.Models.Metadata.Adjuster.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
adjuster.Condition = ConvertToInternalModel(item.Condition);
|
||||
|
||||
return adjuster;
|
||||
}
|
||||
@@ -262,7 +262,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
if (item.Condition is not null)
|
||||
configuration[Data.Models.Metadata.Configuration.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
configuration.Condition = ConvertToInternalModel(item.Condition);
|
||||
|
||||
if (item.ConfLocation is not null && item.ConfLocation.Length > 0)
|
||||
{
|
||||
@@ -306,7 +306,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
if (item.Condition is not null)
|
||||
confSetting[Data.Models.Metadata.ConfSetting.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
confSetting.Condition = ConvertToInternalModel(item.Condition);
|
||||
|
||||
return confSetting;
|
||||
}
|
||||
@@ -399,7 +399,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
if (item.Condition is not null)
|
||||
dipSwitch[Data.Models.Metadata.DipSwitch.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
dipSwitch.Condition = ConvertToInternalModel(item.Condition);
|
||||
|
||||
if (item.DipLocation is not null && item.DipLocation.Length > 0)
|
||||
{
|
||||
@@ -429,7 +429,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
if (item.Condition is not null)
|
||||
dipValue[Data.Models.Metadata.DipValue.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
dipValue.Condition = ConvertToInternalModel(item.Condition);
|
||||
|
||||
return dipValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user