Create DB version of Against; add passthroughs

This commit is contained in:
Matt Nadareski
2025-02-24 09:20:46 -05:00
parent 2cd17cd711
commit 1bed35c933
19 changed files with 198 additions and 68 deletions

View File

@@ -598,7 +598,7 @@ namespace SabreTools.DatFiles
return;
// Get the current machine
var machine = ItemsDB.GetMachineForItem(datItem.Key);
var machine = GetMachineForItemDB(datItem.Key);
if (machine.Value == null)
return;

View File

@@ -378,7 +378,7 @@ namespace SabreTools.DatFiles
continue;
// Get the machine for the first item
var machine = ItemsDB.GetMachineForItem(items.First().Key);
var machine = GetMachineForItemDB(items.First().Key);
if (machine.Value == null)
continue;
@@ -396,14 +396,14 @@ namespace SabreTools.DatFiles
foreach (var item in items)
{
// Get the source for the current item
var source = ItemsDB.GetSourceForItem(item.Key);
var source = GetSourceForItemDB(item.Key);
// Get the parent items and current machine name
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(cloneOf);
if (parentItems.Count == 0)
continue;
string? machineName = ItemsDB.GetMachineForItem(item.Key).Value?
string? machineName = GetMachineForItemDB(item.Key).Value?
.GetStringFieldValue(Models.Metadata.Machine.NameKey);
// Special disk handling
@@ -558,10 +558,10 @@ namespace SabreTools.DatFiles
continue;
// Get the source for the first item
var source = ItemsDB.GetSourceForItem(items.First().Key);
var source = GetSourceForItemDB(items.First().Key);
// Get the machine for the first item in the list
var machine = ItemsDB.GetMachineForItem(items.First().Key);
var machine = GetMachineForItemDB(items.First().Key);
if (machine.Value == null)
continue;
@@ -587,7 +587,7 @@ namespace SabreTools.DatFiles
}
// Get the parent machine
var parentMachine = ItemsDB.GetMachineForItem(GetItemsForBucketDB(cloneOf).First().Key);
var parentMachine = GetMachineForItemDB(GetItemsForBucketDB(cloneOf).First().Key);
if (parentMachine.Value == null)
continue;
@@ -596,7 +596,7 @@ namespace SabreTools.DatFiles
string? romof = parentMachine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
foreach (var key in items.Keys)
{
var itemMachine = ItemsDB.GetMachineForItem(key);
var itemMachine = GetMachineForItemDB(key);
if (itemMachine.Value == null)
continue;
@@ -771,10 +771,10 @@ namespace SabreTools.DatFiles
continue;
// Get the source for the first item
var source = ItemsDB.GetSourceForItem(items.First().Key);
var source = GetSourceForItemDB(items.First().Key);
// Get the machine for the first item
var machine = ItemsDB.GetMachineForItem(items.First().Key);
var machine = GetMachineForItemDB(items.First().Key);
if (machine.Value == null)
continue;
@@ -822,7 +822,7 @@ namespace SabreTools.DatFiles
.Select(i => (i as DeviceRef)!.GetName()!));
// Set new machine information and add to the current machine
var copyFrom = ItemsDB.GetMachineForItem(items.First().Key);
var copyFrom = GetMachineForItemDB(items.First().Key);
if (copyFrom.Value == null)
continue;
@@ -878,7 +878,7 @@ namespace SabreTools.DatFiles
.Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!));
// Set new machine information and add to the current machine
var copyFrom = ItemsDB.GetMachineForItem(GetItemsForBucketDB(bucket).First().Key);
var copyFrom = GetMachineForItemDB(GetItemsForBucketDB(bucket).First().Key);
if (copyFrom.Value == null)
continue;
@@ -975,10 +975,10 @@ namespace SabreTools.DatFiles
continue;
// Get the source for the first item
var source = ItemsDB.GetSourceForItem(items.First().Key);
var source = GetSourceForItemDB(items.First().Key);
// Get the machine for the first item
var machine = ItemsDB.GetMachineForItem(items.First().Key);
var machine = GetMachineForItemDB(items.First().Key);
if (machine.Value == null)
continue;
@@ -1049,7 +1049,7 @@ namespace SabreTools.DatFiles
continue;
// Get the machine
var machine = ItemsDB.GetMachineForItem(items.First().Key);
var machine = GetMachineForItemDB(items.First().Key);
if (machine.Value == null)
continue;
@@ -1133,7 +1133,7 @@ namespace SabreTools.DatFiles
continue;
// Get the machine for the first item
var machine = ItemsDB.GetMachineForItem(items.First().Key);
var machine = GetMachineForItemDB(items.First().Key);
if (machine.Value == null)
continue;
@@ -1155,14 +1155,14 @@ namespace SabreTools.DatFiles
// Now we want to get the parent romof tag and put it in each of the remaining items
items = GetItemsForBucketDB(bucket);
machine = ItemsDB.GetMachineForItem(GetItemsForBucketDB(cloneOf).First().Key);
machine = GetMachineForItemDB(GetItemsForBucketDB(cloneOf).First().Key);
if (machine.Value == null)
continue;
string? romof = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
foreach (var item in items)
{
machine = ItemsDB.GetMachineForItem(item.Key);
machine = GetMachineForItemDB(item.Key);
if (machine.Value == null)
continue;
@@ -1231,7 +1231,7 @@ namespace SabreTools.DatFiles
continue;
// Get the machine for the item
var machine = ItemsDB.GetMachineForItem(items.First().Key);
var machine = GetMachineForItemDB(items.First().Key);
if (machine.Value == null)
continue;

View File

@@ -498,7 +498,7 @@ namespace SabreTools.DatFiles
continue;
// Create a machine to hold everything
var machine = ItemsDB.GetMachineForItem(items.First().Key).Value!.GetInternalClone();
var machine = GetMachineForItemDB(items.First().Key).Value!.GetInternalClone();
// Handle Trurip object, if it exists
if (machine.ContainsKey(Models.Metadata.Machine.TruripKey))

View File

@@ -271,6 +271,18 @@ namespace SabreTools.DatFiles
public IDictionary<long, Machine> GetMachinesDB()
=> ItemsDB.GetMachines();
/// <summary>
/// Get the index and machine associated with an item index
/// </summary>
public KeyValuePair<long, Machine?> GetMachineForItemDB(long itemIndex)
=> GetMachineForItemDB(itemIndex);
/// <summary>
/// Get the index and source associated with an item index
/// </summary>
public KeyValuePair<long, Source?> GetSourceForItemDB(long itemIndex)
=> GetSourceForItemDB(itemIndex);
/// <summary>
/// Remove a key from the file dictionary if it exists
/// </summary>

View File

@@ -135,7 +135,7 @@ namespace SabreTools.DatFiles.Formats
var datItem = new KeyValuePair<long, DatItem>(kvp.Key, ProcessNullifiedItem(kvp.Value));
// Get the machine for the item
var machine = ItemsDB.GetMachineForItem(datItem.Key);
var machine = GetMachineForItemDB(datItem.Key);
// Write out the item if we're using machine names or we're not ignoring
if (!Modifiers.UseRomName || !ShouldIgnore(datItem.Value, ignoreblanks))
@@ -179,7 +179,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="lastgame">The name of the last game to be output</param>
private void WriteDatItemDB(StreamWriter sw, KeyValuePair<long, DatItem> datItem, string? lastgame)
{
var machine = ItemsDB.GetMachineForItem(datItem.Key).Value;
var machine = GetMachineForItemDB(datItem.Key).Value;
WriteDatItemImpl(sw, datItem.Value, machine!, lastgame);
}

View File

@@ -489,7 +489,7 @@ namespace SabreTools.DatFiles.Formats
foreach (var kvp in items)
{
// Get the machine for the item
var machine = ItemsDB.GetMachineForItem(kvp.Key);
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))
@@ -621,7 +621,7 @@ namespace SabreTools.DatFiles.Formats
private void WriteDatItemDB(JsonTextWriter jtw, KeyValuePair<long, DatItem> datItem)
{
// Get the machine for the item
var machine = ItemsDB.GetMachineForItem(datItem.Key);
var machine = GetMachineForItemDB(datItem.Key);
// Pre-process the item name
ProcessItemName(datItem.Value, machine.Value, forceRemoveQuotes: true, forceRomName: false);

View File

@@ -318,7 +318,7 @@ namespace SabreTools.DatFiles.Formats
foreach (var kvp in items)
{
// Get the machine for the item
var machine = ItemsDB.GetMachineForItem(kvp.Key);
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))
@@ -445,7 +445,7 @@ namespace SabreTools.DatFiles.Formats
private void WriteDatItemDB(XmlTextWriter xtw, KeyValuePair<long, DatItem> datItem)
{
// Get the machine for the item
var machine = ItemsDB.GetMachineForItem(datItem.Key);
var machine = GetMachineForItemDB(datItem.Key);
// Pre-process the item name
ProcessItemName(datItem.Value, machine.Value, forceRemoveQuotes: true, forceRomName: false);

View File

@@ -1156,16 +1156,6 @@ namespace SabreTools.DatFiles
return GetBucketKey(datItem.Key, _bucketedBy, lower: true, norename: true);
}
/// <summary>
/// Class used during deduplication
/// </summary>
private struct ItemMappings(DatItem item, long machineId, long sourceId)
{
public DatItem Item = item;
public long MachineId = machineId;
public long SourceId = sourceId;
}
#endregion
#region Statistics

View File

@@ -0,0 +1,12 @@
namespace SabreTools.DatFiles
{
/// <summary>
/// Class used during deduplication
/// </summary>
public struct ItemMappings(DatItems.DatItem item, long machineId, long sourceId)
{
public DatItems.DatItem Item = item;
public long MachineId = machineId;
public long SourceId = sourceId;
}
}