Files
SabreTools.Serialization/SabreTools.Metadata.DatItems/Formats/Blank.cs
2026-03-24 18:03:01 -04:00

96 lines
2.6 KiB
C#

using System.Xml.Serialization;
using Newtonsoft.Json;
namespace SabreTools.Metadata.DatItems.Formats
{
/// <summary>
/// Represents a blank set from an input DAT
/// </summary>
[JsonObject("blank"), XmlRoot("blank")]
public sealed class Blank : DatItem
{
#region Fields
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Blank;
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Blank object
/// </summary>
public Blank()
{
SetFieldValue(Data.Models.Metadata.DatItem.TypeKey, ItemType);
}
#endregion
#region Cloning Methods
/// <inheritdoc/>
public override object Clone()
{
var blank = new Blank();
blank.SetFieldValue(MachineKey, GetMachine());
blank.SetFieldValue(RemoveKey, GetBoolFieldValue(RemoveKey));
blank.SetFieldValue<Source?>(SourceKey, GetFieldValue<Source?>(SourceKey));
blank.SetFieldValue<string?>(Data.Models.Metadata.DatItem.TypeKey, GetStringFieldValue(Data.Models.Metadata.DatItem.TypeKey).AsItemType().AsStringValue());
return blank;
}
#endregion
#region Comparision Methods
/// <inheritdoc/>
public override bool Equals(ModelBackedItem? other)
{
// If other is null
if (other is null)
return false;
// If the type is mismatched
if (other is not DatItem otherItem)
return false;
// Compare internal models
return Equals(otherItem);
}
/// <inheritdoc/>
public override bool Equals(ModelBackedItem<Data.Models.Metadata.DatItem>? other)
{
// If other is null
if (other is null)
return false;
// If the type is mismatched
if (other is not DatItem otherItem)
return false;
// Compare internal models
return Equals(otherItem);
}
/// <inheritdoc/>
public override bool Equals(DatItem? other)
{
// If we don't have a blank, return false
if (GetStringFieldValue(Data.Models.Metadata.DatItem.TypeKey) != other?.GetStringFieldValue(Data.Models.Metadata.DatItem.TypeKey))
return false;
// Otherwise, treat it as a Blank
Blank? newOther = other as Blank;
// If the machine information matches
return GetMachine() == newOther!.GetMachine();
}
#endregion
}
}