Move more to the DatItem base class

This commit is contained in:
Matt Nadareski
2023-08-14 22:33:05 -04:00
parent 6adbe601a2
commit ed1f809065
41 changed files with 708 additions and 1310 deletions

View File

@@ -22,8 +22,8 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("name"), XmlElement("name")]
public string? Name
{
get => _dipSwitch.ReadString(Models.Internal.DipSwitch.NameKey);
set => _dipSwitch[Models.Internal.DipSwitch.NameKey] = value;
get => _internal.ReadString(Models.Internal.DipSwitch.NameKey);
set => _internal[Models.Internal.DipSwitch.NameKey] = value;
}
/// <summary>
@@ -32,8 +32,8 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
public string? Tag
{
get => _dipSwitch.ReadString(Models.Internal.DipSwitch.TagKey);
set => _dipSwitch[Models.Internal.DipSwitch.TagKey] = value;
get => _internal.ReadString(Models.Internal.DipSwitch.TagKey);
set => _internal[Models.Internal.DipSwitch.TagKey] = value;
}
/// <summary>
@@ -42,8 +42,8 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")]
public string? Mask
{
get => _dipSwitch.ReadString(Models.Internal.DipSwitch.MaskKey);
set => _dipSwitch[Models.Internal.DipSwitch.MaskKey] = value;
get => _internal.ReadString(Models.Internal.DipSwitch.MaskKey);
set => _internal[Models.Internal.DipSwitch.MaskKey] = value;
}
/// <summary>
@@ -52,8 +52,8 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
public List<Condition>? Conditions
{
get => _dipSwitch.Read<Condition[]>(Models.Internal.DipSwitch.ConditionKey)?.ToList();
set => _dipSwitch[Models.Internal.DipSwitch.ConditionKey] = value?.ToArray();
get => _internal.Read<Condition[]>(Models.Internal.DipSwitch.ConditionKey)?.ToList();
set => _internal[Models.Internal.DipSwitch.ConditionKey] = value?.ToArray();
}
[JsonIgnore]
@@ -65,8 +65,8 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("locations")]
public List<DipLocation>? Locations
{
get => _dipSwitch.Read<DipLocation[]>(Models.Internal.DipSwitch.DipLocationKey)?.ToList();
set => _dipSwitch[Models.Internal.DipSwitch.DipLocationKey] = value?.ToArray();
get => _internal.Read<DipLocation[]>(Models.Internal.DipSwitch.DipLocationKey)?.ToList();
set => _internal[Models.Internal.DipSwitch.DipLocationKey] = value?.ToArray();
}
[JsonIgnore]
@@ -78,8 +78,8 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("values", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("values")]
public List<DipValue>? Values
{
get => _dipSwitch.Read<DipValue[]>(Models.Internal.DipSwitch.DipValueKey)?.ToList();
set => _dipSwitch[Models.Internal.DipSwitch.DipValueKey] = value?.ToArray();
get => _internal.Read<DipValue[]>(Models.Internal.DipSwitch.DipValueKey)?.ToList();
set => _internal[Models.Internal.DipSwitch.DipValueKey] = value?.ToArray();
}
[JsonIgnore]
@@ -109,12 +109,6 @@ namespace SabreTools.DatItems.Formats
#endregion
/// <summary>
/// Internal DipSwitch model
/// </summary>
[JsonIgnore]
private Models.Internal.DipSwitch _dipSwitch = new();
#endregion // Fields
#region Accessors
@@ -134,6 +128,7 @@ namespace SabreTools.DatItems.Formats
/// </summary>
public DipSwitch()
{
_internal = new Models.Internal.DipSwitch();
Name = string.Empty;
ItemType = ItemType.DipSwitch;
}
@@ -154,27 +149,12 @@ namespace SabreTools.DatItems.Formats
Source = this.Source?.Clone() as Source,
Remove = this.Remove,
_dipSwitch = this._dipSwitch?.Clone() as Models.Internal.DipSwitch ?? new Models.Internal.DipSwitch(),
_internal = this._internal?.Clone() as Models.Internal.DipSwitch ?? new Models.Internal.DipSwitch(),
Part = this.Part,
};
}
#endregion
#region Comparision Methods
/// <inheritdoc/>
public override bool Equals(DatItem? other)
{
// If we don't have a DipSwitch, return false
if (ItemType != other?.ItemType || other is not DipSwitch otherInternal)
return false;
// Compare the internal models
return _dipSwitch.EqualTo(otherInternal._dipSwitch);
}
#endregion
}
}