Files
SabreTools/SabreTools.DatItems/Formats/Sample.cs

92 lines
2.2 KiB
C#
Raw Normal View History

using System.Xml.Serialization;
2020-09-02 12:19:12 -07:00
using Newtonsoft.Json;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2024-03-05 01:42:42 -05:00
using SabreTools.Filter;
2020-08-23 22:23:55 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
{
2019-01-08 17:40:12 -08:00
/// <summary>
/// Represents a (usually WAV-formatted) sample to be included for use in the set
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("sample"), XmlRoot("sample")]
2019-01-08 17:40:12 -08:00
public class Sample : DatItem
{
2020-09-02 12:19:12 -07:00
#region Fields
/// <summary>
/// Name of the item
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("name"), XmlElement("name")]
public string? Name
{
2023-09-04 23:51:37 -04:00
get => _internal.ReadString(Models.Metadata.Sample.NameKey);
set => _internal[Models.Metadata.Sample.NameKey] = value;
}
2020-09-02 12:19:12 -07:00
#endregion
#region Accessors
/// <inheritdoc/>
public override string? GetName() => Name;
2020-09-02 12:19:12 -07:00
/// <inheritdoc/>
public override void SetName(string? name) => Name = name;
2020-09-02 12:19:12 -07:00
#endregion
2019-01-08 17:40:12 -08:00
#region Constructors
2019-01-08 17:40:12 -08:00
/// <summary>
/// Create a default, empty Sample object
/// </summary>
public Sample()
{
2023-09-04 23:51:37 -04:00
_internal = new Models.Metadata.Sample();
2023-08-15 01:38:01 -04:00
Machine = new Machine();
2020-08-20 13:17:14 -07:00
Name = string.Empty;
ItemType = ItemType.Sample;
2019-01-08 17:40:12 -08:00
}
2019-01-08 17:40:12 -08:00
#endregion
2019-01-08 17:40:12 -08:00
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2019-01-08 17:40:12 -08:00
public override object Clone()
{
return new Sample()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
2023-08-15 01:38:01 -04:00
Machine = this.Machine.Clone() as Machine ?? new Machine(),
Source = this.Source?.Clone() as Source,
2020-08-20 13:17:14 -07:00
Remove = this.Remove,
2020-09-03 13:01:33 -07:00
2024-02-28 19:19:50 -05:00
_internal = this._internal?.Clone() as Models.Metadata.Sample ?? [],
2019-01-08 17:40:12 -08:00
};
}
2019-01-08 17:40:12 -08:00
#endregion
2024-03-05 01:42:42 -05:00
#region Manipulation
/// <inheritdoc/>
public override bool RemoveField(DatItemField datItemField)
{
// Get the correct internal field name
string? fieldName = datItemField switch
{
_ => null,
};
// Remove the field and return
return FieldManipulator.RemoveField(_internal, fieldName);
}
#endregion
2019-01-08 17:40:12 -08:00
}
}