mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
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:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
@@ -17,26 +18,40 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _slot.ReadString(Models.Internal.Slot.NameKey);
|
||||
set => _slot[Models.Internal.Slot.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Slot options associated with the slot
|
||||
/// </summary>
|
||||
[JsonProperty("slotoptions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("slotoptions")]
|
||||
public List<SlotOption> SlotOptions { get; set; }
|
||||
public List<SlotOption>? SlotOptions
|
||||
{
|
||||
get => _slot.Read<SlotOption[]>(Models.Internal.Slot.SlotOptionKey)?.ToList();
|
||||
set => _slot[Models.Internal.Slot.SlotOptionKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SlotOptionsSpecified { get { return SlotOptions != null && SlotOptions.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Slot model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Slot _slot = 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
|
||||
|
||||
@@ -63,12 +78,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,
|
||||
|
||||
Name = this.Name,
|
||||
SlotOptions = this.SlotOptions,
|
||||
_slot = this._slot?.Clone() as Models.Internal.Slot ?? new Models.Internal.Slot(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,30 +91,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 Slot, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Slot otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Slot
|
||||
Slot newOther = other as Slot;
|
||||
|
||||
// If the Slot information matches
|
||||
bool match = (Name == newOther.Name);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the slot options match
|
||||
if (SlotOptionsSpecified)
|
||||
{
|
||||
foreach (SlotOption slotOption in SlotOptions)
|
||||
{
|
||||
match &= newOther.SlotOptions.Contains(slotOption);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _slot.EqualTo(otherInternal._slot);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user