using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Core;
using SabreTools.Filter;
namespace SabreTools.DatItems.Formats
{
///
/// Represents the sound output for a machine
///
[JsonObject("sound"), XmlRoot("sound")]
public class Sound : DatItem
{
#region Fields
///
/// Number of speakers or channels
///
[JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("channels")]
public long? Channels
{
get => _internal.ReadLong(Models.Metadata.Sound.ChannelsKey);
set => _internal[Models.Metadata.Sound.ChannelsKey] = value;
}
[JsonIgnore]
public bool ChannelsSpecified { get { return Channels != null; } }
#endregion
#region Constructors
///
/// Create a default, empty Sound object
///
public Sound()
{
_internal = new Models.Metadata.Sound();
Machine = new Machine();
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 ?? new Machine(),
Source = this.Source?.Clone() as Source,
Remove = this.Remove,
_internal = this._internal?.Clone() as Models.Metadata.Sound ?? [],
};
}
#endregion
#region Manipulation
///
public override bool RemoveField(DatItemField datItemField)
{
// Get the correct internal field name
string? fieldName = datItemField switch
{
DatItemField.Default => Models.Metadata.Sound.ChannelsKey,
_ => null,
};
// Remove the field and return
return FieldManipulator.RemoveField(_internal, fieldName);
}
///
public override bool SetField(DatItemField datItemField, string value)
{
// Get the correct internal field name
string? fieldName = datItemField switch
{
DatItemField.Default => Models.Metadata.Sound.ChannelsKey,
_ => null,
};
// Set the field and return
return FieldManipulator.SetField(_internal, fieldName, value);
}
#endregion
}
}