Files
SabreTools/SabreTools.DatItems/Analog.cs

135 lines
3.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-12-08 13:23:59 -08:00
using SabreTools.Core;
using Newtonsoft.Json;
2020-12-08 15:15:41 -08:00
namespace SabreTools.DatItems
{
/// <summary>
/// Represents a single analog item
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("analog"), XmlRoot("analog")]
public class Analog : DatItem
{
#region Fields
/// <summary>
/// Analog mask value
/// </summary>
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("mask")]
public string Mask { get; set; }
#endregion
#region Accessors
2020-12-13 13:22:06 -08:00
/// <inheritdoc/>
public override void SetFields(
Dictionary<DatItemField, string> datItemMappings,
Dictionary<MachineField, string> machineMappings)
{
// Set base fields
2020-12-13 13:22:06 -08:00
base.SetFields(datItemMappings, machineMappings);
// Handle Analog-specific fields
2020-12-13 13:22:06 -08:00
if (datItemMappings.Keys.Contains(DatItemField.Analog_Mask))
Mask = datItemMappings[DatItemField.Analog_Mask];
}
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Analog object
/// </summary>
public Analog()
{
ItemType = ItemType.Analog;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Analog()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Mask = this.Mask,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Analog, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Analog
Analog newOther = other as Analog;
// If the Feature information matches
return (Mask == newOther.Mask);
}
#endregion
#region Filtering
2020-12-13 13:22:06 -08:00
/// <inheritdoc/>
public override void RemoveFields(
List<DatItemField> datItemFields,
List<MachineField> machineFields)
{
// Remove common fields first
2020-12-13 13:22:06 -08:00
base.RemoveFields(datItemFields, machineFields);
// Remove the fields
2020-12-13 13:22:06 -08:00
if (datItemFields.Contains(DatItemField.Analog_Mask))
Mask = null;
}
#endregion
#region Sorting and Merging
2020-12-13 13:22:06 -08:00
/// <inheritdoc/>
public override void ReplaceFields(
DatItem item,
List<DatItemField> datItemFields,
List<MachineField> machineFields)
{
// Replace common fields first
2020-12-13 13:22:06 -08:00
base.ReplaceFields(item, datItemFields, machineFields);
// If we don't have a Analog to replace from, ignore specific fields
if (item.ItemType != ItemType.Analog)
return;
// Cast for easier access
Analog newItem = item as Analog;
// Replace the fields
2020-12-13 13:22:06 -08:00
if (datItemFields.Contains(DatItemField.Analog_Mask))
Mask = newItem.Mask;
}
#endregion
}
}