mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add OpenMSX machine serialization
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SabreTools.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
@@ -7,6 +10,34 @@ namespace SabreTools.Serialization
|
||||
{
|
||||
#region Serialize
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.OpenMSX.Software"/> to <cref="Models.Internal.Machine"/>
|
||||
/// </summary>
|
||||
public static Models.Internal.Machine ConvertMachineFromOpenMSX(Models.OpenMSX.Software item)
|
||||
{
|
||||
var machine = new Models.Internal.Machine
|
||||
{
|
||||
[Models.Internal.Machine.NameKey] = item.Title,
|
||||
[Models.Internal.Machine.GenMSXIDKey] = item.GenMSXID,
|
||||
[Models.Internal.Machine.SystemKey] = item.System,
|
||||
[Models.Internal.Machine.CompanyKey] = item.Company,
|
||||
[Models.Internal.Machine.YearKey] = item.Year,
|
||||
[Models.Internal.Machine.CountryKey] = item.Country,
|
||||
};
|
||||
|
||||
if (item.Dump != null && item.Dump.Any())
|
||||
{
|
||||
var dumps = new List<Models.Internal.Dump>();
|
||||
foreach (var dump in item.Dump)
|
||||
{
|
||||
dumps.Add(ConvertFromOpenMSX(dump));
|
||||
}
|
||||
machine[Models.Internal.Machine.DumpKey] = dumps.ToArray();
|
||||
}
|
||||
|
||||
return machine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.OpenMSX.Dump"/> to <cref="Models.Internal.Dump"/>
|
||||
/// </summary>
|
||||
@@ -67,6 +98,34 @@ namespace SabreTools.Serialization
|
||||
|
||||
#region Deserialize
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.Internal.Machine"/> to <cref="Models.OpenMSX.Software"/>
|
||||
/// </summary>
|
||||
public static Models.OpenMSX.Software ConvertMachineToOpenMSX(Models.Internal.Machine item)
|
||||
{
|
||||
var game = new Models.OpenMSX.Software
|
||||
{
|
||||
Title = item.ReadString(Models.Internal.Machine.NameKey),
|
||||
GenMSXID = item.ReadString(Models.Internal.Machine.GenMSXIDKey),
|
||||
System = item.ReadString(Models.Internal.Machine.SystemKey),
|
||||
Company = item.ReadString(Models.Internal.Machine.CompanyKey),
|
||||
Year = item.ReadString(Models.Internal.Machine.YearKey),
|
||||
Country = item.ReadString(Models.Internal.Machine.CountryKey),
|
||||
};
|
||||
|
||||
if (item.ContainsKey(Models.Internal.Machine.DumpKey) && item[Models.Internal.Machine.DumpKey] is Models.Internal.Dump[] dumps)
|
||||
{
|
||||
var dumpItems = new List<Models.OpenMSX.Dump>();
|
||||
foreach (var dump in dumps)
|
||||
{
|
||||
dumpItems.Add(ConvertToOpenMSX(dump));
|
||||
}
|
||||
game.Dump = dumpItems.ToArray();
|
||||
}
|
||||
|
||||
return game;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.Internal.Dump"/> to <cref="Models.OpenMSX.Dump"/>
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user