diff --git a/SabreTools.Models/Internal/Machine.cs b/SabreTools.Models/Internal/Machine.cs
index 8502477c..6da26f2c 100644
--- a/SabreTools.Models/Internal/Machine.cs
+++ b/SabreTools.Models/Internal/Machine.cs
@@ -228,6 +228,7 @@ namespace SabreTools.Models.Internal
/// string
public const string TagsKey = "tags";
+ /// TODO: This needs an internal model OR mapping to fields
/// Trurip
public const string TruripKey = "trurip";
@@ -289,6 +290,18 @@ namespace SabreTools.Models.Internal
return this[key] as string;
}
+ ///
+ /// Read a key as a string[], returning null on error
+ ///
+ public string[]? ReadStringArray(string key)
+ {
+ if (string.IsNullOrWhiteSpace(key))
+ return null;
+ if (!ContainsKey(key))
+ return null;
+ return this[key] as string[];
+ }
+
#endregion
}
}
\ No newline at end of file
diff --git a/SabreTools.Models/Logiqx/GameBase.cs b/SabreTools.Models/Logiqx/GameBase.cs
index c4335e66..b6ce477e 100644
--- a/SabreTools.Models/Logiqx/GameBase.cs
+++ b/SabreTools.Models/Logiqx/GameBase.cs
@@ -102,6 +102,7 @@ namespace SabreTools.Models.Logiqx
[XmlElement("archive")]
public Archive[]? Archive { get; set; }
+ /// TODO: Validate multiple can exist
/// MAME extension
[XmlElement("driver")]
public Driver[]? Driver { get; set; }
diff --git a/SabreTools.Serialization/Internal.ClrMamePro.cs b/SabreTools.Serialization/Internal.ClrMamePro.cs
index 5ec0525a..237c1a9b 100644
--- a/SabreTools.Serialization/Internal.ClrMamePro.cs
+++ b/SabreTools.Serialization/Internal.ClrMamePro.cs
@@ -118,12 +118,12 @@ namespace SabreTools.Serialization
if (item.DipSwitch != null && item.DipSwitch.Any())
{
- var dipSwitchs = new List();
+ var dipSwitches = new List();
foreach (var dipSwitch in item.DipSwitch)
{
- dipSwitchs.Add(ConvertFromClrMamePro(dipSwitch));
+ dipSwitches.Add(ConvertFromClrMamePro(dipSwitch));
}
- machine[Models.Internal.Machine.DipSwitchKey] = dipSwitchs.ToArray();
+ machine[Models.Internal.Machine.DipSwitchKey] = dipSwitches.ToArray();
}
if (item.Driver != null)
@@ -452,10 +452,10 @@ namespace SabreTools.Serialization
if (item.ContainsKey(Models.Internal.Machine.InputKey) && item[Models.Internal.Machine.InputKey] is Models.Internal.Input input)
gameBase.Input = ConvertToClrMamePro(input);
- if (item.ContainsKey(Models.Internal.Machine.DipSwitchKey) && item[Models.Internal.Machine.DipSwitchKey] is Models.Internal.DipSwitch[] dipSwitchs)
+ if (item.ContainsKey(Models.Internal.Machine.DipSwitchKey) && item[Models.Internal.Machine.DipSwitchKey] is Models.Internal.DipSwitch[] dipSwitches)
{
var dipSwitchItems = new List();
- foreach (var dipSwitch in dipSwitchs)
+ foreach (var dipSwitch in dipSwitches)
{
dipSwitchItems.Add(ConvertToClrMamePro(dipSwitch));
}
diff --git a/SabreTools.Serialization/Internal.Logiqx.cs b/SabreTools.Serialization/Internal.Logiqx.cs
index 848a3a02..1a448f70 100644
--- a/SabreTools.Serialization/Internal.Logiqx.cs
+++ b/SabreTools.Serialization/Internal.Logiqx.cs
@@ -1,3 +1,6 @@
+using System.Collections.Generic;
+using System.Linq;
+
namespace SabreTools.Serialization
{
///
@@ -7,6 +10,138 @@ namespace SabreTools.Serialization
{
#region Serialize
+ ///
+ /// Convert from to
+ ///
+ public static Models.Internal.Machine ConvertMachineFromLogiqx(Models.Logiqx.GameBase item)
+ {
+ var machine = new Models.Internal.Machine
+ {
+ [Models.Internal.Machine.NameKey] = item.Name,
+ [Models.Internal.Machine.SourceFileKey] = item.SourceFile,
+ [Models.Internal.Machine.IsBiosKey] = item.IsBios,
+ [Models.Internal.Machine.IsDeviceKey] = item.IsDevice,
+ [Models.Internal.Machine.IsMechanicalKey] = item.IsMechanical,
+ [Models.Internal.Machine.CloneOfKey] = item.CloneOf,
+ [Models.Internal.Machine.RomOfKey] = item.RomOf,
+ [Models.Internal.Machine.SampleOfKey] = item.SampleOf,
+ [Models.Internal.Machine.BoardKey] = item.Board,
+ [Models.Internal.Machine.RebuildToKey] = item.RebuildTo,
+ [Models.Internal.Machine.IdKey] = item.Id,
+ [Models.Internal.Machine.CloneOfIdKey] = item.CloneOfId,
+ [Models.Internal.Machine.RunnableKey] = item.Runnable,
+ [Models.Internal.Machine.CommentKey] = item.Comment,
+ [Models.Internal.Machine.DescriptionKey] = item.Description,
+ [Models.Internal.Machine.YearKey] = item.Year,
+ [Models.Internal.Machine.ManufacturerKey] = item.Manufacturer,
+ [Models.Internal.Machine.PublisherKey] = item.Publisher,
+ [Models.Internal.Machine.CategoryKey] = item.Category,
+ [Models.Internal.Machine.TruripKey] = item.Trurip,
+ };
+
+ if (item.Release != null && item.Release.Any())
+ {
+ var releases = new List();
+ foreach (var release in item.Release)
+ {
+ releases.Add(ConvertFromLogiqx(release));
+ }
+ machine[Models.Internal.Machine.ReleaseKey] = releases.ToArray();
+ }
+
+ if (item.BiosSet != null && item.BiosSet.Any())
+ {
+ var biosSets = new List();
+ foreach (var biosSet in item.BiosSet)
+ {
+ biosSets.Add(ConvertFromLogiqx(biosSet));
+ }
+ machine[Models.Internal.Machine.BiosSetKey] = biosSets.ToArray();
+ }
+
+ if (item.Rom != null && item.Rom.Any())
+ {
+ var roms = new List();
+ foreach (var rom in item.Rom)
+ {
+ roms.Add(ConvertFromLogiqx(rom));
+ }
+ machine[Models.Internal.Machine.RomKey] = roms.ToArray();
+ }
+
+ if (item.Disk != null && item.Disk.Any())
+ {
+ var disks = new List();
+ foreach (var disk in item.Disk)
+ {
+ disks.Add(ConvertFromLogiqx(disk));
+ }
+ machine[Models.Internal.Machine.DiskKey] = disks.ToArray();
+ }
+
+ if (item.Media != null && item.Media.Any())
+ {
+ var medias = new List();
+ foreach (var media in item.Media)
+ {
+ medias.Add(ConvertFromLogiqx(media));
+ }
+ machine[Models.Internal.Machine.MediaKey] = medias.ToArray();
+ }
+
+ if (item.DeviceRef != null && item.DeviceRef.Any())
+ {
+ var deviceRefs = new List();
+ foreach (var deviceRef in item.DeviceRef)
+ {
+ deviceRefs.Add(ConvertFromLogiqx(deviceRef));
+ }
+ machine[Models.Internal.Machine.DeviceRefKey] = deviceRefs.ToArray();
+ }
+
+ if (item.Sample != null && item.Sample.Any())
+ {
+ var samples = new List();
+ foreach (var sample in item.Sample)
+ {
+ samples.Add(ConvertFromLogiqx(sample));
+ }
+ machine[Models.Internal.Machine.SampleKey] = samples.ToArray();
+ }
+
+ if (item.Archive != null && item.Archive.Any())
+ {
+ var archives = new List();
+ foreach (var archive in item.Archive)
+ {
+ archives.Add(ConvertFromLogiqx(archive));
+ }
+ machine[Models.Internal.Machine.ArchiveKey] = archives.ToArray();
+ }
+
+ if (item.Driver != null && item.Driver.Any())
+ {
+ var drivers = new List();
+ foreach (var driver in item.Driver)
+ {
+ drivers.Add(ConvertFromLogiqx(driver));
+ }
+ machine[Models.Internal.Machine.DriverKey] = drivers.ToArray();
+ }
+
+ if (item.SoftwareList != null && item.SoftwareList.Any())
+ {
+ var softwareLists = new List();
+ foreach (var softwareList in item.SoftwareList)
+ {
+ softwareLists.Add(ConvertFromLogiqx(softwareList));
+ }
+ machine[Models.Internal.Machine.SoftwareListKey] = softwareLists.ToArray();
+ }
+
+ return machine;
+ }
+
///
/// Convert from to
///
@@ -171,7 +306,140 @@ namespace SabreTools.Serialization
#endregion
- #region Logiqx
+ #region Deserialize
+
+ ///
+ /// Convert from to
+ ///
+ public static Models.Logiqx.GameBase ConvertMachineToLogiqx(Models.Internal.Machine item, bool game = false)
+ {
+ Models.Logiqx.GameBase gameBase = game ? new Models.Logiqx.Game() : new Models.Logiqx.Machine();
+
+ gameBase.Name = item.ReadString(Models.Internal.Machine.NameKey);
+ gameBase.SourceFile = item.ReadString(Models.Internal.Machine.SourceFileKey);
+ gameBase.IsBios = item.ReadString(Models.Internal.Machine.IsBiosKey);
+ gameBase.IsDevice = item.ReadString(Models.Internal.Machine.IsDeviceKey);
+ gameBase.IsMechanical = item.ReadString(Models.Internal.Machine.IsMechanicalKey);
+ gameBase.CloneOf = item.ReadString(Models.Internal.Machine.CloneOfKey);
+ gameBase.RomOf = item.ReadString(Models.Internal.Machine.RomOfKey);
+ gameBase.SampleOf = item.ReadString(Models.Internal.Machine.SampleOfKey);
+ gameBase.Board = item.ReadString(Models.Internal.Machine.BoardKey);
+ gameBase.RebuildTo = item.ReadString(Models.Internal.Machine.RebuildToKey);
+ gameBase.Id = item.ReadString(Models.Internal.Machine.IdKey);
+ gameBase.CloneOfId = item.ReadString(Models.Internal.Machine.CloneOfIdKey);
+ gameBase.Runnable = item.ReadString(Models.Internal.Machine.RunnableKey);
+ gameBase.Comment = item.ReadStringArray(Models.Internal.Machine.CommentKey);
+ gameBase.Description = item.ReadString(Models.Internal.Machine.DescriptionKey);
+ gameBase.Year = item.ReadString(Models.Internal.Machine.YearKey);
+ gameBase.Manufacturer = item.ReadString(Models.Internal.Machine.ManufacturerKey);
+ gameBase.Publisher = item.ReadString(Models.Internal.Machine.PublisherKey);
+ gameBase.Category = item.ReadStringArray(Models.Internal.Machine.CategoryKey);
+
+ if (item.ContainsKey(Models.Internal.Machine.TruripKey) && item[Models.Internal.Machine.TruripKey] is Models.Logiqx.Trurip trurip)
+ gameBase.Trurip = trurip;
+
+ if (item.ContainsKey(Models.Internal.Machine.ReleaseKey) && item[Models.Internal.Machine.ReleaseKey] is Models.Internal.Release[] releases)
+ {
+ var releaseItems = new List();
+ foreach (var release in releases)
+ {
+ releaseItems.Add(ConvertToLogiqx(release));
+ }
+ gameBase.Release = releaseItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.BiosSetKey) && item[Models.Internal.Machine.BiosSetKey] is Models.Internal.BiosSet[] biosSets)
+ {
+ var biosSetItems = new List();
+ foreach (var biosSet in biosSets)
+ {
+ biosSetItems.Add(ConvertToLogiqx(biosSet));
+ }
+ gameBase.BiosSet = biosSetItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
+ {
+ var romItems = new List();
+ foreach (var rom in roms)
+ {
+ romItems.Add(ConvertToLogiqx(rom));
+ }
+ gameBase.Rom = romItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.DiskKey) && item[Models.Internal.Machine.DiskKey] is Models.Internal.Disk[] disks)
+ {
+ var diskItems = new List();
+ foreach (var disk in disks)
+ {
+ diskItems.Add(ConvertToLogiqx(disk));
+ }
+ gameBase.Disk = diskItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.MediaKey) && item[Models.Internal.Machine.MediaKey] is Models.Internal.Media[] medias)
+ {
+ var mediaItems = new List();
+ foreach (var media in medias)
+ {
+ mediaItems.Add(ConvertToLogiqx(media));
+ }
+ gameBase.Media = mediaItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.DeviceRefKey) && item[Models.Internal.Machine.DeviceRefKey] is Models.Internal.DeviceRef[] deviceRefs)
+ {
+ var deviceRefItems = new List();
+ foreach (var deviceRef in deviceRefs)
+ {
+ deviceRefItems.Add(ConvertToLogiqx(deviceRef));
+ }
+ gameBase.DeviceRef = deviceRefItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.SampleKey) && item[Models.Internal.Machine.SampleKey] is Models.Internal.Sample[] samples)
+ {
+ var sampleItems = new List();
+ foreach (var sample in samples)
+ {
+ sampleItems.Add(ConvertToLogiqx(sample));
+ }
+ gameBase.Sample = sampleItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.ArchiveKey) && item[Models.Internal.Machine.ArchiveKey] is Models.Internal.Archive[] archives)
+ {
+ var archiveItems = new List();
+ foreach (var archive in archives)
+ {
+ archiveItems.Add(ConvertToLogiqx(archive));
+ }
+ gameBase.Archive = archiveItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.DriverKey) && item[Models.Internal.Machine.DriverKey] is Models.Internal.Driver[] drivers)
+ {
+ var driverItems = new List();
+ foreach (var chip in drivers)
+ {
+ driverItems.Add(ConvertToLogiqx(chip));
+ }
+ gameBase.Driver = driverItems.ToArray();
+ }
+
+ if (item.ContainsKey(Models.Internal.Machine.SoftwareListKey) && item[Models.Internal.Machine.SoftwareListKey] is Models.Internal.SoftwareList[] softwareLists)
+ {
+ var softwareListItems = new List();
+ foreach (var softwareList in softwareLists)
+ {
+ softwareListItems.Add(ConvertToLogiqx(softwareList));
+ }
+ gameBase.SoftwareList = softwareListItems.ToArray();
+ }
+
+ return gameBase;
+ }
///
/// Convert from to