mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add RomCenter 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,23 @@ namespace SabreTools.Serialization
|
||||
{
|
||||
#region Serialize
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.RomCenter.Game"/> to <cref="Models.Internal.Machine"/>
|
||||
/// </summary>
|
||||
public static Models.Internal.Machine ConvertMachineFromRomCenter(Models.RomCenter.Rom item)
|
||||
{
|
||||
var machine = new Models.Internal.Machine
|
||||
{
|
||||
[Models.Internal.Machine.RomOfKey] = item.ParentName,
|
||||
//[Models.Internal.Machine.RomOfKey] = item.ParentDescription, // This is unmappable
|
||||
[Models.Internal.Machine.NameKey] = item.GameName,
|
||||
[Models.Internal.Machine.DescriptionKey] = item.GameDescription,
|
||||
[Models.Internal.Machine.RomKey] = new Models.Internal.Rom[] { ConvertFromRomCenter(item) },
|
||||
};
|
||||
|
||||
return machine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.RomCenter.Rom"/> to <cref="Models.Internal.Rom"/>
|
||||
/// </summary>
|
||||
@@ -26,6 +46,31 @@ namespace SabreTools.Serialization
|
||||
|
||||
#region Deserialize
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.Internal.Machine"/> to an array of <cref="Models.RomCenter.Rom"/>
|
||||
/// </summary>
|
||||
public static Models.RomCenter.Rom[] ConvertMachineToRomCenter(Models.Internal.Machine item)
|
||||
{
|
||||
var romItems = new List<Models.RomCenter.Rom>();
|
||||
|
||||
if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
|
||||
{
|
||||
foreach (var rom in roms)
|
||||
{
|
||||
var romItem = ConvertToRomCenter(rom);
|
||||
|
||||
romItem.ParentName = rom.ReadString(Models.Internal.Machine.RomOfKey);
|
||||
//romItem.ParentDescription = rom.ReadString(Models.Internal.Machine.RomOfKey); // This is unmappable
|
||||
romItem.GameName = rom.ReadString(Models.Internal.Machine.NameKey);
|
||||
romItem.GameDescription = rom.ReadString(Models.Internal.Machine.DescriptionKey);
|
||||
|
||||
romItems.Add(romItem);
|
||||
}
|
||||
}
|
||||
|
||||
return romItems.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.Internal.Rom"/> to <cref="Models.RomCenter.Rom"/>
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user