Files
SabreTools/SabreTools.DatItems/Location.cs

147 lines
3.8 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:20:56 -07:00
2020-12-08 13:23:59 -08:00
using SabreTools.Core;
2020-09-03 13:20:56 -07:00
using Newtonsoft.Json;
2020-12-08 15:15:41 -08:00
namespace SabreTools.DatItems
{
/// <summary>
/// Represents one conflocation or diplocation
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("location"), XmlRoot("location")]
public class Location : DatItem
{
#region Fields
/// <summary>
/// Location name
/// </summary>
[JsonProperty("name")]
2020-09-07 22:00:02 -07:00
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Location ID
/// </summary>
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("number")]
2020-09-06 23:08:50 -07:00
public long? Number { get; set; }
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool NumberSpecified { get { return Number != null; } }
/// <summary>
/// Determines if location is inverted or not
/// </summary>
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("inverted")]
public bool? Inverted { get; set; }
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool InvertedSpecified { get { return Inverted != null; } }
#endregion
#region Accessors
/// <inheritdoc/>
public override string GetName()
{
return Name;
}
/// <inheritdoc/>
public override void SetName(string name)
{
Name = name;
}
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Location object
/// </summary>
public Location()
{
Name = string.Empty;
ItemType = ItemType.Location;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Location()
{
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,
Number = this.Number,
Inverted = this.Inverted,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Location, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Location
Location newOther = other as Location;
// If the Location information matches
return (Name == newOther.Name
&& Number == newOther.Number
&& Inverted == newOther.Inverted);
}
#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 Location to replace from, ignore specific fields
if (item.ItemType != ItemType.Location)
return;
// Cast for easier access
Location newItem = item as Location;
// Replace the fields
2020-12-13 13:22:06 -08:00
if (datItemFields.Contains(DatItemField.Location_Name))
Name = newItem.Name;
2020-12-13 13:22:06 -08:00
if (datItemFields.Contains(DatItemField.Location_Number))
Number = newItem.Number;
2020-12-13 13:22:06 -08:00
if (datItemFields.Contains(DatItemField.Location_Inverted))
Inverted = newItem.Inverted;
}
#endregion
}
}