2017-01-27 16:42:24 -08:00
|
|
|
|
using System;
|
2020-09-07 14:47:27 -07:00
|
|
|
|
using System.Xml.Serialization;
|
2020-08-21 17:27:11 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2023-08-14 15:12:26 -04:00
|
|
|
|
using SabreTools.Core;
|
2024-03-05 01:42:42 -05:00
|
|
|
|
using SabreTools.Filter;
|
2017-01-08 22:48:19 -08:00
|
|
|
|
|
2020-12-08 15:15:41 -08:00
|
|
|
|
namespace SabreTools.DatItems
|
2016-10-24 12:58:57 -07:00
|
|
|
|
{
|
2019-01-08 12:11:55 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents the information specific to a set/game/machine
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonObject("machine"), XmlRoot("machine")]
|
2024-03-12 22:22:12 -04:00
|
|
|
|
public class Machine : ModelBackedItem<Models.Metadata.Machine>, ICloneable
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
|
#region Constants
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Trurip/EmuArc Machine developer
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public const string DeveloperKey = "DEVELOPER";
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Trurip/EmuArc Game genre
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public const string GenreKey = "GENRE";
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Trurip/EmuArc Title ID
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public const string TitleIDKey = "TITLEID";
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-03-12 11:53:58 -04:00
|
|
|
|
#region Constructors
|
2020-09-07 22:00:02 -07:00
|
|
|
|
|
2024-03-12 11:53:58 -04:00
|
|
|
|
public Machine() { }
|
2020-08-20 22:42:04 -07:00
|
|
|
|
|
2024-03-12 11:53:58 -04:00
|
|
|
|
public Machine(Models.Metadata.Machine machine)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Get all fields to automatically copy without processing
|
|
|
|
|
|
var nonItemFields = TypeHelper.GetConstants(typeof(Models.Metadata.Machine));
|
|
|
|
|
|
if (nonItemFields == null)
|
|
|
|
|
|
return;
|
2020-08-20 22:42:04 -07:00
|
|
|
|
|
2024-03-12 11:53:58 -04:00
|
|
|
|
// Populate the internal machine from non-filter fields
|
2024-03-12 22:22:12 -04:00
|
|
|
|
_internal = new Models.Metadata.Machine();
|
2024-03-12 11:53:58 -04:00
|
|
|
|
foreach (string fieldName in nonItemFields)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (machine.ContainsKey(fieldName))
|
2024-03-12 22:22:12 -04:00
|
|
|
|
_internal[fieldName] = machine[fieldName];
|
2024-03-12 11:53:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-21 17:27:11 -07:00
|
|
|
|
|
2024-03-09 23:43:43 -05:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Accessors
|
2020-08-21 17:27:11 -07:00
|
|
|
|
|
2024-03-11 11:07:21 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a clone of the current internal model
|
|
|
|
|
|
/// </summary>
|
2024-03-12 22:22:12 -04:00
|
|
|
|
public Models.Metadata.Machine GetInternalClone() => (_internal.Clone() as Models.Metadata.Machine)!;
|
2024-03-11 11:07:21 -04:00
|
|
|
|
|
2020-09-07 14:47:27 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
#region Cloning methods
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a clone of the current machine
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>New machine with the same values as the current one</returns>
|
|
|
|
|
|
public object Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Machine()
|
|
|
|
|
|
{
|
2024-03-12 22:22:12 -04:00
|
|
|
|
_internal = this._internal.Clone() as Models.Metadata.Machine ?? [],
|
2019-01-08 12:11:55 -08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-03-05 01:42:42 -05:00
|
|
|
|
|
|
|
|
|
|
#region Manipulation
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-03-05 02:56:50 -05:00
|
|
|
|
/// Runs a filter and determines if it passes or not
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filterRunner">Filter runner to use for checking</param>
|
|
|
|
|
|
/// <returns>True if the Machine passes the filter, false otherwise</returns>
|
2024-03-12 22:22:12 -04:00
|
|
|
|
public bool PassesFilter(FilterRunner filterRunner) => filterRunner.Run(_internal);
|
2024-03-05 02:56:50 -05:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-03-05 01:42:42 -05:00
|
|
|
|
/// Remove a field from the Machine
|
|
|
|
|
|
/// </summary>
|
2024-03-05 16:37:52 -05:00
|
|
|
|
/// <param name="fieldName">Field to remove</param>
|
2024-03-05 01:42:42 -05:00
|
|
|
|
/// <returns>True if the removal was successful, false otherwise</returns>
|
2024-03-05 16:37:52 -05:00
|
|
|
|
public bool RemoveField(string? fieldName)
|
2024-03-12 22:22:12 -04:00
|
|
|
|
=> FieldManipulator.RemoveField(_internal, fieldName);
|
2024-03-05 01:42:42 -05:00
|
|
|
|
|
2024-03-05 20:07:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Replace a field from another Machine
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="other">Machine to replace field from</param>
|
|
|
|
|
|
/// <param name="fieldName">Field to replace</param>
|
|
|
|
|
|
/// <returns>True if the replacement was successful, false otherwise</returns>
|
|
|
|
|
|
public bool ReplaceField(Machine? other, string? fieldName)
|
2024-03-12 22:22:12 -04:00
|
|
|
|
=> FieldManipulator.ReplaceField(other?._internal, _internal, fieldName);
|
2024-03-05 20:07:38 -05:00
|
|
|
|
|
2024-03-05 02:20:12 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set a field in the Machine from a mapping string
|
|
|
|
|
|
/// </summary>
|
2024-03-05 17:17:40 -05:00
|
|
|
|
/// <param name="fieldName">Field to set</param>
|
2024-03-05 02:20:12 -05:00
|
|
|
|
/// <param name="value">String representing the value to set</param>
|
|
|
|
|
|
/// <returns>True if the setting was successful, false otherwise</returns>
|
|
|
|
|
|
/// <remarks>This only performs minimal validation before setting</remarks>
|
2024-03-05 17:17:40 -05:00
|
|
|
|
public bool SetField(string? fieldName, string value)
|
2024-03-12 22:22:12 -04:00
|
|
|
|
=> FieldManipulator.SetField(_internal, fieldName, value);
|
2024-03-05 02:20:12 -05:00
|
|
|
|
|
2024-03-05 01:42:42 -05:00
|
|
|
|
#endregion
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
2016-10-24 12:58:57 -07:00
|
|
|
|
}
|