Add setters and getters for Machine

This commit is contained in:
Matt Nadareski
2024-03-09 23:43:43 -05:00
parent f37e3a07da
commit c2e30138db
55 changed files with 534 additions and 890 deletions

View File

@@ -395,11 +395,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 && lastgame.ToLowerInvariant() != datItem.Machine.Name?.ToLowerInvariant())
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
SabreJSON.WriteEndGame(jtw);
// If we have a new game, output the beginning of the new item
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name?.ToLowerInvariant())
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
SabreJSON.WriteStartGame(jtw, datItem);
// Check for a "null" item
@@ -410,7 +410,7 @@ namespace SabreTools.DatFiles.Formats
WriteDatItem(jtw, datItem);
// Set the new data to compare against
lastgame = datItem.Machine.Name;
lastgame = datItem.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey);
}
}
@@ -457,8 +457,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.Machine.Name))
datItem.Machine.Name = datItem.Machine.Name!.TrimStart(Path.DirectorySeparatorChar);
if (!string.IsNullOrEmpty(datItem.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)))
datItem.Machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, datItem.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)!.TrimStart(Path.DirectorySeparatorChar));
// Build the state
jtw.WriteStartObject();