2020-12-14 10:58:43 -08:00
|
|
|
|
using System.Xml.Serialization;
|
2020-09-02 16:31:23 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2020-09-03 21:59:53 -07:00
|
|
|
|
using Newtonsoft.Json.Converters;
|
2022-11-03 12:22:17 -07:00
|
|
|
|
using SabreTools.Core;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
using SabreTools.Core.Tools;
|
2020-09-02 16:31:23 -07:00
|
|
|
|
|
2021-02-02 10:23:43 -08:00
|
|
|
|
namespace SabreTools.DatItems.Formats
|
2020-09-02 16:31:23 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents a condition on a machine or other item
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonObject("condition"), XmlRoot("condition")]
|
2020-09-02 16:31:23 -07:00
|
|
|
|
public class Condition : DatItem
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Condition tag value
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Tag
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.ReadString(Models.Internal.Condition.TagKey);
|
|
|
|
|
|
set => _internal[Models.Internal.Condition.TagKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 16:31:23 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Condition mask
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Mask
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.ReadString(Models.Internal.Condition.MaskKey);
|
|
|
|
|
|
set => _internal[Models.Internal.Condition.MaskKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 16:31:23 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Condition relationship
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("relation", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("relation")]
|
2020-09-03 21:59:53 -07:00
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public Relation Relation
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.ReadString(Models.Internal.Condition.RelationKey).AsRelation();
|
|
|
|
|
|
set => _internal[Models.Internal.Condition.RelationKey] = value.FromRelation();
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 16:31:23 -07:00
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public bool RelationSpecified { get { return Relation != Core.Relation.NULL; } }
|
2020-09-07 22:00:02 -07:00
|
|
|
|
|
2020-09-02 16:31:23 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Condition value
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("value")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Value
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
get => _internal.ReadString(Models.Internal.Condition.ValueKey);
|
|
|
|
|
|
set => _internal[Models.Internal.Condition.ValueKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-02 16:31:23 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a default, empty Condition object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Condition()
|
|
|
|
|
|
{
|
2023-08-14 22:33:05 -04:00
|
|
|
|
_internal = new Models.Internal.Condition();
|
2020-09-02 16:31:23 -07:00
|
|
|
|
ItemType = ItemType.Condition;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Cloning Methods
|
|
|
|
|
|
|
2022-11-03 12:22:17 -07:00
|
|
|
|
/// <inheritdoc/>
|
2020-09-02 16:31:23 -07:00
|
|
|
|
public override object Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Condition()
|
|
|
|
|
|
{
|
|
|
|
|
|
ItemType = this.ItemType,
|
|
|
|
|
|
DupeType = this.DupeType,
|
|
|
|
|
|
|
2023-08-14 13:17:51 -04:00
|
|
|
|
Machine = this.Machine?.Clone() as Machine,
|
|
|
|
|
|
Source = this.Source?.Clone() as Source,
|
2020-09-02 16:31:23 -07:00
|
|
|
|
Remove = this.Remove,
|
|
|
|
|
|
|
2023-08-14 22:33:05 -04:00
|
|
|
|
_internal = this._internal?.Clone() as Models.Internal.Condition ?? new Models.Internal.Condition(),
|
2020-09-02 16:31:23 -07:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|