mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Rename a couple AddItemsFrom methods
This commit is contained in:
@@ -7,12 +7,6 @@ namespace SabreTools.DatFiles.Test
|
||||
{
|
||||
public partial class DatFileTests
|
||||
{
|
||||
#region AddItemsFromBios
|
||||
|
||||
// TODO: Implement AddItemsFromBios tests
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddItemsFromChildren
|
||||
|
||||
// TODO: Implement AddItemsFromChildren tests
|
||||
@@ -25,9 +19,15 @@ namespace SabreTools.DatFiles.Test
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddItemsFromParent
|
||||
#region AddItemsFromCloneOfParent
|
||||
|
||||
// TODO: Implement AddItemsFromParent tests
|
||||
// TODO: Implement AddItemsFromCloneOfParent tests
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddItemsFromRomOfParent
|
||||
|
||||
// TODO: Implement AddItemsFromRomOfParent tests
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -11,16 +11,6 @@ namespace SabreTools.DatFiles
|
||||
// TODO: Create tests for all of these individually
|
||||
#region Splitting
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add items to the children
|
||||
/// </summary>
|
||||
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
||||
public void AddItemsFromBios()
|
||||
{
|
||||
AddItemsFromBiosImpl();
|
||||
AddItemsFromBiosImplDB();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use cloneof tags to add items to the parents, removing the child sets in the process
|
||||
/// </summary>
|
||||
@@ -50,10 +40,20 @@ namespace SabreTools.DatFiles
|
||||
/// Use cloneof tags to add items to the children, setting the new romof tag in the process
|
||||
/// </summary>
|
||||
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
||||
public void AddItemsFromParent()
|
||||
public void AddItemsFromCloneOfParent()
|
||||
{
|
||||
AddItemsFromParentImpl();
|
||||
AddItemsFromParentImplDB();
|
||||
AddItemsFromCloneOfParentImpl();
|
||||
AddItemsFromCloneOfParentImplDB();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add items to the children
|
||||
/// </summary>
|
||||
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
||||
public void AddItemsFromRomOfParent()
|
||||
{
|
||||
AddItemsFromRomOfParentImpl();
|
||||
AddItemsFromRomOfParentImplDB();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -101,92 +101,6 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#region Splitting Implementations
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add items to the children
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Applies to <see cref="Items"/>.
|
||||
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
||||
/// </remarks>
|
||||
private void AddItemsFromBiosImpl()
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
{
|
||||
// If the bucket has no items in it
|
||||
List<DatItem> items = GetItemsForBucket(bucket);
|
||||
if (items.Count == 0)
|
||||
continue;
|
||||
|
||||
// Get the machine
|
||||
var machine = items[0].GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
if (machine == null)
|
||||
continue;
|
||||
|
||||
// Get the romof parent items
|
||||
string? romOf = machine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
||||
List<DatItem> parentItems = GetItemsForBucket(romOf);
|
||||
if (parentItems.Count == 0)
|
||||
continue;
|
||||
|
||||
// If the parent exists and has items, we copy the items from the parent to the current game
|
||||
DatItem copyFrom = items[0];
|
||||
foreach (DatItem item in parentItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
if (items.FindIndex(i => i.GetName() == datItem.GetName()) == -1 && !items.Contains(datItem))
|
||||
Add(bucket, datItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add items to the children
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Applies to <see cref="ItemsDB"/>.
|
||||
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
||||
/// </remarks>
|
||||
private void AddItemsFromBiosImplDB()
|
||||
{
|
||||
List<string> buckets = [.. ItemsDB.SortedKeys];
|
||||
foreach (string bucket in buckets)
|
||||
{
|
||||
// If the bucket has no items in it
|
||||
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
||||
if (items.Count == 0)
|
||||
continue;
|
||||
|
||||
// Get the source for the first item
|
||||
var source = ItemsDB.GetSourceForItem(items.First().Key);
|
||||
|
||||
// Get the machine for the first item
|
||||
var machine = ItemsDB.GetMachineForItem(items.First().Key);
|
||||
if (machine.Value == null)
|
||||
continue;
|
||||
|
||||
// Get the romof parent items
|
||||
string? romOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
||||
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(romOf);
|
||||
if (parentItems.Count == 0)
|
||||
continue;
|
||||
|
||||
// If the parent exists and has items, we copy the items from the parent to the current game
|
||||
foreach (var item in parentItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Value.Clone();
|
||||
if (items.Any(i => i.Value.GetName() == datItem.GetName())
|
||||
&& items.Any(i => i.Value == datItem))
|
||||
{
|
||||
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use cloneof tags to add items to the parents, removing the child sets in the process
|
||||
/// </summary>
|
||||
@@ -771,7 +685,7 @@ namespace SabreTools.DatFiles
|
||||
/// Applies to <see cref="Items"/>.
|
||||
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
||||
/// </remarks>
|
||||
private void AddItemsFromParentImpl()
|
||||
private void AddItemsFromCloneOfParentImpl()
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
buckets.Sort();
|
||||
@@ -824,7 +738,7 @@ namespace SabreTools.DatFiles
|
||||
/// Applies to <see cref="ItemsDB"/>.
|
||||
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
||||
/// </remarks>
|
||||
private void AddItemsFromParentImplDB()
|
||||
private void AddItemsFromCloneOfParentImplDB()
|
||||
{
|
||||
List<string> buckets = [.. ItemsDB.SortedKeys];
|
||||
foreach (string bucket in buckets)
|
||||
@@ -882,6 +796,92 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add items to the children
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Applies to <see cref="Items"/>.
|
||||
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
||||
/// </remarks>
|
||||
private void AddItemsFromRomOfParentImpl()
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
{
|
||||
// If the bucket has no items in it
|
||||
List<DatItem> items = GetItemsForBucket(bucket);
|
||||
if (items.Count == 0)
|
||||
continue;
|
||||
|
||||
// Get the machine
|
||||
var machine = items[0].GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
if (machine == null)
|
||||
continue;
|
||||
|
||||
// Get the romof parent items
|
||||
string? romOf = machine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
||||
List<DatItem> parentItems = GetItemsForBucket(romOf);
|
||||
if (parentItems.Count == 0)
|
||||
continue;
|
||||
|
||||
// If the parent exists and has items, we copy the items from the parent to the current game
|
||||
DatItem copyFrom = items[0];
|
||||
foreach (DatItem item in parentItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
if (items.FindIndex(i => i.GetName() == datItem.GetName()) == -1 && !items.Contains(datItem))
|
||||
Add(bucket, datItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add items to the children
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Applies to <see cref="ItemsDB"/>.
|
||||
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
||||
/// </remarks>
|
||||
private void AddItemsFromRomOfParentImplDB()
|
||||
{
|
||||
List<string> buckets = [.. ItemsDB.SortedKeys];
|
||||
foreach (string bucket in buckets)
|
||||
{
|
||||
// If the bucket has no items in it
|
||||
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
||||
if (items.Count == 0)
|
||||
continue;
|
||||
|
||||
// Get the source for the first item
|
||||
var source = ItemsDB.GetSourceForItem(items.First().Key);
|
||||
|
||||
// Get the machine for the first item
|
||||
var machine = ItemsDB.GetMachineForItem(items.First().Key);
|
||||
if (machine.Value == null)
|
||||
continue;
|
||||
|
||||
// Get the romof parent items
|
||||
string? romOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
||||
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(romOf);
|
||||
if (parentItems.Count == 0)
|
||||
continue;
|
||||
|
||||
// If the parent exists and has items, we copy the items from the parent to the current game
|
||||
foreach (var item in parentItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Value.Clone();
|
||||
if (items.Any(i => i.Value.GetName() == datItem.GetName())
|
||||
&& items.Any(i => i.Value == datItem))
|
||||
{
|
||||
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all BIOS and device sets
|
||||
/// </summary>
|
||||
|
||||
@@ -148,10 +148,10 @@ namespace SabreTools.DatTools
|
||||
// Now we want to loop through all of the games and set the correct information
|
||||
while (datFile.AddItemsFromDevices(true, true)) ;
|
||||
datFile.AddItemsFromDevices(false, true);
|
||||
datFile.AddItemsFromParent();
|
||||
datFile.AddItemsFromCloneOfParent();
|
||||
|
||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||
datFile.AddItemsFromBios();
|
||||
datFile.AddItemsFromRomOfParent();
|
||||
|
||||
// Then, remove the romof and cloneof tags so it's not picked up by the manager
|
||||
datFile.RemoveMachineRelationshipTags();
|
||||
@@ -191,7 +191,7 @@ namespace SabreTools.DatTools
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
// Now we want to loop through all of the games and set the correct information
|
||||
datFile.AddItemsFromParent();
|
||||
datFile.AddItemsFromCloneOfParent();
|
||||
|
||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||
datFile.RemoveItemsFromRomOfChild(false);
|
||||
|
||||
Reference in New Issue
Block a user