From 5b89d382a7bfae4bab0ce46e4e61df1178107748 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 14 Aug 2023 15:12:26 -0400 Subject: [PATCH] Use internal models for Machine --- SabreTools.DatItems/Machine.cs | 262 ++++++++++++++++++++++----------- 1 file changed, 177 insertions(+), 85 deletions(-) diff --git a/SabreTools.DatItems/Machine.cs b/SabreTools.DatItems/Machine.cs index 8f7affb9..8c92817e 100644 --- a/SabreTools.DatItems/Machine.cs +++ b/SabreTools.DatItems/Machine.cs @@ -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 /// [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; + } /// /// Additional notes @@ -30,63 +34,99 @@ namespace SabreTools.DatItems /// Known as "Extra" in AttractMode [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; + } /// /// Extended description /// [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; + } /// /// Year(s) of release/manufacture /// [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; + } /// /// Manufacturer, if available /// [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; + } /// /// Publisher, if available /// [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; + } /// /// Category, if available /// [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; + } /// /// fomof parent /// [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; + } /// /// cloneof parent /// [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; + } /// /// sampleof parent /// [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; + } /// /// 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 /// Also in Logiqx EmuArc [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; + } /// /// Screen rotation /// [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; + } /// /// Control method /// [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; + } /// /// Support status /// [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; + } /// /// Display count /// [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; + } /// /// Display type /// [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; + } /// /// Number of input buttons /// [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 /// [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; + } /// /// Emulator source file related to the machine @@ -170,7 +269,11 @@ namespace SabreTools.DatItems /// Also in Logiqx [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; + } /// /// Machine runnable status @@ -178,7 +281,11 @@ namespace SabreTools.DatItems /// Also in Logiqx [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 /// [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; + } /// /// Rebuild location if different than machine name /// [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; + } /// /// No-Intro ID for the game /// [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; + } /// /// No-Intro ID for the game /// [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 /// [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; + } /// /// MSX System /// [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; + } /// /// Machine country of origin /// [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 /// [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 + /// + /// Internal Machine model + /// + [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 }; }