Move some constants to the deserializer

This commit is contained in:
Matt Nadareski
2024-04-03 21:46:35 -04:00
parent 8ced91d0fa
commit ff8dcd30a5
3 changed files with 22 additions and 20 deletions

View File

@@ -1,14 +0,0 @@
namespace SabreTools.Serialization
{
/// <summary>
/// Separated value serializer/deserializer for AttractMode romlists
/// </summary>
public static class AttractMode
{
public const string HeaderWithoutRomname = "#Name;Title;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra;Buttons";
public const int HeaderWithoutRomnameCount = 17;
public const string HeaderWithRomname = "#Romname;Title;Emulator;Cloneof;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra;Buttons;Favourite;Tags;PlayedCount;PlayedTime;FileIsAvailable";
public const int HeaderWithRomnameCount = 22;
}
}

View File

@@ -12,6 +12,14 @@ namespace SabreTools.Serialization.Deserializers
IFileDeserializer<MetadataFile>,
IStreamDeserializer<MetadataFile>
{
#region Constants
public const int HeaderWithoutRomnameCount = 17;
public const int HeaderWithRomnameCount = 22;
#endregion
#region IFileDeserializer
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
@@ -70,7 +78,7 @@ namespace SabreTools.Serialization.Deserializers
// Parse the line into a row
Row row;
if (reader.Line.Count < Serialization.AttractMode.HeaderWithRomnameCount)
if (reader.Line.Count < HeaderWithRomnameCount)
{
row = new Row
{
@@ -94,8 +102,8 @@ namespace SabreTools.Serialization.Deserializers
};
// If we have additional fields
if (reader.Line.Count > Serialization.AttractMode.HeaderWithoutRomnameCount)
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(Serialization.AttractMode.HeaderWithoutRomnameCount).ToArray();
if (reader.Line.Count > HeaderWithoutRomnameCount)
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(HeaderWithoutRomnameCount).ToArray();
}
else
{
@@ -121,8 +129,8 @@ namespace SabreTools.Serialization.Deserializers
};
// If we have additional fields
if (reader.Line.Count > Serialization.AttractMode.HeaderWithRomnameCount)
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(Serialization.AttractMode.HeaderWithRomnameCount).ToArray();
if (reader.Line.Count > HeaderWithRomnameCount)
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(HeaderWithRomnameCount).ToArray();
}
rows.Add(row);

View File

@@ -11,6 +11,14 @@ namespace SabreTools.Serialization.Serializers
IFileSerializer<MetadataFile>,
IStreamSerializer<MetadataFile>
{
#region Constants
public const string HeaderWithoutRomname = "#Name;Title;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra;Buttons";
public const string HeaderWithRomname = "#Romname;Title;Emulator;Cloneof;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra;Buttons;Favourite;Tags;PlayedCount;PlayedTime;FileIsAvailable";
#endregion
#region IFileSerializer
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
@@ -64,7 +72,7 @@ namespace SabreTools.Serialization.Serializers
// TODO: Include flag to write out long or short header
// Write the short header
writer.WriteString(Serialization.AttractMode.HeaderWithoutRomname); // TODO: Convert to array of values
writer.WriteString(HeaderWithoutRomname); // TODO: Convert to array of values
writer.WriteLine();
// Write out the rows, if they exist