mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-05 22:01:33 +00:00
76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
using System.Xml.Serialization;
|
|
using Newtonsoft.Json;
|
|
using SabreTools.Data.Extensions;
|
|
|
|
namespace SabreTools.Metadata.DatItems.Formats
|
|
{
|
|
/// <summary>
|
|
/// Represents one ListXML dipvalue
|
|
/// </summary>
|
|
[JsonObject("dipvalue"), XmlRoot("dipvalue")]
|
|
public sealed class DipValue : DatItem<Data.Models.Metadata.DipValue>
|
|
{
|
|
#region Fields
|
|
|
|
/// <inheritdoc>/>
|
|
protected override ItemType ItemType => ItemType.DipValue;
|
|
|
|
[JsonIgnore]
|
|
public bool ConditionsSpecified
|
|
{
|
|
get
|
|
{
|
|
var conditions = Read<Condition[]?>(Data.Models.Metadata.DipValue.ConditionKey);
|
|
return conditions is not null && conditions.Length > 0;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public DipValue() : base() { }
|
|
|
|
public DipValue(Data.Models.Metadata.DipValue item) : base(item)
|
|
{
|
|
// Process flag values
|
|
bool? defaultValue = ReadBool(Data.Models.Metadata.DipValue.DefaultKey);
|
|
if (defaultValue is not null)
|
|
Write<string?>(Data.Models.Metadata.DipValue.DefaultKey, defaultValue.FromYesNo());
|
|
|
|
// Handle subitems
|
|
var condition = Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipValue.ConditionKey);
|
|
if (condition is not null)
|
|
Write<Condition?>(Data.Models.Metadata.DipValue.ConditionKey, new Condition(condition));
|
|
}
|
|
|
|
public DipValue(Data.Models.Metadata.DipValue item, Machine machine, Source source) : this(item)
|
|
{
|
|
Write<Source?>(SourceKey, source);
|
|
CopyMachineInformation(machine);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Cloning Methods
|
|
|
|
/// <inheritdoc/>
|
|
public override object Clone() => new DipValue(_internal.Clone() as Data.Models.Metadata.DipValue ?? []);
|
|
|
|
/// <inheritdoc/>
|
|
public override Data.Models.Metadata.DipValue GetInternalClone()
|
|
{
|
|
var dipValueItem = base.GetInternalClone();
|
|
|
|
// Handle subitems
|
|
var subCondition = Read<Condition>(Data.Models.Metadata.DipValue.ConditionKey);
|
|
if (subCondition is not null)
|
|
dipValueItem[Data.Models.Metadata.DipValue.ConditionKey] = subCondition.GetInternalClone();
|
|
|
|
return dipValueItem;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|