Files
SabreTools/SabreTools.DatItems/Formats/ConfSetting.cs

102 lines
3.1 KiB
C#
Raw Normal View History

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 confsetting
/// </summary>
[JsonObject("confsetting"), XmlRoot("confsetting")]
public class ConfSetting : DatItem
{
#region Fields
/// <summary>
/// Setting value
/// </summary>
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("value")]
public string? Value
{
2023-09-04 23:51:37 -04:00
get => _internal.ReadString(Models.Metadata.ConfSetting.ValueKey);
set => _internal[Models.Metadata.ConfSetting.ValueKey] = value;
}
/// <summary>
/// Determines if the setting is default or not
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
public bool? Default
{
2023-09-04 23:51:37 -04:00
get => _internal.ReadBool(Models.Metadata.ConfSetting.DefaultKey);
set => _internal[Models.Metadata.ConfSetting.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
{
2023-09-04 23:51:37 -04:00
get => _internal.Read<Condition[]>(Models.Metadata.ConfSetting.ConditionKey)?.ToList();
set => _internal[Models.Metadata.ConfSetting.ConditionKey] = value?.ToArray();
}
[JsonIgnore]
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
#endregion
#region Accessors
/// <inheritdoc/>
2024-03-08 15:31:21 -05:00
public override string? GetName() => GetFieldValue<string>(Models.Metadata.ConfSetting.NameKey);
/// <inheritdoc/>
2024-03-08 15:31:21 -05:00
public override void SetName(string? name) => SetFieldValue(Models.Metadata.ConfSetting.NameKey, name);
#endregion
#region Constructors
/// <summary>
/// Create a default, empty ConfSetting object
/// </summary>
public ConfSetting()
{
2023-09-04 23:51:37 -04:00
_internal = new Models.Metadata.ConfSetting();
2023-08-15 01:38:01 -04:00
Machine = new Machine();
2024-03-08 20:42:24 -05:00
SetName(string.Empty);
ItemType = ItemType.ConfSetting;
}
#endregion
#region Cloning Methods
/// <inheritdoc/>
public override object Clone()
{
return new ConfSetting()
{
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,
Remove = this.Remove,
2024-02-28 19:19:50 -05:00
_internal = this._internal?.Clone() as Models.Metadata.ConfSetting ?? [],
};
}
#endregion
}
}