Files
SabreTools/SabreTools.DatItems/Formats/DipValue.cs
2023-08-14 22:33:05 -04:00

110 lines
3.2 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Core;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents one ListXML dipvalue
/// </summary>
[JsonObject("dipvalue"), XmlRoot("dipvalue")]
public class DipValue : DatItem
{
#region Fields
/// <summary>
/// Setting name
/// </summary>
[JsonProperty("name"), XmlElement("name")]
public string? Name
{
get => _internal.ReadString(Models.Internal.DipValue.NameKey);
set => _internal[Models.Internal.DipValue.NameKey] = value;
}
/// <summary>
/// Setting value
/// </summary>
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("value")]
public string? Value
{
get => _internal.ReadString(Models.Internal.DipValue.ValueKey);
set => _internal[Models.Internal.DipValue.ValueKey] = value;
}
/// <summary>
/// Determines if the setting is default or not
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
public bool? Default
{
get => _internal.ReadBool(Models.Internal.DipValue.DefaultKey);
set => _internal[Models.Internal.DipValue.DefaultKey] = value;
}
[JsonIgnore]
public bool DefaultSpecified { get { return Default != null; } }
/// <summary>
/// List of conditions on the setting
/// </summary>
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
public List<Condition>? Conditions
{
get => _internal.Read<Condition[]>(Models.Internal.DipValue.ConditionKey)?.ToList();
set => _internal[Models.Internal.DipValue.ConditionKey] = value?.ToArray();
}
[JsonIgnore]
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
#endregion
#region Accessors
/// <inheritdoc/>
public override string? GetName() => Name;
/// <inheritdoc/>
public override void SetName(string? name) => Name = name;
#endregion
#region Constructors
/// <summary>
/// Create a default, empty DipValue object
/// </summary>
public DipValue()
{
_internal = new Models.Internal.DipValue();
Name = string.Empty;
ItemType = ItemType.DipValue;
}
#endregion
#region Cloning Methods
/// <inheritdoc/>
public override object Clone()
{
return new DipValue()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine?.Clone() as Machine,
Source = this.Source?.Clone() as Source,
Remove = this.Remove,
_internal = this._internal?.Clone() as Models.Internal.DipValue ?? new Models.Internal.DipValue(),
};
}
#endregion
}
}