2020-12-14 10:58:43 -08:00
|
|
|
|
using System.Xml.Serialization;
|
2020-09-02 16:46:17 -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-09-02 16:46:17 -07:00
|
|
|
|
|
2021-02-02 10:23:43 -08:00
|
|
|
|
namespace SabreTools.DatItems.Formats
|
2020-09-02 16:46:17 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents a single instance of another item
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonObject("instance"), XmlRoot("instance")]
|
2020-09-02 16:46:17 -07:00
|
|
|
|
public class Instance : DatItem
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Name of the item
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("name"), XmlElement("name")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Name
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.ReadString(Models.Metadata.Instance.NameKey);
|
|
|
|
|
|
set => _internal[Models.Metadata.Instance.NameKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 16:46:17 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Short name for the instance
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("briefname", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("briefname")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? BriefName
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.ReadString(Models.Metadata.Instance.BriefNameKey);
|
|
|
|
|
|
set => _internal[Models.Metadata.Instance.BriefNameKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-02 16:46:17 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Accessors
|
|
|
|
|
|
|
2020-12-13 14:01:16 -08:00
|
|
|
|
/// <inheritdoc/>
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public override string? GetName() => Name;
|
2020-09-02 16:46:17 -07:00
|
|
|
|
|
2020-12-13 14:01:16 -08:00
|
|
|
|
/// <inheritdoc/>
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public override void SetName(string? name) => Name = name;
|
2020-12-13 14:01:16 -08:00
|
|
|
|
|
2020-09-02 16:46:17 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a default, empty Instance object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Instance()
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
_internal = new Models.Metadata.Instance();
|
2023-08-15 01:38:01 -04:00
|
|
|
|
Machine = new Machine();
|
|
|
|
|
|
|
2020-09-02 16:46:17 -07:00
|
|
|
|
Name = string.Empty;
|
|
|
|
|
|
ItemType = ItemType.Instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Cloning Methods
|
|
|
|
|
|
|
2022-11-03 12:22:17 -07:00
|
|
|
|
/// <inheritdoc/>
|
2020-09-02 16:46:17 -07:00
|
|
|
|
public override object Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Instance()
|
|
|
|
|
|
{
|
|
|
|
|
|
ItemType = this.ItemType,
|
|
|
|
|
|
DupeType = this.DupeType,
|
|
|
|
|
|
|
2023-08-15 01:38:01 -04:00
|
|
|
|
Machine = this.Machine.Clone() as Machine ?? new Machine(),
|
2023-08-14 13:17:51 -04:00
|
|
|
|
Source = this.Source?.Clone() as Source,
|
2020-09-02 16:46:17 -07:00
|
|
|
|
Remove = this.Remove,
|
|
|
|
|
|
|
2024-02-28 19:19:50 -05:00
|
|
|
|
_internal = this._internal?.Clone() as Models.Metadata.Instance ?? [],
|
2020-09-02 16:46:17 -07:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-03-05 01:42:42 -05:00
|
|
|
|
|
|
|
|
|
|
#region Manipulation
|
|
|
|
|
|
|
2024-03-05 02:20:12 -05:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public override bool SetField(DatItemField datItemField, string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Get the correct internal field name
|
|
|
|
|
|
string? fieldName = datItemField switch
|
|
|
|
|
|
{
|
|
|
|
|
|
DatItemField.Instance_BriefName => Models.Metadata.Instance.BriefNameKey,
|
|
|
|
|
|
_ => null,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Set the field and return
|
|
|
|
|
|
return FieldManipulator.SetField(_internal, fieldName, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-05 01:42:42 -05:00
|
|
|
|
#endregion
|
2020-09-02 16:46:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|