Files
SabreTools/SabreTools.DatItems/Formats/Setting.cs

131 lines
3.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-09-03 13:01:33 -07:00
2020-12-08 13:23:59 -08:00
using SabreTools.Core;
2020-09-03 13:01:33 -07:00
using Newtonsoft.Json;
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents one ListXML confsetting or dipvalue
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("setting"), XmlRoot("setting")]
public class Setting : DatItem
{
#region Fields
/// <summary>
/// Setting name
/// </summary>
[JsonProperty("name")]
2020-09-07 22:00:02 -07:00
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Setting value
/// </summary>
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("value")]
public string Value { get; set; }
/// <summary>
/// Determines if the setting is default or not
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("default")]
public bool? Default { get; set; }
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool DefaultSpecified { get { return Default != null; } }
/// <summary>
/// List of conditions on the setting
/// </summary>
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("conditions")]
public List<Condition> Conditions { get; set; }
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
#endregion
#region Accessors
/// <inheritdoc/>
2020-12-14 10:15:28 -08:00
public override string GetName() => Name;
/// <inheritdoc/>
2020-12-14 10:15:28 -08:00
public override void SetName(string name) => Name = name;
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Setting object
/// </summary>
public Setting()
{
Name = string.Empty;
ItemType = ItemType.Setting;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Setting()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
2020-09-03 13:01:33 -07:00
Name = this.Name,
Value = this.Value,
Default = this.Default,
Conditions = this.Conditions,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Setting, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Setting
Setting newOther = other as Setting;
// If the Setting information matches
bool match = (Name == newOther.Name
&& Value == newOther.Value
&& Default == newOther.Default);
if (!match)
return match;
// If the conditions match
2020-09-30 13:25:40 -07:00
if (ConditionsSpecified)
{
foreach (Condition condition in Conditions)
{
match &= newOther.Conditions.Contains(condition);
}
}
return match;
}
#endregion
}
}