mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix filtering logic around multiple match cases
This commit is contained in:
@@ -49,17 +49,36 @@ namespace SabreTools.Core.Filter
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Loop through and run each filter in order
|
||||
// Group filters by key
|
||||
var filterDictionary = new Dictionary<string, List<FilterObject>>();
|
||||
foreach (var filter in Filters)
|
||||
{
|
||||
// If the filter isn't for this object type, skip
|
||||
// Skip filters not applicable to the item
|
||||
if (filter.Key.ItemName == "item" && Array.IndexOf(TypeHelper.GetDatItemTypeNames(), itemName) == -1)
|
||||
continue;
|
||||
else if (filter.Key.ItemName != "item" && filter.Key.ItemName != itemName)
|
||||
continue;
|
||||
|
||||
// Ensure the key exists
|
||||
string key = filter.Key.ToString();
|
||||
if (!filterDictionary.ContainsKey(filter.Key.ToString()))
|
||||
filterDictionary[key] = [];
|
||||
|
||||
// Add the filter to the set
|
||||
filterDictionary[key].Add(filter);
|
||||
}
|
||||
|
||||
// Loop through and run each filter in order
|
||||
foreach (var filterKey in filterDictionary.Keys)
|
||||
{
|
||||
bool matchOne = false;
|
||||
foreach (var filter in filterDictionary[filterKey])
|
||||
{
|
||||
matchOne |= filter.Matches(dictionaryBase);
|
||||
}
|
||||
|
||||
// If we don't get a match, it's a failure
|
||||
if (!filter.Matches(dictionaryBase))
|
||||
if (!matchOne)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,9 @@ namespace SabreTools.DatFiles.Test
|
||||
DatFile datFile = new Formats.Logiqx(null, useGame: false);
|
||||
datFile.ConvertFromMetadata(item, "filename", indexId: 0, keep: true, statsOnly: false);
|
||||
|
||||
DatItems.Machine actualMachine = Assert.Single(datFile.ItemsDB.GetMachines()).Value;
|
||||
ValidateMachine(actualMachine);
|
||||
// TODO: Reenable when ItemsDB is used again
|
||||
// DatItems.Machine actualMachine = Assert.Single(datFile.ItemsDB.GetMachines()).Value;
|
||||
// ValidateMachine(actualMachine);
|
||||
|
||||
// Aggregate for easier validation
|
||||
DatItems.DatItem[] datItems = datFile.Items.SortedKeys
|
||||
|
||||
Reference in New Issue
Block a user