using System.Xml.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using SabreTools.Core; using SabreTools.Core.Tools; namespace SabreTools.DatItems.Formats { /// /// Represents which Chip(s) is associated with a set /// [JsonObject("chip"), XmlRoot("chip")] public class Chip : DatItem { #region Fields /// /// Name of the item /// [JsonProperty("name"), XmlElement("name")] public string? Name { get => _chip.ReadString(Models.Internal.Chip.NameKey); set => _chip[Models.Internal.Chip.NameKey] = value; } /// /// Internal tag /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")] public string? Tag { get => _chip.ReadString(Models.Internal.Chip.TagKey); set => _chip[Models.Internal.Chip.TagKey] = value; } /// /// Type of the chip /// [JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")] [JsonConverter(typeof(StringEnumConverter))] public ChipType ChipType { get => _chip.ReadString(Models.Internal.Chip.ChipTypeKey).AsChipType(); set => _chip[Models.Internal.Chip.ChipTypeKey] = value.FromChipType(); } [JsonIgnore] public bool ChipTypeSpecified { get { return ChipType != ChipType.NULL; } } /// /// Clock speed /// [JsonProperty("clock", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("clock")] public long? Clock { get => _chip.ReadLong(Models.Internal.Chip.ClockKey); set => _chip[Models.Internal.Chip.ClockKey] = value; } [JsonIgnore] public bool ClockSpecified { get { return Clock != null; } } /// /// Internal Chip model /// [JsonIgnore] private Models.Internal.Chip _chip = new(); #endregion #region Accessors /// public override string? GetName() => Name; /// public override void SetName(string? name) => Name = name; #endregion #region Constructors /// /// Create a default, empty Chip object /// public Chip() { Name = string.Empty; ItemType = ItemType.Chip; } #endregion #region Cloning Methods /// 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, _chip = this._chip?.Clone() as Models.Internal.Chip ?? new Models.Internal.Chip(), }; } #endregion #region Comparision Methods /// public override bool Equals(DatItem? other) { // If we don't have a Chip, return false if (ItemType != other?.ItemType || other is not Chip otherInternal) return false; // Compare the internal models return _chip.EqualTo(otherInternal._chip); } #endregion } }