mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-27 16:49:56 +00:00
This is both big and not big. The not big part of this is that I essentially just moved some stuff up to the typed type that used to live in the untyped type. The big part is that this allows every single DatItem implementation to be significantly cleaner with their implementations of the methods and internal model.
132 lines
3.4 KiB
C#
132 lines
3.4 KiB
C#
using System;
|
|
using System.Xml.Serialization;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace SabreTools.Metadata.DatItems.Formats
|
|
{
|
|
/// <summary>
|
|
/// SoftwareList dataarea information
|
|
/// </summary>
|
|
/// <remarks>One DataArea can contain multiple Rom items</remarks>
|
|
[JsonObject("dataarea"), XmlRoot("dataarea")]
|
|
public sealed class DataArea : DatItem<Data.Models.Metadata.DataArea>
|
|
{
|
|
#region Properties
|
|
|
|
public Data.Models.Metadata.Endianness? Endianness
|
|
{
|
|
get => _internal.Endianness;
|
|
set => _internal.Endianness = value;
|
|
}
|
|
|
|
/// <inheritdoc>/>
|
|
public override Data.Models.Metadata.ItemType ItemType
|
|
=> Data.Models.Metadata.ItemType.DataArea;
|
|
|
|
public string? Name
|
|
{
|
|
get => _internal.Name;
|
|
set => _internal.Name = value;
|
|
}
|
|
|
|
public Rom[]? Rom { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool RomSpecified => Rom is not null && Rom.Length > 0;
|
|
|
|
public long? Size
|
|
{
|
|
get => _internal.Size;
|
|
set => _internal.Size = value;
|
|
}
|
|
|
|
public Data.Models.Metadata.Width? Width
|
|
{
|
|
get => _internal.Width;
|
|
set => _internal.Width = value;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public DataArea() : base() { }
|
|
|
|
public DataArea(Data.Models.Metadata.DataArea item) : base(item)
|
|
{
|
|
// Handle subitems
|
|
if (item.Rom is not null)
|
|
Rom = Array.ConvertAll(item.Rom, rom => new Rom(rom));
|
|
}
|
|
|
|
public DataArea(Data.Models.Metadata.DataArea item, Machine machine, Source source) : this(item)
|
|
{
|
|
Source = source;
|
|
CopyMachineInformation(machine);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Accessors
|
|
|
|
/// <inheritdoc/>
|
|
public override string? GetName() => Name;
|
|
|
|
/// <inheritdoc/>
|
|
public override void SetName(string? name) => Name = name;
|
|
|
|
#endregion
|
|
|
|
#region Cloning Methods
|
|
|
|
/// <inheritdoc/>
|
|
public override object Clone() => new DataArea(GetInternalClone());
|
|
|
|
public override Data.Models.Metadata.DataArea GetInternalClone()
|
|
{
|
|
var partItem = _internal.Clone() as Data.Models.Metadata.DataArea ?? new();
|
|
|
|
if (Rom is not null)
|
|
partItem.Rom = Array.ConvertAll(Rom, rom => rom.GetInternalClone());
|
|
|
|
return partItem;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Comparision Methods
|
|
|
|
/// <inheritdoc/>
|
|
public override bool Equals(DatItem? other)
|
|
{
|
|
// If the other item is null
|
|
if (other is null)
|
|
return false;
|
|
|
|
// If the type matches
|
|
if (other is DataArea otherDataArea)
|
|
return _internal.Equals(otherDataArea._internal);
|
|
|
|
// Everything else fails
|
|
return false;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override bool Equals(DatItem<Data.Models.Metadata.DataArea>? other)
|
|
{
|
|
// If the other value is invalid
|
|
if (other is null)
|
|
return false;
|
|
|
|
// If the type matches
|
|
if (other is DataArea otherDataArea)
|
|
return _internal.Equals(otherDataArea._internal);
|
|
|
|
// Everything else fails
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|