Move machine to same name model as DatItem

This commit is contained in:
Matt Nadareski
2025-05-02 16:05:08 -04:00
parent 90a7917ebe
commit 7754ca5bd7
34 changed files with 247 additions and 230 deletions

View File

@@ -412,11 +412,11 @@ namespace SabreTools.DatFiles.Formats
DatItem datItem = datItems[index];
// If we have a different game and we're not at the start of the list, output the end of last item
if (lastgame != null && !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
if (lastgame != null && !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName(), StringComparison.OrdinalIgnoreCase))
WriteEndGame(jtw);
// If we have a new game, output the beginning of the new item
if (lastgame == null || !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
if (lastgame == null || !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName(), StringComparison.OrdinalIgnoreCase))
WriteStartGame(jtw, datItem);
// Check for a "null" item
@@ -427,7 +427,7 @@ namespace SabreTools.DatFiles.Formats
WriteDatItem(jtw, datItem);
// Set the new data to compare against
lastgame = datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey);
lastgame = datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName();
}
}
@@ -493,11 +493,11 @@ namespace SabreTools.DatFiles.Formats
var machine = GetMachineForItemDB(kvp.Key);
// If we have a different game and we're not at the start of the list, output the end of last item
if (lastgame != null && !string.Equals(lastgame, machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
if (lastgame != null && !string.Equals(lastgame, machine.Value!.GetName(), StringComparison.OrdinalIgnoreCase))
WriteEndGame(jtw);
// If we have a new game, output the beginning of the new item
if (lastgame == null || !string.Equals(lastgame, machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
if (lastgame == null || !string.Equals(lastgame, machine.Value!.GetName(), StringComparison.OrdinalIgnoreCase))
WriteStartGame(jtw, kvp.Value);
// Check for a "null" item
@@ -508,7 +508,7 @@ namespace SabreTools.DatFiles.Formats
WriteDatItemDB(jtw, datItem);
// Set the new data to compare against
lastgame = machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey);
lastgame = machine.Value!.GetName();
}
}
@@ -555,8 +555,8 @@ namespace SabreTools.DatFiles.Formats
private static void WriteStartGame(JsonTextWriter jtw, DatItem datItem)
{
// No game should start with a path separator
if (!string.IsNullOrEmpty(datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)))
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)!.TrimStart(Path.DirectorySeparatorChar));
if (!string.IsNullOrEmpty(datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName()))
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName()!.TrimStart(Path.DirectorySeparatorChar));
// Build the state
jtw.WriteStartObject();