Try to make method names clearer

This commit is contained in:
Matt Nadareski
2025-01-13 13:01:36 -05:00
parent ecf21a5bc0
commit e78154d824
2 changed files with 113 additions and 113 deletions

View File

@@ -65,10 +65,10 @@ namespace SabreTools.DatFiles
/// Use romof tags to remove bios items from children /// Use romof tags to remove bios items from children
/// </summary> /// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param> /// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
public void RemoveBiosItemsFromChild(bool bios) public void RemoveItemsFromRomOfChild(bool bios)
{ {
RemoveBiosItemsFromChildImpl(bios); RemoveItemsFromRomOfChildImpl(bios);
RemoveBiosItemsFromChildImplDB(bios); RemoveItemsFromRomOfChildImplDB(bios);
} }
/// <summary> /// <summary>
@@ -966,108 +966,6 @@ namespace SabreTools.DatFiles
} }
} }
/// <summary>
/// Use romof tags to remove bios items from children
/// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
/// <remarks>
/// Applies to <see cref="Items"/>.
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
/// </remarks>
private void RemoveBiosItemsFromChildImpl(bool bios)
{
// Loop through the romof tags
List<string> buckets = [.. Items.Keys];
buckets.Sort();
foreach (string bucket in buckets)
{
// If the bucket has no items in it
var items = GetItemsForBucket(bucket);
if (items == null || items.Count == 0)
continue;
// Get the machine
var machine = items[0].GetFieldValue<Machine>(DatItem.MachineKey);
if (machine == null)
continue;
// If the game (is/is not) a bios, we want to continue
if (bios ^ (machine.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true))
continue;
// Get the bios parent
string? romOf = machine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
if (string.IsNullOrEmpty(romOf))
continue;
// If the parent doesn't have any items, we want to continue
var parentItems = GetItemsForBucket(romOf!);
if (parentItems == null || parentItems.Count == 0)
continue;
// If the parent exists and has items, we remove the items that are in the parent from the current game
foreach (DatItem item in parentItems)
{
DatItem datItem = (DatItem)item.Clone();
while (items.Contains(datItem))
{
Items.Remove(bucket, datItem);
}
}
}
}
/// <summary>
/// Use romof tags to remove bios items from children
/// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
/// <remarks>
/// Applies to <see cref="ItemsDB"/>.
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
/// </remarks>
private void RemoveBiosItemsFromChildImplDB(bool bios)
{
// Loop through the romof tags
List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string bucket in buckets)
{
// If the bucket has no items in it
var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0)
continue;
// Get the machine for the item
var machine = ItemsDB.GetMachineForItem(items.First().Key);
if (machine.Value == null)
continue;
// If the game (is/is not) a bios, we want to continue
if (bios ^ (machine.Value.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true))
continue;
// Get the bios parent
string? romOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
if (string.IsNullOrEmpty(romOf))
continue;
// If the parent doesn't have any items, we want to continue
var parentItems = GetItemsForBucketDB(romOf!);
if (parentItems == null || parentItems.Count == 0)
continue;
// If the parent exists and has items, we remove the items that are in the parent from the current game
foreach (var item in parentItems)
{
var matchedItems = items.Where(i => i.Value == item.Value);
foreach (var match in matchedItems)
{
ItemsDB.RemoveItem(match.Key);
}
}
}
}
/// <summary> /// <summary>
/// Use cloneof tags to remove items from the children /// Use cloneof tags to remove items from the children
/// </summary> /// </summary>
@@ -1182,6 +1080,108 @@ namespace SabreTools.DatFiles
} }
} }
/// <summary>
/// Use romof tags to remove bios items from children
/// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
/// <remarks>
/// Applies to <see cref="Items"/>.
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
/// </remarks>
private void RemoveItemsFromRomOfChildImpl(bool bios)
{
// Loop through the romof tags
List<string> buckets = [.. Items.Keys];
buckets.Sort();
foreach (string bucket in buckets)
{
// If the bucket has no items in it
var items = GetItemsForBucket(bucket);
if (items == null || items.Count == 0)
continue;
// Get the machine
var machine = items[0].GetFieldValue<Machine>(DatItem.MachineKey);
if (machine == null)
continue;
// If the game (is/is not) a bios, we want to continue
if (bios ^ (machine.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true))
continue;
// Get the bios parent
string? romOf = machine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
if (string.IsNullOrEmpty(romOf))
continue;
// If the parent doesn't have any items, we want to continue
var parentItems = GetItemsForBucket(romOf!);
if (parentItems == null || parentItems.Count == 0)
continue;
// If the parent exists and has items, we remove the items that are in the parent from the current game
foreach (DatItem item in parentItems)
{
DatItem datItem = (DatItem)item.Clone();
while (items.Contains(datItem))
{
Items.Remove(bucket, datItem);
}
}
}
}
/// <summary>
/// Use romof tags to remove bios items from children
/// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
/// <remarks>
/// Applies to <see cref="ItemsDB"/>.
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
/// </remarks>
private void RemoveItemsFromRomOfChildImplDB(bool bios)
{
// Loop through the romof tags
List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string bucket in buckets)
{
// If the bucket has no items in it
var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0)
continue;
// Get the machine for the item
var machine = ItemsDB.GetMachineForItem(items.First().Key);
if (machine.Value == null)
continue;
// If the game (is/is not) a bios, we want to continue
if (bios ^ (machine.Value.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true))
continue;
// Get the bios parent
string? romOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
if (string.IsNullOrEmpty(romOf))
continue;
// If the parent doesn't have any items, we want to continue
var parentItems = GetItemsForBucketDB(romOf!);
if (parentItems == null || parentItems.Count == 0)
continue;
// If the parent exists and has items, we remove the items that are in the parent from the current game
foreach (var item in parentItems)
{
var matchedItems = items.Where(i => i.Value == item.Value);
foreach (var match in matchedItems)
{
ItemsDB.RemoveItem(match.Key);
}
}
}
}
/// <summary> /// <summary>
/// Remove all romof and cloneof tags from all machines /// Remove all romof and cloneof tags from all machines
/// </summary> /// </summary>

View File

@@ -127,8 +127,8 @@ namespace SabreTools.DatTools
datFile.AddItemsFromChildren(true, false); datFile.AddItemsFromChildren(true, false);
// Now that we have looped through the cloneof tags, we loop through the romof tags // Now that we have looped through the cloneof tags, we loop through the romof tags
datFile.RemoveBiosItemsFromChild(false); datFile.RemoveItemsFromRomOfChild(false);
datFile.RemoveBiosItemsFromChild(true); datFile.RemoveItemsFromRomOfChild(true);
// Finally, remove the romof and cloneof tags so it's not picked up by the manager // Finally, remove the romof and cloneof tags so it's not picked up by the manager
datFile.RemoveMachineRelationshipTags(); datFile.RemoveMachineRelationshipTags();
@@ -172,8 +172,8 @@ namespace SabreTools.DatTools
datFile.AddItemsFromChildren(true, true); datFile.AddItemsFromChildren(true, true);
// Now that we have looped through the cloneof tags, we loop through the romof tags // Now that we have looped through the cloneof tags, we loop through the romof tags
datFile.RemoveBiosItemsFromChild(false); datFile.RemoveItemsFromRomOfChild(false);
datFile.RemoveBiosItemsFromChild(true); datFile.RemoveItemsFromRomOfChild(true);
// Finally, remove the romof and cloneof tags so it's not picked up by the manager // Finally, remove the romof and cloneof tags so it's not picked up by the manager
datFile.RemoveMachineRelationshipTags(); datFile.RemoveMachineRelationshipTags();
@@ -194,8 +194,8 @@ namespace SabreTools.DatTools
datFile.AddItemsFromParent(); datFile.AddItemsFromParent();
// Now that we have looped through the cloneof tags, we loop through the romof tags // Now that we have looped through the cloneof tags, we loop through the romof tags
datFile.RemoveBiosItemsFromChild(false); datFile.RemoveItemsFromRomOfChild(false);
datFile.RemoveBiosItemsFromChild(true); datFile.RemoveItemsFromRomOfChild(true);
// Finally, remove the romof and cloneof tags so it's not picked up by the manager // Finally, remove the romof and cloneof tags so it's not picked up by the manager
datFile.RemoveMachineRelationshipTags(); datFile.RemoveMachineRelationshipTags();
@@ -216,8 +216,8 @@ namespace SabreTools.DatTools
datFile.RemoveItemsFromCloneOfChild(); datFile.RemoveItemsFromCloneOfChild();
// Now that we have looped through the cloneof tags, we loop through the romof tags // Now that we have looped through the cloneof tags, we loop through the romof tags
datFile.RemoveBiosItemsFromChild(false); datFile.RemoveItemsFromRomOfChild(false);
datFile.RemoveBiosItemsFromChild(true); datFile.RemoveItemsFromRomOfChild(true);
// Finally, remove the romof and cloneof tags so it's not picked up by the manager // Finally, remove the romof and cloneof tags so it's not picked up by the manager
datFile.RemoveMachineRelationshipTags(); datFile.RemoveMachineRelationshipTags();