Add nullable context to SabreTools.DatItems

This change also starts migrating the internals of the DatItem formats to the new internal models. Right now, it's basically just acting like a wrapper around those models.
This commit is contained in:
Matt Nadareski
2023-08-14 13:17:51 -04:00
parent 1752b1a0ac
commit b37aed389e
87 changed files with 3266 additions and 2199 deletions

View File

@@ -1,8 +1,8 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SabreTools.Core;
using SabreTools.Core.Tools;
namespace SabreTools.DatItems.Formats
{
@@ -22,14 +22,22 @@ namespace SabreTools.DatItems.Formats
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string Tag { get; set; }
public string? Tag
{
get => _softwareList.ReadString(Models.Internal.SoftwareList.TagKey);
set => _softwareList[Models.Internal.SoftwareList.TagKey] = value;
}
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
public string? Name
{
get => _softwareList.ReadString(Models.Internal.SoftwareList.NameKey);
set => _softwareList[Models.Internal.SoftwareList.NameKey] = value;
}
/// <summary>
/// Status of the softare list according to the machine
@@ -37,7 +45,11 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("status")]
public SoftwareListStatus Status { get; set; }
public SoftwareListStatus Status
{
get => _softwareList.ReadString(Models.Internal.SoftwareList.StatusKey).AsSoftwareListStatus();
set => _softwareList[Models.Internal.SoftwareList.StatusKey] = value.FromSoftwareListStatus();
}
[JsonIgnore]
public bool StatusSpecified { get { return Status != SoftwareListStatus.None; } }
@@ -47,17 +59,27 @@ namespace SabreTools.DatItems.Formats
/// </summary>
[JsonProperty("filter", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("filter")]
public string Filter { get; set; }
public string? Filter
{
get => _softwareList.ReadString(Models.Internal.SoftwareList.FilterKey);
set => _softwareList[Models.Internal.SoftwareList.FilterKey] = value;
}
/// <summary>
/// Internal SoftwareList model
/// </summary>
[JsonIgnore]
private Models.Internal.SoftwareList _softwareList = new();
#endregion
#region Accessors
/// <inheritdoc/>
public override string GetName() => Name;
public override string? GetName() => Name;
/// <inheritdoc/>
public override void SetName(string name) => Name = name;
public override void SetName(string? name) => Name = name;
#endregion
@@ -83,14 +105,11 @@ namespace SabreTools.DatItems.Formats
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Machine = this.Machine?.Clone() as Machine,
Source = this.Source?.Clone() as Source,
Remove = this.Remove,
Tag = this.Tag,
Name = this.Name,
Status = this.Status,
Filter = this.Filter,
_softwareList = this._softwareList?.Clone() as Models.Internal.SoftwareList ?? new Models.Internal.SoftwareList(),
};
}
@@ -98,20 +117,14 @@ namespace SabreTools.DatItems.Formats
#region Comparision Methods
public override bool Equals(DatItem other)
public override bool Equals(DatItem? other)
{
// If we don't have a sample, return false
if (ItemType != other.ItemType)
// If we don't have a Adjuster, return false
if (ItemType != other?.ItemType || other is not SoftwareList otherInternal)
return false;
// Otherwise, treat it as a SoftwareList
SoftwareList newOther = other as SoftwareList;
// If the SoftwareList information matches
return (Tag == newOther.Tag
&& Name == newOther.Name
&& Status == newOther.Status
&& Filter == newOther.Filter);
// Compare the internal models
return _softwareList.EqualTo(otherInternal._softwareList);
}
#endregion