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

@@ -2,6 +2,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SabreTools.Core;
using SabreTools.Core.Tools;
namespace SabreTools.DatItems.Formats
{
@@ -21,7 +22,11 @@ namespace SabreTools.DatItems.Formats
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("status")]
[JsonConverter(typeof(StringEnumConverter))]
public SupportStatus Status { get; set; }
public SupportStatus Status
{
get => _driver.ReadString(Models.Internal.Driver.StatusKey).AsSupportStatus();
set => _driver[Models.Internal.Driver.StatusKey] = value.FromSupportStatus();
}
[JsonIgnore]
public bool StatusSpecified { get { return Status != SupportStatus.NULL; } }
@@ -31,7 +36,11 @@ namespace SabreTools.DatItems.Formats
/// </summary>
[JsonProperty("emulation", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("emulation")]
[JsonConverter(typeof(StringEnumConverter))]
public SupportStatus Emulation { get; set; }
public SupportStatus Emulation
{
get => _driver.ReadString(Models.Internal.Driver.EmulationKey).AsSupportStatus();
set => _driver[Models.Internal.Driver.EmulationKey] = value.FromSupportStatus();
}
[JsonIgnore]
public bool EmulationSpecified { get { return Emulation != SupportStatus.NULL; } }
@@ -41,7 +50,11 @@ namespace SabreTools.DatItems.Formats
/// </summary>
[JsonProperty("cocktail", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("cocktail")]
[JsonConverter(typeof(StringEnumConverter))]
public SupportStatus Cocktail { get; set; }
public SupportStatus Cocktail
{
get => _driver.ReadString(Models.Internal.Driver.CocktailKey).AsSupportStatus();
set => _driver[Models.Internal.Driver.CocktailKey] = value.FromSupportStatus();
}
[JsonIgnore]
public bool CocktailSpecified { get { return Cocktail != SupportStatus.NULL; } }
@@ -51,7 +64,11 @@ namespace SabreTools.DatItems.Formats
/// </summary>
[JsonProperty("savestate", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("savestate")]
[JsonConverter(typeof(StringEnumConverter))]
public Supported SaveState { get; set; }
public Supported SaveState
{
get => _driver.ReadString(Models.Internal.Driver.SaveStateKey).AsSupported();
set => _driver[Models.Internal.Driver.SaveStateKey] = value.FromSupported(verbose: true);
}
[JsonIgnore]
public bool SaveStateSpecified { get { return SaveState != Supported.NULL; } }
@@ -60,7 +77,11 @@ namespace SabreTools.DatItems.Formats
/// Requires artwork
/// </summary>
[JsonProperty("requiresartwork", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("requiresartwork")]
public bool? RequiresArtwork { get; set; }
public bool? RequiresArtwork
{
get => _driver.ReadBool(Models.Internal.Driver.RequiresArtworkKey);
set => _driver[Models.Internal.Driver.RequiresArtworkKey] = value;
}
[JsonIgnore]
public bool RequiresArtworkSpecified { get { return RequiresArtwork != null; } }
@@ -69,7 +90,11 @@ namespace SabreTools.DatItems.Formats
/// Unofficial
/// </summary>
[JsonProperty("unofficial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("unofficial")]
public bool? Unofficial { get; set; }
public bool? Unofficial
{
get => _driver.ReadBool(Models.Internal.Driver.UnofficialKey);
set => _driver[Models.Internal.Driver.UnofficialKey] = value;
}
[JsonIgnore]
public bool UnofficialSpecified { get { return Unofficial != null; } }
@@ -78,7 +103,11 @@ namespace SabreTools.DatItems.Formats
/// No sound hardware
/// </summary>
[JsonProperty("nosoundhardware", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("nosoundhardware")]
public bool? NoSoundHardware { get; set; }
public bool? NoSoundHardware
{
get => _driver.ReadBool(Models.Internal.Driver.NoSoundHardwareKey);
set => _driver[Models.Internal.Driver.NoSoundHardwareKey] = value;
}
[JsonIgnore]
public bool NoSoundHardwareSpecified { get { return NoSoundHardware != null; } }
@@ -87,11 +116,21 @@ namespace SabreTools.DatItems.Formats
/// Incomplete
/// </summary>
[JsonProperty("incomplete", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("incomplete")]
public bool? Incomplete { get; set; }
public bool? Incomplete
{
get => _driver.ReadBool(Models.Internal.Driver.IncompleteKey);
set => _driver[Models.Internal.Driver.IncompleteKey] = value;
}
[JsonIgnore]
public bool IncompleteSpecified { get { return Incomplete != null; } }
/// <summary>
/// Internal Driver model
/// </summary>
[JsonIgnore]
private Models.Internal.Driver _driver = new();
#endregion
#region Constructors
@@ -116,18 +155,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,
Status = this.Status,
Emulation = this.Emulation,
Cocktail = this.Cocktail,
SaveState = this.SaveState,
RequiresArtwork = this.RequiresArtwork,
Unofficial = this.Unofficial,
NoSoundHardware = this.NoSoundHardware,
Incomplete = this.Incomplete,
_driver = this._driver?.Clone() as Models.Internal.Driver ?? new Models.Internal.Driver(),
};
}
@@ -136,24 +168,14 @@ namespace SabreTools.DatItems.Formats
#region Comparision Methods
/// <inheritdoc/>
public override bool Equals(DatItem other)
public override bool Equals(DatItem? other)
{
// If we don't have a Driver, return false
if (ItemType != other.ItemType)
if (ItemType != other?.ItemType || other is not Driver otherInternal)
return false;
// Otherwise, treat it as a Driver
Driver newOther = other as Driver;
// If the Feature information matches
return (Status == newOther.Status
&& Emulation == newOther.Emulation
&& Cocktail == newOther.Cocktail
&& SaveState == newOther.SaveState
&& RequiresArtwork == newOther.RequiresArtwork
&& Unofficial == newOther.Unofficial
&& NoSoundHardware == newOther.NoSoundHardware
&& Incomplete == newOther.Incomplete);
// Compare the internal models
return _driver.EqualTo(otherInternal._driver);
}
#endregion