Files
SabreTools/SabreTools.Library/DatItems/Machine.cs

1048 lines
32 KiB
C#
Raw Normal View History

2017-01-27 16:42:24 -08:00
using System;
using System.Collections.Generic;
2020-08-20 13:17:14 -07:00
using System.Linq;
2020-09-07 14:47:27 -07:00
using System.Xml.Serialization;
2020-06-11 11:44:46 -07:00
2020-08-20 13:17:14 -07:00
using SabreTools.Library.Filtering;
2020-08-21 10:16:05 -07:00
using SabreTools.Library.Tools;
using Newtonsoft.Json;
2020-08-24 13:53:53 -07:00
using Newtonsoft.Json.Converters;
namespace SabreTools.Library.DatItems
{
/// <summary>
/// Represents the information specific to a set/game/machine
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("machine"), XmlRoot("machine")]
public class Machine : ICloneable
{
2020-08-20 13:17:14 -07:00
#region Fields
2020-09-07 22:00:02 -07:00
#region Common
2020-08-20 14:36:36 -07:00
/// <summary>
/// Name of the machine
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Include)]
2020-09-07 22:00:02 -07:00
[XmlElement("name")]
2020-08-20 14:36:36 -07:00
public string Name { get; set; } = null;
/// <summary>
/// Additional notes
/// </summary>
/// <remarks>Known as "Extra" in AttractMode</remarks>
2020-08-24 11:56:49 -07:00
[JsonProperty("comment", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("comment")]
2020-08-20 14:36:36 -07:00
public string Comment { get; set; } = null;
/// <summary>
/// Extended description
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("description", DefaultValueHandling = DefaultValueHandling.Include)]
2020-09-07 14:47:27 -07:00
[XmlElement("description")]
2020-08-20 14:36:36 -07:00
public string Description { get; set; } = null;
/// <summary>
/// Year(s) of release/manufacture
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("year", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("year")]
2020-08-20 14:36:36 -07:00
public string Year { get; set; } = null;
/// <summary>
/// Manufacturer, if available
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("manufacturer", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("manufacturer")]
2020-08-20 14:36:36 -07:00
public string Manufacturer { get; set; } = null;
/// <summary>
/// Publisher, if available
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("publisher", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("publisher")]
2020-08-20 14:36:36 -07:00
public string Publisher { get; set; } = null;
/// <summary>
/// Category, if available
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("category", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("category")]
2020-08-20 14:36:36 -07:00
public string Category { get; set; } = null;
/// <summary>
/// fomof parent
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("romof", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("romof")]
2020-08-20 14:36:36 -07:00
public string RomOf { get; set; } = null;
/// <summary>
/// cloneof parent
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("cloneof", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("cloneof")]
2020-08-20 14:36:36 -07:00
public string CloneOf { get; set; } = null;
/// <summary>
/// sampleof parent
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("sampleof", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("sampleof")]
2020-08-20 14:36:36 -07:00
public string SampleOf { get; set; } = null;
/// <summary>
/// Type of the machine
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-08-24 13:53:53 -07:00
[JsonConverter(typeof(StringEnumConverter))]
2020-09-07 22:00:02 -07:00
[XmlElement("type")]
public MachineType MachineType { get; set; } = 0x0;
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool MachineTypeSpecified { get { return MachineType != 0x0 && MachineType != MachineType.NULL; } }
2020-08-20 14:36:36 -07:00
#endregion
2020-09-07 22:00:02 -07:00
#region AttractMode
2020-08-20 14:36:36 -07:00
/// <summary>
/// Player count
/// </summary>
2020-08-20 22:42:04 -07:00
/// <remarks>Also in Logiqx EmuArc</remarks>
2020-08-24 11:56:49 -07:00
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("players")]
2020-08-20 14:36:36 -07:00
public string Players { get; set; } = null;
/// <summary>
/// Screen rotation
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("rotation", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("rotation")]
2020-08-20 14:36:36 -07:00
public string Rotation { get; set; } = null;
/// <summary>
/// Control method
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("control", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("control")]
2020-08-20 14:36:36 -07:00
public string Control { get; set; } = null;
/// <summary>
/// Support status
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("status")]
2020-08-20 14:36:36 -07:00
public string Status { get; set; } = null;
/// <summary>
2020-08-20 14:36:36 -07:00
/// Display count
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("displaycount", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("displaycount")]
2020-08-20 14:36:36 -07:00
public string DisplayCount { get; set; } = null;
/// <summary>
2020-08-20 14:36:36 -07:00
/// Display type
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("displaytype", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("displaytype")]
2020-08-20 14:36:36 -07:00
public string DisplayType { get; set; } = null;
/// <summary>
2020-08-20 14:36:36 -07:00
/// Number of input buttons
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("buttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("buttons")]
2020-08-20 14:36:36 -07:00
public string Buttons { get; set; } = null;
#endregion
2020-09-07 22:00:02 -07:00
#region ListXML
/// <summary>
2020-08-20 14:36:36 -07:00
/// Emulator source file related to the machine
/// </summary>
/// <remarks>Also in Logiqx</remarks>
2020-08-24 11:56:49 -07:00
[JsonProperty("sourcefile", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("sourcefile")]
2020-08-20 14:36:36 -07:00
public string SourceFile { get; set; } = null;
/// <summary>
/// Machine runnable status
/// </summary>
/// <remarks>Also in Logiqx</remarks>
2020-08-24 11:56:49 -07:00
[JsonProperty("runnable", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("runnable")]
public Runnable Runnable { get; set; } = Runnable.NULL;
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool RunnableSpecified { get { return Runnable != Runnable.NULL; } }
2020-08-20 14:36:36 -07:00
#endregion
2020-09-07 22:00:02 -07:00
#region Logiqx
2020-08-20 14:36:36 -07:00
/// <summary>
/// Machine board name
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("board", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("board")]
2020-08-20 14:36:36 -07:00
public string Board { get; set; } = null;
/// <summary>
/// Rebuild location if different than machine name
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("rebuildto", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("rebuildto")]
2020-08-20 14:36:36 -07:00
public string RebuildTo { get; set; } = null;
#endregion
2020-08-24 22:25:47 -07:00
// TODO: Should this be a separate object for TruRip?
2020-09-07 22:00:02 -07:00
#region Logiqx EmuArc
2020-08-20 22:42:04 -07:00
/// <summary>
/// Title ID
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("titleid", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("titleid")]
2020-08-20 22:42:04 -07:00
public string TitleID { get; set; } = null;
/// <summary>
/// Machine developer
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("developer", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("developer")]
2020-08-20 22:42:04 -07:00
public string Developer { get; set; } = null;
/// <summary>
/// Game genre
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("genre", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("genre")]
2020-08-20 22:42:04 -07:00
public string Genre { get; set; } = null;
/// <summary>
/// Game subgenre
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("subgenre", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("subgenre")]
2020-08-20 22:42:04 -07:00
public string Subgenre { get; set; } = null;
/// <summary>
/// Game ratings
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("ratings", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("ratings")]
2020-08-20 22:42:04 -07:00
public string Ratings { get; set; } = null;
/// <summary>
/// Game score
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("score", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("score")]
2020-08-20 22:42:04 -07:00
public string Score { get; set; } = null;
/// <summary>
/// Is the machine enabled
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("enabled", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("enabled")]
2020-08-20 22:42:04 -07:00
public string Enabled { get; set; } = null; // bool?
/// <summary>
/// Does the game have a CRC check
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("hascrc", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("hascrc")]
2020-08-25 22:13:49 -07:00
public bool? Crc { get; set; } = null;
2020-08-20 22:42:04 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool CrcSpecified { get { return Crc != null; } }
2020-08-20 22:42:04 -07:00
/// <summary>
/// Machine relations
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("relatedto", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("relatedto")]
2020-08-20 22:42:04 -07:00
public string RelatedTo { get; set; } = null;
#endregion
2020-09-07 22:00:02 -07:00
#region OpenMSX
/// <summary>
/// Generation MSX ID
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("genmsxid", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("genmsxid")]
public string GenMSXID { get; set; } = null;
/// <summary>
/// MSX System
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("system", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("system")]
public string System { get; set; } = null;
/// <summary>
/// Machine country of origin
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("country", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("country")]
public string Country { get; set; } = null;
#endregion
2020-09-07 22:00:02 -07:00
#region SoftwareList
2020-08-20 14:36:36 -07:00
/// <summary>
/// Support status
/// </summary>
2020-08-24 11:56:49 -07:00
[JsonProperty("supported", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 14:47:27 -07:00
[XmlElement("supported")]
2020-08-22 13:31:13 -07:00
public Supported Supported { get; set; } = Supported.NULL;
2020-08-20 14:36:36 -07:00
2020-09-07 14:47:27 -07:00
[JsonIgnore]
public bool SupportedSpecified { get { return Supported != Supported.NULL; } }
#endregion
2020-09-07 22:00:02 -07:00
#endregion // Fields
2020-08-20 13:17:14 -07:00
#region Accessors
2020-08-21 10:16:05 -07:00
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
public void SetFields(Dictionary<Field, string> mappings)
{
#region Common
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Name))
Name = mappings[Field.Machine_Name];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Comment))
Comment = mappings[Field.Machine_Comment];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Description))
Description = mappings[Field.Machine_Description];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Year))
Year = mappings[Field.Machine_Year];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Manufacturer))
Manufacturer = mappings[Field.Machine_Manufacturer];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Publisher))
Publisher = mappings[Field.Machine_Publisher];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Category))
Category = mappings[Field.Machine_Category];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_RomOf))
RomOf = mappings[Field.Machine_RomOf];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_CloneOf))
CloneOf = mappings[Field.Machine_CloneOf];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_SampleOf))
SampleOf = mappings[Field.Machine_SampleOf];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Type))
MachineType = mappings[Field.Machine_Type].AsMachineType();
2020-08-21 10:16:05 -07:00
#endregion
#region AttractMode
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Players))
Players = mappings[Field.Machine_Players];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Rotation))
Rotation = mappings[Field.Machine_Rotation];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Control))
Control = mappings[Field.Machine_Control];
2020-08-21 10:16:05 -07:00
2020-08-25 11:20:50 -07:00
if (mappings.Keys.Contains(Field.Machine_Status))
Status = mappings[Field.Machine_Status];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_DisplayCount))
DisplayCount = mappings[Field.Machine_DisplayCount];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_DisplayType))
DisplayType = mappings[Field.Machine_DisplayType];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Buttons))
Buttons = mappings[Field.Machine_Buttons];
2020-08-21 10:16:05 -07:00
#endregion
#region ListXML
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_SourceFile))
SourceFile = mappings[Field.Machine_SourceFile];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Runnable))
Runnable = mappings[Field.Machine_Runnable].AsRunnable();
2020-08-21 10:16:05 -07:00
#endregion
#region Logiqx
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Board))
Board = mappings[Field.Machine_Board];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_RebuildTo))
RebuildTo = mappings[Field.Machine_RebuildTo];
2020-08-21 10:16:05 -07:00
#endregion
#region Logiqx EmuArc
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_TitleID))
TitleID = mappings[Field.Machine_TitleID];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Developer))
Developer = mappings[Field.Machine_Developer];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Genre))
Genre = mappings[Field.Machine_Genre];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Subgenre))
Subgenre = mappings[Field.Machine_Subgenre];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Ratings))
Ratings = mappings[Field.Machine_Ratings];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Score))
Score = mappings[Field.Machine_Score];
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Enabled))
Enabled = mappings[Field.Machine_Enabled];
2020-08-21 10:16:05 -07:00
2020-08-25 12:15:28 -07:00
if (mappings.Keys.Contains(Field.Machine_CRC))
2020-08-25 22:13:49 -07:00
Crc = mappings[Field.Machine_CRC].AsYesNo();
2020-08-21 10:16:05 -07:00
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_RelatedTo))
RelatedTo = mappings[Field.Machine_RelatedTo];
2020-08-21 10:16:05 -07:00
#endregion
#region OpenMSX
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_GenMSXID))
GenMSXID = mappings[Field.Machine_GenMSXID];
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_System))
System = mappings[Field.Machine_System];
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Country))
Country = mappings[Field.Machine_Country];
#endregion
2020-08-21 10:16:05 -07:00
#region SoftwareList
2020-08-24 22:25:47 -07:00
if (mappings.Keys.Contains(Field.Machine_Supported))
Supported = mappings[Field.Machine_Supported].AsSupported();
2020-08-21 10:16:05 -07:00
#endregion
}
2020-08-20 13:17:14 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a new Machine object
/// </summary>
public Machine()
{
}
/// <summary>
/// Create a new Machine object with the included information
/// </summary>
/// <param name="name">Name of the machine</param>
/// <param name="description">Description of the machine</param>
public Machine(string name, string description)
{
Name = name;
Description = description;
}
#endregion
#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()
{
#region Common
Name = this.Name,
Comment = this.Comment,
Description = this.Description,
Year = this.Year,
Manufacturer = this.Manufacturer,
Publisher = this.Publisher,
Category = this.Category,
RomOf = this.RomOf,
CloneOf = this.CloneOf,
SampleOf = this.SampleOf,
2020-08-25 22:13:49 -07:00
MachineType = this.MachineType,
2020-08-20 14:36:36 -07:00
#endregion
#region AttractMode
2020-08-20 14:36:36 -07:00
Players = this.Players,
Rotation = this.Rotation,
Control = this.Control,
Status = this.Status,
DisplayCount = this.DisplayCount,
DisplayType = this.DisplayType,
Buttons = this.Buttons,
#endregion
#region ListXML
SourceFile = this.SourceFile,
Runnable = this.Runnable,
2020-08-20 14:36:36 -07:00
#endregion
#region Logiqx
2020-08-20 14:36:36 -07:00
Board = this.Board,
RebuildTo = this.RebuildTo,
#endregion
2020-08-20 22:42:04 -07:00
#region Logiqx EmuArc
TitleID = this.TitleID,
Developer = this.Developer,
Genre = this.Genre,
Subgenre = this.Subgenre,
Ratings = this.Ratings,
Score = this.Score,
Enabled = this.Enabled,
2020-08-25 22:13:49 -07:00
Crc = this.Crc,
2020-08-20 22:42:04 -07:00
RelatedTo = this.RelatedTo,
#endregion
#region OpenMSX
GenMSXID = this.GenMSXID,
System = this.System,
Country = this.Country,
#endregion
#region SoftwareList
2020-08-20 14:36:36 -07:00
Supported = this.Supported,
#endregion
};
}
#endregion
2020-08-20 13:17:14 -07:00
#region Filtering
/// <summary>
/// Check to see if a Machine passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <returns>True if the item passed the filter, false otherwise</returns>
public bool PassesFilter(Filter filter)
{
2020-08-20 14:36:36 -07:00
#region Common
2020-08-25 15:08:38 -07:00
// Machine_Name
2020-09-08 12:59:08 -07:00
bool passes = filter.PassStringFilter(filter.Machine_Name, Name);
2020-08-20 13:17:14 -07:00
if (filter.IncludeOfInGame)
{
2020-09-08 12:59:08 -07:00
passes |= filter.PassStringFilter(filter.Machine_Name, CloneOf);
passes |= filter.PassStringFilter(filter.Machine_Name, RomOf);
2020-08-20 13:17:14 -07:00
}
2020-09-08 12:59:08 -07:00
if (!passes)
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Comment
if (!filter.PassStringFilter(filter.Machine_Comment, Comment))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Description
if (!filter.PassStringFilter(filter.Machine_Description, Description))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Year
if (!filter.PassStringFilter(filter.Machine_Year, Year))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Manufacturer
if (!filter.PassStringFilter(filter.Machine_Manufacturer, Manufacturer))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Publisher
if (!filter.PassStringFilter(filter.Machine_Publisher, Publisher))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Category
if (!filter.PassStringFilter(filter.Machine_Category, Category))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_RomOf
if (!filter.PassStringFilter(filter.Machine_RomOf, RomOf))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_CloneOf
if (!filter.PassStringFilter(filter.Machine_CloneOf, CloneOf))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_SampleOf
if (!filter.PassStringFilter(filter.Machine_SampleOf, SampleOf))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:38:49 -07:00
// Machine_Type
if (filter.Machine_Type.MatchesPositive(0x0, MachineType) == false)
2020-08-25 15:38:49 -07:00
return false;
if (filter.Machine_Type.MatchesNegative(0x0, MachineType) == true)
2020-08-25 15:38:49 -07:00
return false;
2020-08-20 14:36:36 -07:00
#endregion
#region AttractMode
2020-08-25 15:08:38 -07:00
// Machine_Players
if (!filter.PassStringFilter(filter.Machine_Players, Players))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Rotation
if (!filter.PassStringFilter(filter.Machine_Rotation, Rotation))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Control
if (!filter.PassStringFilter(filter.Machine_Control, Control))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Status
if (!filter.PassStringFilter(filter.Machine_Status, Status))
2020-08-20 13:17:14 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_DisplayCount
if (!filter.PassStringFilter(filter.Machine_DisplayCount, DisplayCount))
2020-08-20 14:36:36 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_DisplayType
if (!filter.PassStringFilter(filter.Machine_DisplayType, DisplayType))
2020-08-20 14:36:36 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Buttons
if (!filter.PassStringFilter(filter.Machine_Buttons, Buttons))
2020-08-20 14:36:36 -07:00
return false;
#endregion
#region ListXML
2020-08-25 15:38:49 -07:00
// Machine_SourceFile
if (!filter.PassStringFilter(filter.Machine_SourceFile, SourceFile))
2020-08-20 14:36:36 -07:00
return false;
2020-08-25 15:38:49 -07:00
// Machine_Runnable
2020-08-25 14:11:00 -07:00
if (filter.Machine_Runnable.MatchesPositive(Runnable.NULL, Runnable) == false)
return false;
2020-08-25 14:11:00 -07:00
if (filter.Machine_Runnable.MatchesNegative(Runnable.NULL, Runnable) == true)
2020-08-20 13:17:14 -07:00
return false;
#endregion
2020-08-20 14:36:36 -07:00
#region Logiqx
2020-08-25 15:08:38 -07:00
// Machine_Board
if (!filter.PassStringFilter(filter.Machine_Board, Board))
2020-08-20 14:36:36 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_RebuildTo
if (!filter.PassStringFilter(filter.Machine_RebuildTo, RebuildTo))
2020-08-20 14:36:36 -07:00
return false;
#endregion
2020-08-20 22:42:04 -07:00
#region Logiqx EmuArc
2020-08-25 15:08:38 -07:00
// Machine_TitleID
if (!filter.PassStringFilter(filter.Machine_TitleID, TitleID))
2020-08-20 22:42:04 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Developer
if (!filter.PassStringFilter(filter.Machine_Developer, Developer))
2020-08-20 22:42:04 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Genre
if (!filter.PassStringFilter(filter.Machine_Genre, Genre))
2020-08-20 22:42:04 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Subgenre
if (!filter.PassStringFilter(filter.Machine_Subgenre, Subgenre))
2020-08-20 22:42:04 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Ratings
if (!filter.PassStringFilter(filter.Machine_Ratings, Ratings))
2020-08-20 22:42:04 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Score
if (!filter.PassStringFilter(filter.Machine_Score, Score))
2020-08-20 22:42:04 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_Enabled
if (!filter.PassStringFilter(filter.Machine_Enabled, Enabled))
2020-08-20 22:42:04 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_CRC
if (!filter.PassBoolFilter(filter.Machine_CRC, Crc))
2020-08-20 22:42:04 -07:00
return false;
2020-08-25 15:08:38 -07:00
// Machine_RelatedTo
if (!filter.PassStringFilter(filter.Machine_RelatedTo, RelatedTo))
2020-08-20 22:42:04 -07:00
return false;
#endregion
#region OpenMSX
2020-08-25 15:08:38 -07:00
// Machine_GenMSXID
if (!filter.PassStringFilter(filter.Machine_GenMSXID, GenMSXID))
return false;
2020-08-25 15:08:38 -07:00
// Machine_System
if (!filter.PassStringFilter(filter.Machine_System, System))
return false;
2020-08-25 15:08:38 -07:00
// Machine_Country
if (!filter.PassStringFilter(filter.Machine_Country, Country))
return false;
#endregion
2020-08-20 14:36:36 -07:00
#region SoftwareList
2020-08-25 15:08:38 -07:00
// Machine_Supported
2020-08-25 14:11:00 -07:00
if (filter.Machine_Supported.MatchesPositive(Supported.NULL, Supported) == false)
2020-08-22 13:31:13 -07:00
return false;
2020-08-25 14:11:00 -07:00
if (filter.Machine_Supported.MatchesNegative(Supported.NULL, Supported) == true)
2020-08-20 14:36:36 -07:00
return false;
2020-08-25 15:26:07 -07:00
#endregion // SoftwareList
2020-08-20 13:17:14 -07:00
return true;
}
/// <summary>
/// Remove fields from the Machine
/// </summary>
/// <param name="fields">List of Fields to remove</param>
public void RemoveFields(List<Field> fields)
{
2020-08-20 14:36:36 -07:00
#region Common
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Name))
2020-08-20 13:17:14 -07:00
Name = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Comment))
2020-08-20 13:17:14 -07:00
Comment = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Description))
2020-08-20 13:17:14 -07:00
Description = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Year))
2020-08-20 13:17:14 -07:00
Year = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Manufacturer))
2020-08-20 13:17:14 -07:00
Manufacturer = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Publisher))
2020-08-20 13:17:14 -07:00
Publisher = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Category))
2020-08-20 13:17:14 -07:00
Category = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_RomOf))
2020-08-20 13:17:14 -07:00
RomOf = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_CloneOf))
2020-08-20 13:17:14 -07:00
CloneOf = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_SampleOf))
2020-08-20 13:17:14 -07:00
SampleOf = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Type))
MachineType = 0x0;
2020-08-20 14:36:36 -07:00
#endregion
#region AttractMode
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Players))
2020-08-20 14:36:36 -07:00
Players = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Rotation))
2020-08-20 14:36:36 -07:00
Rotation = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Control))
2020-08-20 14:36:36 -07:00
Control = null;
2020-08-25 11:20:50 -07:00
if (fields.Contains(Field.Machine_Status))
2020-08-20 14:36:36 -07:00
Status = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_DisplayCount))
2020-08-20 14:36:36 -07:00
DisplayCount = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_DisplayType))
2020-08-20 14:36:36 -07:00
DisplayType = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Buttons))
2020-08-20 14:36:36 -07:00
Buttons = null;
#endregion
#region ListXML
2020-08-20 13:17:14 -07:00
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_SourceFile))
2020-08-20 13:17:14 -07:00
SourceFile = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Runnable))
Runnable = Runnable.NULL;
2020-08-20 13:17:14 -07:00
2020-08-20 14:36:36 -07:00
#endregion
#region Logiqx
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Board))
2020-08-20 14:36:36 -07:00
Board = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_RebuildTo))
2020-08-20 14:36:36 -07:00
RebuildTo = null;
#endregion
2020-08-20 22:42:04 -07:00
#region Logiqx EmuArc
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_TitleID))
2020-08-20 22:42:04 -07:00
TitleID = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Developer))
2020-08-20 22:42:04 -07:00
Developer = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Genre))
2020-08-20 22:42:04 -07:00
Genre = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Subgenre))
2020-08-20 22:42:04 -07:00
Subgenre = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Ratings))
2020-08-20 22:42:04 -07:00
Ratings = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Score))
2020-08-20 22:42:04 -07:00
Score = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Enabled))
2020-08-20 22:42:04 -07:00
Enabled = null;
2020-08-25 12:15:28 -07:00
if (fields.Contains(Field.Machine_CRC))
2020-08-25 22:13:49 -07:00
Crc = null;
2020-08-20 22:42:04 -07:00
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_RelatedTo))
2020-08-20 22:42:04 -07:00
RelatedTo = null;
#endregion
#region OpenMSX
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_GenMSXID))
GenMSXID = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_System))
System = null;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Country))
Country = null;
#endregion
2020-08-20 14:36:36 -07:00
#region SoftwareList
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Supported))
2020-08-22 13:31:13 -07:00
Supported = Supported.NULL;
2020-08-20 14:36:36 -07:00
#endregion
2020-08-20 13:17:14 -07:00
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace machine fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param>
/// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, false otherwise</param>
public void ReplaceFields(Machine machine, List<Field> fields, bool onlySame)
{
2020-08-20 14:36:36 -07:00
#region Common
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Name))
2020-08-20 13:17:14 -07:00
Name = machine.Name;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Comment))
2020-08-20 13:17:14 -07:00
Comment = machine.Comment;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Description))
2020-08-20 13:17:14 -07:00
{
if (!onlySame || (onlySame && Name == Description))
Description = machine.Description;
}
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Year))
2020-08-20 13:17:14 -07:00
Year = machine.Year;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Manufacturer))
2020-08-20 13:17:14 -07:00
Manufacturer = machine.Manufacturer;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Publisher))
2020-08-20 13:17:14 -07:00
Publisher = machine.Publisher;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Category))
2020-08-20 13:17:14 -07:00
Category = machine.Category;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_RomOf))
2020-08-20 13:17:14 -07:00
RomOf = machine.RomOf;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_CloneOf))
2020-08-20 13:17:14 -07:00
CloneOf = machine.CloneOf;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_SampleOf))
2020-08-20 13:17:14 -07:00
SampleOf = machine.SampleOf;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Type))
MachineType = machine.MachineType;
2020-08-20 14:36:36 -07:00
#endregion
#region AttractMode
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Players))
2020-08-20 14:36:36 -07:00
Players = machine.Players;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Rotation))
2020-08-20 14:36:36 -07:00
Rotation = machine.Rotation;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Control))
2020-08-20 14:36:36 -07:00
Control = machine.Control;
2020-08-25 11:20:50 -07:00
if (fields.Contains(Field.Machine_Status))
2020-08-20 14:36:36 -07:00
Status = machine.Status;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_DisplayCount))
2020-08-20 14:36:36 -07:00
DisplayCount = machine.DisplayCount;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_DisplayType))
2020-08-20 14:36:36 -07:00
DisplayType = machine.DisplayType;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Buttons))
2020-08-20 14:36:36 -07:00
Buttons = machine.Buttons;
#endregion
#region ListXML
2020-08-20 13:17:14 -07:00
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_SourceFile))
2020-08-20 13:17:14 -07:00
SourceFile = machine.SourceFile;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Runnable))
2020-08-20 13:17:14 -07:00
Runnable = machine.Runnable;
2020-08-20 14:36:36 -07:00
#endregion
#region Logiqx
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Board))
2020-08-20 14:36:36 -07:00
Board = machine.Board;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_RebuildTo))
2020-08-20 14:36:36 -07:00
RebuildTo = machine.RebuildTo;
#endregion
2020-08-20 22:42:04 -07:00
#region Logiqx EmuArc
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_TitleID))
2020-08-20 22:42:04 -07:00
TitleID = machine.TitleID;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Developer))
2020-08-20 22:42:04 -07:00
Developer = machine.Developer;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Genre))
2020-08-20 22:42:04 -07:00
Genre = machine.Genre;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Subgenre))
2020-08-20 22:42:04 -07:00
Subgenre = machine.Subgenre;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Ratings))
2020-08-20 22:42:04 -07:00
Ratings = machine.Ratings;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Score))
2020-08-20 22:42:04 -07:00
Score = machine.Score;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Enabled))
2020-08-20 22:42:04 -07:00
Enabled = machine.Enabled;
2020-08-25 12:15:28 -07:00
if (fields.Contains(Field.Machine_CRC))
2020-08-25 22:13:49 -07:00
Crc = machine.Crc;
2020-08-20 22:42:04 -07:00
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_RelatedTo))
2020-08-20 22:42:04 -07:00
RelatedTo = machine.RelatedTo;
#endregion
#region OpenMSX
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_GenMSXID))
GenMSXID = machine.GenMSXID;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_System))
System = machine.System;
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Country))
Country = machine.Country;
#endregion
2020-08-20 14:36:36 -07:00
#region SoftwareList
2020-08-24 22:25:47 -07:00
if (fields.Contains(Field.Machine_Supported))
2020-08-20 14:36:36 -07:00
Supported = machine.Supported;
#endregion
2020-08-20 13:17:14 -07:00
}
#endregion
}
}