Use internal models for Machine

This commit is contained in:
Matt Nadareski
2023-08-14 15:12:26 -04:00
parent 59dd9e8d26
commit 5b89d382a7

View File

@@ -1,9 +1,9 @@
using System;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SabreTools.Core;
using SabreTools.Core.Tools;
namespace SabreTools.DatItems
{
@@ -22,7 +22,11 @@ namespace SabreTools.DatItems
/// </summary>
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Include)]
[XmlElement("name")]
public string? Name { get; set; } = null;
public string? Name
{
get => _machine.ReadString(Models.Internal.Machine.NameKey);
set => _machine[Models.Internal.Machine.NameKey] = value;
}
/// <summary>
/// Additional notes
@@ -30,63 +34,99 @@ namespace SabreTools.DatItems
/// <remarks>Known as "Extra" in AttractMode</remarks>
[JsonProperty("comment", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("comment")]
public string? Comment { get; set; } = null;
public string? Comment
{
get => _machine.ReadString(Models.Internal.Machine.CommentKey);
set => _machine[Models.Internal.Machine.CommentKey] = value;
}
/// <summary>
/// Extended description
/// </summary>
[JsonProperty("description", DefaultValueHandling = DefaultValueHandling.Include)]
[XmlElement("description")]
public string? Description { get; set; } = null;
public string? Description
{
get => _machine.ReadString(Models.Internal.Machine.DescriptionKey);
set => _machine[Models.Internal.Machine.DescriptionKey] = value;
}
/// <summary>
/// Year(s) of release/manufacture
/// </summary>
[JsonProperty("year", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("year")]
public string? Year { get; set; } = null;
public string? Year
{
get => _machine.ReadString(Models.Internal.Machine.YearKey);
set => _machine[Models.Internal.Machine.YearKey] = value;
}
/// <summary>
/// Manufacturer, if available
/// </summary>
[JsonProperty("manufacturer", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("manufacturer")]
public string? Manufacturer { get; set; } = null;
public string? Manufacturer
{
get => _machine.ReadString(Models.Internal.Machine.ManufacturerKey);
set => _machine[Models.Internal.Machine.ManufacturerKey] = value;
}
/// <summary>
/// Publisher, if available
/// </summary>
[JsonProperty("publisher", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("publisher")]
public string? Publisher { get; set; } = null;
public string? Publisher
{
get => _machine.ReadString(Models.Internal.Machine.PublisherKey);
set => _machine[Models.Internal.Machine.PublisherKey] = value;
}
/// <summary>
/// Category, if available
/// </summary>
[JsonProperty("category", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("category")]
public string? Category { get; set; } = null;
public string? Category
{
get => _machine.ReadString(Models.Internal.Machine.CategoryKey);
set => _machine[Models.Internal.Machine.CategoryKey] = value;
}
/// <summary>
/// fomof parent
/// </summary>
[JsonProperty("romof", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("romof")]
public string? RomOf { get; set; } = null;
public string? RomOf
{
get => _machine.ReadString(Models.Internal.Machine.RomOfKey);
set => _machine[Models.Internal.Machine.RomOfKey] = value;
}
/// <summary>
/// cloneof parent
/// </summary>
[JsonProperty("cloneof", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("cloneof")]
public string? CloneOf { get; set; } = null;
public string? CloneOf
{
get => _machine.ReadString(Models.Internal.Machine.CloneOfKey);
set => _machine[Models.Internal.Machine.CloneOfKey] = value;
}
/// <summary>
/// sampleof parent
/// </summary>
[JsonProperty("sampleof", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sampleof")]
public string? SampleOf { get; set; } = null;
public string? SampleOf
{
get => _machine.ReadString(Models.Internal.Machine.SampleOfKey);
set => _machine[Models.Internal.Machine.SampleOfKey] = value;
}
/// <summary>
/// Type of the machine
@@ -94,7 +134,34 @@ namespace SabreTools.DatItems
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("type")]
public MachineType MachineType { get; set; } = 0x0;
public MachineType MachineType
{
get
{
bool? isBios = _machine.ReadBool(Models.Internal.Machine.IsBiosKey);
bool? isDevice = _machine.ReadBool(Models.Internal.Machine.IsDeviceKey);
bool? isMechanical = _machine.ReadBool(Models.Internal.Machine.IsMechanicalKey);
MachineType machineType = MachineType.None;
if (isBios == true)
machineType |= MachineType.Bios;
if (isDevice == true)
machineType |= MachineType.Device;
if (isMechanical == true)
machineType |= MachineType.Mechanical;
return machineType;
}
set
{
if (value.HasFlag(MachineType.Bios))
_machine[Models.Internal.Machine.IsBiosKey] = "yes";
if (value.HasFlag(MachineType.Device))
_machine[Models.Internal.Machine.IsDeviceKey] = "yes";
if (value.HasFlag(MachineType.Mechanical))
_machine[Models.Internal.Machine.IsMechanicalKey] = "yes";
}
}
[JsonIgnore]
public bool MachineTypeSpecified { get { return MachineType != 0x0 && MachineType != MachineType.None; } }
@@ -109,49 +176,77 @@ namespace SabreTools.DatItems
/// <remarks>Also in Logiqx EmuArc</remarks>
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("players")]
public string? Players { get; set; } = null;
public string? Players
{
get => _machine.ReadString(Models.Internal.Machine.PlayersKey);
set => _machine[Models.Internal.Machine.PlayersKey] = value;
}
/// <summary>
/// Screen rotation
/// </summary>
[JsonProperty("rotation", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("rotation")]
public string? Rotation { get; set; } = null;
public string? Rotation
{
get => _machine.ReadString(Models.Internal.Machine.RotationKey);
set => _machine[Models.Internal.Machine.RotationKey] = value;
}
/// <summary>
/// Control method
/// </summary>
[JsonProperty("control", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("control")]
public string? Control { get; set; } = null;
public string? Control
{
get => _machine.ReadString(Models.Internal.Machine.ControlKey);
set => _machine[Models.Internal.Machine.ControlKey] = value;
}
/// <summary>
/// Support status
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("status")]
public string? Status { get; set; } = null;
public string? Status
{
get => _machine.ReadString(Models.Internal.Machine.StatusKey);
set => _machine[Models.Internal.Machine.StatusKey] = value;
}
/// <summary>
/// Display count
/// </summary>
[JsonProperty("displaycount", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("displaycount")]
public string? DisplayCount { get; set; } = null;
public string? DisplayCount
{
get => _machine.ReadString(Models.Internal.Machine.DisplayCountKey);
set => _machine[Models.Internal.Machine.DisplayCountKey] = value;
}
/// <summary>
/// Display type
/// </summary>
[JsonProperty("displaytype", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("displaytype")]
public string? DisplayType { get; set; } = null;
public string? DisplayType
{
get => _machine.ReadString(Models.Internal.Machine.DisplayTypeKey);
set => _machine[Models.Internal.Machine.DisplayTypeKey] = value;
}
/// <summary>
/// Number of input buttons
/// </summary>
[JsonProperty("buttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("buttons")]
public string? Buttons { get; set; } = null;
public string? Buttons
{
get => _machine.ReadString(Models.Internal.Machine.ButtonsKey);
set => _machine[Models.Internal.Machine.ButtonsKey] = value;
}
#endregion
@@ -162,7 +257,11 @@ namespace SabreTools.DatItems
/// </summary>
[JsonProperty("history", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("history")]
public string? History { get; set; } = null;
public string? History
{
get => _machine.ReadString(Models.Internal.Machine.HistoryKey);
set => _machine[Models.Internal.Machine.HistoryKey] = value;
}
/// <summary>
/// Emulator source file related to the machine
@@ -170,7 +269,11 @@ namespace SabreTools.DatItems
/// <remarks>Also in Logiqx</remarks>
[JsonProperty("sourcefile", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sourcefile")]
public string? SourceFile { get; set; } = null;
public string? SourceFile
{
get => _machine.ReadString(Models.Internal.Machine.SourceFileKey);
set => _machine[Models.Internal.Machine.SourceFileKey] = value;
}
/// <summary>
/// Machine runnable status
@@ -178,7 +281,11 @@ namespace SabreTools.DatItems
/// <remarks>Also in Logiqx</remarks>
[JsonProperty("runnable", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("runnable")]
public Runnable Runnable { get; set; } = Runnable.NULL;
public Runnable Runnable
{
get => _machine.ReadString(Models.Internal.Machine.RunnableKey).AsRunnable();
set => _machine[Models.Internal.Machine.RunnableKey] = value.FromRunnable();
}
[JsonIgnore]
public bool RunnableSpecified { get { return Runnable != Runnable.NULL; } }
@@ -192,28 +299,44 @@ namespace SabreTools.DatItems
/// </summary>
[JsonProperty("board", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("board")]
public string? Board { get; set; } = null;
public string? Board
{
get => _machine.ReadString(Models.Internal.Machine.BoardKey);
set => _machine[Models.Internal.Machine.BoardKey] = value;
}
/// <summary>
/// Rebuild location if different than machine name
/// </summary>
[JsonProperty("rebuildto", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("rebuildto")]
public string? RebuildTo { get; set; } = null;
public string? RebuildTo
{
get => _machine.ReadString(Models.Internal.Machine.RebuildToKey);
set => _machine[Models.Internal.Machine.RebuildToKey] = value;
}
/// <summary>
/// No-Intro ID for the game
/// </summary>
[JsonProperty("nointroid", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("nointroid")]
public string? NoIntroId { get; set; } = null;
public string? NoIntroId
{
get => _machine.ReadString(Models.Internal.Machine.IdKey);
set => _machine[Models.Internal.Machine.IdKey] = value;
}
/// <summary>
/// No-Intro ID for the game
/// </summary>
[JsonProperty("nointrocloneofid", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("nointrocloneofid")]
public string? NoIntroCloneOfId { get; set; } = null;
public string? NoIntroCloneOfId
{
get => _machine.ReadString(Models.Internal.Machine.CloneOfIdKey);
set => _machine[Models.Internal.Machine.CloneOfIdKey] = value;
}
#endregion
@@ -295,21 +418,33 @@ namespace SabreTools.DatItems
/// </summary>
[JsonProperty("genmsxid", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("genmsxid")]
public string? GenMSXID { get; set; } = null;
public string? GenMSXID
{
get => _machine.ReadString(Models.Internal.Machine.GenMSXIDKey);
set => _machine[Models.Internal.Machine.GenMSXIDKey] = value;
}
/// <summary>
/// MSX System
/// </summary>
[JsonProperty("system", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("system")]
public string? System { get; set; } = null;
public string? System
{
get => _machine.ReadString(Models.Internal.Machine.SystemKey);
set => _machine[Models.Internal.Machine.SystemKey] = value;
}
/// <summary>
/// Machine country of origin
/// </summary>
[JsonProperty("country", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("country")]
public string? Country { get; set; } = null;
public string? Country
{
get => _machine.ReadString(Models.Internal.Machine.CountryKey);
set => _machine[Models.Internal.Machine.CountryKey] = value;
}
#endregion
@@ -320,13 +455,23 @@ namespace SabreTools.DatItems
/// </summary>
[JsonProperty("supported", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("supported")]
public Supported Supported { get; set; } = Supported.NULL;
public Supported Supported
{
get => _machine.ReadString(Models.Internal.Machine.SupportedKey).AsSupported();
set => _machine[Models.Internal.Machine.SupportedKey] = value.FromSupported(verbose: true);
}
[JsonIgnore]
public bool SupportedSpecified { get { return Supported != Supported.NULL; } }
#endregion
/// <summary>
/// Internal Machine model
/// </summary>
[JsonIgnore]
private Models.Internal.Machine _machine = new();
#endregion // Fields
#region Constructors
@@ -363,46 +508,7 @@ namespace SabreTools.DatItems
{
#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,
MachineType = this.MachineType,
#endregion
#region AttractMode
Players = this.Players,
Rotation = this.Rotation,
Control = this.Control,
Status = this.Status,
DisplayCount = this.DisplayCount,
DisplayType = this.DisplayType,
Buttons = this.Buttons,
#endregion
#region ListXML
History = this.History,
SourceFile = this.SourceFile,
Runnable = this.Runnable,
#endregion
#region Logiqx
Board = this.Board,
RebuildTo = this.RebuildTo,
NoIntroId = this.NoIntroId,
NoIntroCloneOfId = this.NoIntroCloneOfId,
_machine = this._machine.Clone() as Models.Internal.Machine ?? new Models.Internal.Machine(),
#endregion
@@ -419,20 +525,6 @@ namespace SabreTools.DatItems
RelatedTo = this.RelatedTo,
#endregion
#region OpenMSX
GenMSXID = this.GenMSXID,
System = this.System,
Country = this.Country,
#endregion
#region SoftwareList
Supported = this.Supported,
#endregion
};
}