Files
SabreTools/SabreTools.DatItems/Formats/Chip.cs

117 lines
3.0 KiB
C#
Raw Normal View History

using System.Xml.Serialization;
2020-08-25 22:48:46 -07:00
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2020-08-25 22:48:46 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
2020-08-25 22:48:46 -07:00
{
/// <summary>
/// Represents which Chip(s) is associated with a set
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("chip"), XmlRoot("chip")]
2020-08-25 22:48:46 -07:00
public class Chip : 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")]
2020-09-02 12:19:12 -07:00
public string Name { get; set; }
2020-08-25 22:48:46 -07:00
/// <summary>
/// Internal tag
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
2020-08-25 22:48:46 -07:00
public string Tag { get; set; }
/// <summary>
/// Type of the chip
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")]
[JsonConverter(typeof(StringEnumConverter))]
public ChipType ChipType { get; set; }
2020-08-25 22:48:46 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ChipTypeSpecified { get { return ChipType != ChipType.NULL; } }
2020-08-25 22:48:46 -07:00
/// <summary>
/// Clock speed
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("clock", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("clock")]
2020-09-04 11:20:54 -07:00
public long? Clock { get; set; }
2020-08-25 22:48:46 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ClockTypeSpecified { get { return Clock != null; } }
2020-08-25 22:48:46 -07:00
#endregion
#region Accessors
/// <inheritdoc/>
2020-12-14 10:15:28 -08:00
public override string GetName() => Name;
2020-09-02 12:19:12 -07:00
/// <inheritdoc/>
2020-12-14 10:15:28 -08:00
public override void SetName(string name) => Name = name;
2020-08-25 22:48:46 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Chip object
/// </summary>
public Chip()
{
Name = string.Empty;
ItemType = ItemType.Chip;
}
#endregion
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-08-25 22:48:46 -07:00
public override object Clone()
{
return new Chip()
{
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,
2020-08-25 22:48:46 -07:00
Tag = this.Tag,
ChipType = this.ChipType,
Clock = this.Clock,
};
}
#endregion
#region Comparision Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-08-25 22:48:46 -07:00
public override bool Equals(DatItem other)
{
// If we don't have a chip, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a chip
Chip newOther = other as Chip;
// If the chip information matches
return (Name == newOther.Name
&& Tag == newOther.Tag
&& ChipType == newOther.ChipType
&& Clock == newOther.Clock);
}
#endregion
}
}