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-12 22:52:36 -04:00
|
|
|
|
using SabreTools.Core.Filter;
|
2024-03-12 23:38:06 -04:00
|
|
|
|
using SabreTools.Core.Tools;
|
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")]
|
2025-01-08 14:16:54 -05:00
|
|
|
|
public sealed class Machine : ModelBackedItem<Models.Metadata.Machine>, ICloneable, IEquatable<Machine>
|
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-19 15:38:30 -04:00
|
|
|
|
public Machine()
|
|
|
|
|
|
{
|
|
|
|
|
|
_internal = new Models.Metadata.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
|
|
|
|
}
|
2025-01-11 22:00:26 -05:00
|
|
|
|
|
|
|
|
|
|
// Process flag values
|
|
|
|
|
|
if (GetStringFieldValue(Models.Metadata.Machine.Im1CRCKey) != null)
|
|
|
|
|
|
SetFieldValue<string?>(Models.Metadata.Machine.Im1CRCKey, TextHelper.NormalizeCRC32(GetStringFieldValue(Models.Metadata.Machine.Im1CRCKey)));
|
|
|
|
|
|
if (GetStringFieldValue(Models.Metadata.Machine.Im2CRCKey) != null)
|
|
|
|
|
|
SetFieldValue<string?>(Models.Metadata.Machine.Im2CRCKey, TextHelper.NormalizeCRC32(GetStringFieldValue(Models.Metadata.Machine.Im2CRCKey)));
|
|
|
|
|
|
if (GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) != null)
|
|
|
|
|
|
SetFieldValue<string?>(Models.Metadata.Machine.IsBiosKey, GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey).FromYesNo());
|
|
|
|
|
|
if (GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) != null)
|
|
|
|
|
|
SetFieldValue<string?>(Models.Metadata.Machine.IsDeviceKey, GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey).FromYesNo());
|
|
|
|
|
|
if (GetBoolFieldValue(Models.Metadata.Machine.IsMechanicalKey) != null)
|
|
|
|
|
|
SetFieldValue<string?>(Models.Metadata.Machine.IsMechanicalKey, GetBoolFieldValue(Models.Metadata.Machine.IsMechanicalKey).FromYesNo());
|
|
|
|
|
|
if (GetStringFieldValue(Models.Metadata.Machine.SupportedKey) != null)
|
|
|
|
|
|
SetFieldValue<string?>(Models.Metadata.Machine.SupportedKey, GetStringFieldValue(Models.Metadata.Machine.SupportedKey).AsEnumValue<Supported>().AsStringValue());
|
|
|
|
|
|
|
|
|
|
|
|
// Handle Trurip object, if it exists
|
|
|
|
|
|
if (machine.ContainsKey(Models.Metadata.Machine.TruripKey))
|
|
|
|
|
|
{
|
|
|
|
|
|
var truripItem = machine.Read<Models.Logiqx.Trurip>(Models.Metadata.Machine.TruripKey);
|
|
|
|
|
|
if (truripItem != null)
|
|
|
|
|
|
SetFieldValue<Trurip>(Models.Metadata.Machine.TruripKey, new Trurip(truripItem));
|
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
2025-01-08 14:16:54 -05:00
|
|
|
|
_internal = _internal.Clone() as Models.Metadata.Machine ?? [],
|
2019-01-08 12:11:55 -08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-08 14:16:54 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a clone of the current internal model
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Models.Metadata.Machine GetInternalClone() => (_internal.Clone() as Models.Metadata.Machine)!;
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
#endregion
|
2024-03-05 01:42:42 -05:00
|
|
|
|
|
2025-01-08 11:36:43 -05:00
|
|
|
|
#region Comparision Methods
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public override bool Equals(ModelBackedItem? other)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If other is null
|
|
|
|
|
|
if (other == null)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// If the type is mismatched
|
|
|
|
|
|
if (other is not Machine otherItem)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Compare internal models
|
|
|
|
|
|
return _internal.EqualTo(otherItem._internal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public override bool Equals(ModelBackedItem<Models.Metadata.Machine>? other)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If other is null
|
|
|
|
|
|
if (other == null)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// If the type is mismatched
|
|
|
|
|
|
if (other is not Machine otherItem)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Compare internal models
|
|
|
|
|
|
return _internal.EqualTo(otherItem._internal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-08 14:16:54 -05:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public bool Equals(Machine? other)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If other is null
|
|
|
|
|
|
if (other == null)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Compare internal models
|
|
|
|
|
|
return _internal.EqualTo(other._internal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-08 11:36:43 -05: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
|
|
|
|
|
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
|
|
|
|
}
|