Increase readability of Machine access

This commit is contained in:
Matt Nadareski
2025-05-02 16:46:20 -04:00
parent d5ae1dffaa
commit 7d35594040
33 changed files with 124 additions and 114 deletions

View File

@@ -82,7 +82,7 @@ namespace SabreTools.DatFiles.Formats
WriteDatItem(sw, datItem, lastgame);
// Set the new data to compare against
lastgame = datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName();
lastgame = datItem.GetMachine()!.GetName();
}
}
@@ -168,7 +168,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="lastgame">The name of the last game to be output</param>
private void WriteDatItem(StreamWriter sw, DatItem datItem, string? lastgame)
{
var machine = datItem.GetFieldValue<Machine>(DatItem.MachineKey);
var machine = datItem.GetMachine();
WriteDatItemImpl(sw, datItem, machine!, lastgame);
}

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)!.GetName(), StringComparison.OrdinalIgnoreCase))
if (lastgame != null && !string.Equals(lastgame, datItem.GetMachine()!.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)!.GetName(), StringComparison.OrdinalIgnoreCase))
if (lastgame == null || !string.Equals(lastgame, datItem.GetMachine()!.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)!.GetName();
lastgame = datItem.GetMachine()!.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)!.GetName()))
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName()!.TrimStart(Path.DirectorySeparatorChar));
if (!string.IsNullOrEmpty(datItem.GetMachine()!.GetName()))
datItem.GetMachine()!.SetName(datItem.GetMachine()!.GetName()!.TrimStart(Path.DirectorySeparatorChar));
// Build the state
jtw.WriteStartObject();
@@ -564,7 +564,7 @@ namespace SabreTools.DatFiles.Formats
// Write the Machine
jtw.WritePropertyName("machine");
JsonSerializer js = new() { Formatting = Formatting.Indented };
js.Serialize(jtw, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!);
js.Serialize(jtw, datItem.GetMachine()!);
jtw.WritePropertyName("items");
jtw.WriteStartArray();
@@ -595,7 +595,7 @@ namespace SabreTools.DatFiles.Formats
private void WriteDatItem(JsonTextWriter jtw, DatItem datItem)
{
// Get the machine for the item
var machine = datItem.GetFieldValue<Machine>(DatItem.MachineKey);
var machine = datItem.GetMachine();
// Pre-process the item name
ProcessItemName(datItem, machine, forceRemoveQuotes: true, forceRomName: false);

View File

@@ -240,11 +240,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)!.GetName(), StringComparison.OrdinalIgnoreCase))
if (lastgame != null && !string.Equals(lastgame, datItem.GetMachine()!.GetName(), StringComparison.OrdinalIgnoreCase))
WriteEndGame(xtw);
// If we have a new game, output the beginning of the new item
if (lastgame == null || !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName(), StringComparison.OrdinalIgnoreCase))
if (lastgame == null || !string.Equals(lastgame, datItem.GetMachine()!.GetName(), StringComparison.OrdinalIgnoreCase))
WriteStartGame(xtw, datItem);
// Check for a "null" item
@@ -255,7 +255,7 @@ namespace SabreTools.DatFiles.Formats
WriteDatItem(xtw, datItem);
// Set the new data to compare against
lastgame = datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName();
lastgame = datItem.GetMachine()!.GetName();
}
}
@@ -387,14 +387,14 @@ namespace SabreTools.DatFiles.Formats
private static void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
// No game should start with a path separator
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName()?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty);
datItem.GetMachine()!.SetName(datItem.GetMachine()!.GetName()?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty);
// Write the machine
xtw.WriteStartElement("directory");
XmlSerializer xs = new(typeof(Machine));
XmlSerializerNamespaces ns = new();
ns.Add("", "");
xs.Serialize(xtw, datItem.GetFieldValue<Machine>(DatItem.MachineKey), ns);
xs.Serialize(xtw, datItem.GetMachine(), ns);
xtw.WriteStartElement("files");
@@ -424,7 +424,7 @@ namespace SabreTools.DatFiles.Formats
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
// Get the machine for the item
var machine = datItem.GetFieldValue<Machine>(DatItem.MachineKey);
var machine = datItem.GetMachine();
// Pre-process the item name
ProcessItemName(datItem, machine, forceRemoveQuotes: true, forceRomName: false);