Files
SabreTools/SabreTools.DatItems/Formats/Configuration.cs

135 lines
4.4 KiB
C#
Raw Normal View History

2020-09-01 11:55:11 -07:00
using System.Collections.Generic;
using System.Linq;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-09-01 11:55:11 -07:00
using Newtonsoft.Json;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2020-09-01 11:55:11 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
2020-09-01 11:55:11 -07:00
{
/// <summary>
/// Represents which Configuration(s) is associated with a set
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("configuration"), XmlRoot("configuration")]
2020-09-01 11:55:11 -07:00
public class Configuration : DatItem
{
#region Fields
2020-09-02 12:19:12 -07:00
/// <summary>
/// Name of the item
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("name"), XmlElement("name")]
public string? Name
{
2023-08-14 22:33:05 -04:00
get => _internal.ReadString(Models.Internal.Configuration.NameKey);
set => _internal[Models.Internal.Configuration.NameKey] = value;
}
2020-09-02 12:19:12 -07:00
2020-09-01 11:55:11 -07:00
/// <summary>
/// Tag associated with the configuration
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
public string? Tag
{
2023-08-14 22:33:05 -04:00
get => _internal.ReadString(Models.Internal.Configuration.TagKey);
set => _internal[Models.Internal.Configuration.TagKey] = value;
}
2020-09-01 11:55:11 -07:00
/// <summary>
/// Mask associated with the configuration
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")]
public string? Mask
{
2023-08-14 22:33:05 -04:00
get => _internal.ReadString(Models.Internal.Configuration.MaskKey);
set => _internal[Models.Internal.Configuration.MaskKey] = value;
}
2020-09-01 11:55:11 -07:00
/// <summary>
/// Conditions associated with the configuration
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
public List<Condition>? Conditions
{
2023-08-14 22:33:05 -04:00
get => _internal.Read<Condition[]>(Models.Internal.Configuration.ConditionKey)?.ToList();
set => _internal[Models.Internal.Configuration.ConditionKey] = value?.ToArray();
}
2020-09-01 11:55:11 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
2020-09-01 11:55:11 -07:00
/// <summary>
/// Locations associated with the configuration
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("locations")]
public List<ConfLocation>? Locations
{
2023-08-14 22:33:05 -04:00
get => _internal.Read<ConfLocation[]>(Models.Internal.Configuration.ConfLocationKey)?.ToList();
set => _internal[Models.Internal.Configuration.ConfLocationKey] = value?.ToArray();
}
2020-09-01 11:55:11 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } }
2020-09-01 11:55:11 -07:00
/// <summary>
/// Settings associated with the configuration
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("settings", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("settings")]
public List<ConfSetting>? Settings
{
2023-08-14 22:33:05 -04:00
get => _internal.Read<List<ConfSetting>>(Models.Internal.Configuration.ConfSettingKey);
set => _internal[Models.Internal.Configuration.ConfSettingKey] = value;
}
2020-09-01 11:55:11 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool SettingsSpecified { get { return Settings != null && Settings.Count > 0; } }
2020-09-01 11:55:11 -07:00
#endregion
#region Accessors
/// <inheritdoc/>
public override string? GetName() => Name;
2020-09-02 12:19:12 -07:00
/// <inheritdoc/>
public override void SetName(string? name) => Name = name;
2020-09-01 11:55:11 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Configuration object
/// </summary>
public Configuration()
{
2023-08-14 22:33:05 -04:00
_internal = new Models.Internal.Configuration();
2023-08-15 01:38:01 -04:00
Machine = new Machine();
2020-09-01 11:55:11 -07:00
Name = string.Empty;
ItemType = ItemType.Configuration;
}
#endregion
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-09-01 11:55:11 -07:00
public override object Clone()
{
return new Configuration()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
2023-08-15 01:38:01 -04:00
Machine = this.Machine.Clone() as Machine ?? new Machine(),
Source = this.Source?.Clone() as Source,
2020-09-01 11:55:11 -07:00
Remove = this.Remove,
2023-08-14 22:33:05 -04:00
_internal = this._internal?.Clone() as Models.Internal.Configuration ?? new Models.Internal.Configuration(),
2020-09-01 11:55:11 -07:00
};
}
#endregion
}
}