2025-01-11 22:00:26 -05:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Xml.Serialization;
|
2020-09-02 17:22:31 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2025-01-11 22:00:26 -05:00
|
|
|
|
using SabreTools.Core;
|
2020-09-02 17:22:31 -07:00
|
|
|
|
|
2021-02-02 10:23:43 -08:00
|
|
|
|
namespace SabreTools.DatItems.Formats
|
2020-09-02 17:22:31 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents a single port on a machine
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonObject("port"), XmlRoot("port")]
|
2024-03-10 20:39:54 -04:00
|
|
|
|
public sealed class Port : DatItem<Models.Metadata.Port>
|
2020-09-02 17:22:31 -07:00
|
|
|
|
{
|
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
2024-03-10 20:39:54 -04:00
|
|
|
|
/// <inheritdoc>/>
|
|
|
|
|
|
protected override ItemType ItemType => ItemType.Port;
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc>/>
|
|
|
|
|
|
protected override string? NameKey => null;
|
|
|
|
|
|
|
2024-03-09 21:34:26 -05:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool AnalogsSpecified
|
2023-08-14 13:17:51 -04:00
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var analogs = GetFieldValue<Analog[]?>(Models.Metadata.Port.AnalogKey);
|
|
|
|
|
|
return analogs != null && analogs.Length > 0;
|
|
|
|
|
|
}
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 17:22:31 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
2024-03-10 20:39:54 -04:00
|
|
|
|
public Port() : base() { }
|
2025-01-11 23:34:26 -05:00
|
|
|
|
|
2025-01-11 22:00:26 -05:00
|
|
|
|
public Port(Models.Metadata.Port item) : base(item)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Handle subitems
|
|
|
|
|
|
var analogs = item.ReadItemArray<Models.Metadata.Analog>(Models.Metadata.Port.AnalogKey);
|
|
|
|
|
|
if (analogs != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Analog[] analogItems = Array.ConvertAll(analogs, analog => new Analog(analog));
|
|
|
|
|
|
SetFieldValue<Analog[]?>(Models.Metadata.Port.AnalogKey, analogItems);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-02 17:22:31 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2025-01-11 23:34:26 -05:00
|
|
|
|
|
|
|
|
|
|
#region Cloning Methods
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public override Models.Metadata.Port GetInternalClone()
|
|
|
|
|
|
{
|
|
|
|
|
|
var portItem = base.GetInternalClone();
|
|
|
|
|
|
|
|
|
|
|
|
var analogs = GetFieldValue<Analog[]?>(Models.Metadata.Port.AnalogKey);
|
|
|
|
|
|
if (analogs != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Models.Metadata.Analog[] analogItems = Array.ConvertAll(analogs, analog => analog.GetInternalClone());
|
|
|
|
|
|
portItem[Models.Metadata.Port.AnalogKey] = analogItems;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return portItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2020-09-02 17:22:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|