Files
SabreTools/SabreTools.DatItems/Formats/Part.cs

109 lines
3.0 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-09-04 14:10:35 -07:00
using Newtonsoft.Json;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2020-09-04 14:10:35 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
2020-09-04 14:10:35 -07:00
{
/// <summary>
/// SoftwareList part information
/// </summary>
/// <remarks>One Part can contain multiple PartFeature, DataArea, DiskArea, and DipSwitch items</remarks>
2020-09-08 10:12:41 -07:00
[JsonObject("part"), XmlRoot("part")]
2020-09-04 14:10:35 -07:00
public class Part : DatItem
{
#region Fields
2022-11-03 12:22:17 -07:00
[JsonProperty("name"), XmlElement("name")]
public string? Name
{
get => _part.ReadString(Models.Internal.Part.NameKey);
set => _part[Models.Internal.Part.NameKey] = value;
}
2020-09-04 14:10:35 -07:00
2022-11-03 12:22:17 -07:00
[JsonProperty("interface"), XmlElement("interface")]
public string? Interface
{
get => _part.ReadString(Models.Internal.Part.InterfaceKey);
set => _part[Models.Internal.Part.InterfaceKey] = value;
}
2020-09-04 14:10:35 -07:00
2022-11-03 12:22:17 -07:00
[JsonProperty("features", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("features")]
public List<PartFeature>? Features
{
get => _part.Read<PartFeature[]>(Models.Internal.Part.FeatureKey)?.ToList();
set => _part[Models.Internal.Part.FeatureKey] = value?.ToArray();
}
2020-09-04 14:10:35 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool FeaturesSpecified { get { return Features != null && Features.Count > 0; } }
/// <summary>
/// Internal Part model
/// </summary>
[JsonIgnore]
private Models.Internal.Part _part = new();
2020-09-04 14:10:35 -07:00
#endregion
#region Accessors
/// <inheritdoc/>
public override string? GetName() => Name;
2020-09-04 14:10:35 -07:00
/// <inheritdoc/>
public override void SetName(string? name) => Name = name;
2020-09-04 14:10:35 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Part object
/// </summary>
public Part()
{
Name = string.Empty;
ItemType = ItemType.Part;
}
#endregion
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-09-04 14:10:35 -07:00
public override object Clone()
{
return new Part()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine?.Clone() as Machine,
Source = this.Source?.Clone() as Source,
2020-09-04 14:10:35 -07:00
Remove = this.Remove,
_part = this._part?.Clone() as Models.Internal.Part ?? new Models.Internal.Part(),
2020-09-04 14:10:35 -07:00
};
}
#endregion
#region Comparision Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
public override bool Equals(DatItem? other)
2020-09-04 14:10:35 -07:00
{
// If we don't have a Part, return false
if (ItemType != other?.ItemType || other is not Part otherInternal)
2020-09-04 14:10:35 -07:00
return false;
// Compare the internal models
return _part.EqualTo(otherInternal._part);
2020-09-04 14:10:35 -07:00
}
#endregion
}
}