Files
SabreTools/SabreTools.DatItems/Sound.cs

103 lines
2.5 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-09-02 12:51:21 -07:00
2020-12-08 13:23:59 -08:00
using SabreTools.Core;
2020-09-02 12:51:21 -07:00
using Newtonsoft.Json;
2020-12-08 15:15:41 -08:00
namespace SabreTools.DatItems
2020-09-02 12:51:21 -07:00
{
/// <summary>
/// Represents the sound output for a machine
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("sound"), XmlRoot("sound")]
2020-09-02 12:51:21 -07:00
public class Sound : DatItem
{
#region Fields
/// <summary>
/// Number of speakers or channels
2020-09-02 12:51:21 -07:00
/// </summary>
[JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("channels")]
2020-09-03 22:35:09 -07:00
public long? Channels { get; set; }
2020-09-02 12:51:21 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ChannelsSpecified { get { return Channels != null; } }
2020-09-02 12:51:21 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Sound object
/// </summary>
public Sound()
{
ItemType = ItemType.Sound;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Sound()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Channels = this.Channels,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Sound, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Sound
Sound newOther = other as Sound;
// If the Sound information matches
return (Channels == newOther.Channels);
}
#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)
2020-09-02 12:51:21 -07:00
{
// Replace common fields first
2020-12-13 13:22:06 -08:00
base.ReplaceFields(item, datItemFields, machineFields);
2020-09-02 12:51:21 -07:00
// If we don't have a Sound to replace from, ignore specific fields
if (item.ItemType != ItemType.Sound)
return;
// Cast for easier access
Sound newItem = item as Sound;
// Replace the fields
2020-12-13 13:22:06 -08:00
if (datItemFields.Contains(DatItemField.Channels))
2020-09-02 12:51:21 -07:00
Channels = newItem.Channels;
}
#endregion
}
}