mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add provisions for generic item filters
This commit is contained in:
@@ -45,6 +45,8 @@ namespace SabreTools.Filter
|
||||
"set" => ParseMachineFilterId(fieldName!),
|
||||
|
||||
// DatItem
|
||||
"datitem" => ParseDatItemFilterId(fieldName!),
|
||||
"item" => ParseDatItemFilterId(fieldName!),
|
||||
_ => ParseDatItemFilterId(itemName, fieldName!),
|
||||
};
|
||||
}
|
||||
@@ -87,6 +89,23 @@ namespace SabreTools.Filter
|
||||
return (MetadataFile.MachineKey, constantMatch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse and validate item fields
|
||||
/// </summary>
|
||||
private static (string?, string?) ParseDatItemFilterId(string fieldName)
|
||||
{
|
||||
// Get all item types
|
||||
var itemTypes = TypeHelper.GetDatItemTypeNames();
|
||||
|
||||
// If we get any matches
|
||||
string? match = itemTypes.FirstOrDefault(t => t != null && ParseDatItemFilterId(t, fieldName) != (null, null));
|
||||
if (match != null)
|
||||
return ("item", ParseDatItemFilterId(match, fieldName).Item2);
|
||||
|
||||
// Nothing was found
|
||||
return (null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse and validate item fields
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SabreTools.Models.Metadata;
|
||||
|
||||
namespace SabreTools.Filter
|
||||
@@ -57,7 +58,7 @@ namespace SabreTools.Filter
|
||||
foreach (var filter in this.Filters)
|
||||
{
|
||||
// If the filter isn't for this object type, skip
|
||||
if (filter.Key[0] != itemName)
|
||||
if (filter.Key[0] != itemName || (filter.Key[0] == "item" && TypeHelper.GetDatItemTypeNames().Contains(itemName)))
|
||||
continue;
|
||||
|
||||
// If we don't get a match, it's a failure
|
||||
|
||||
@@ -37,6 +37,18 @@ namespace SabreTools.Filter
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to get all DatItem types
|
||||
/// </summary>
|
||||
public static string?[] GetDatItemTypeNames()
|
||||
{
|
||||
return AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(a => a.GetTypes())
|
||||
.Where(t => typeof(DatItem).IsAssignableFrom(t) && t.IsClass)
|
||||
.Select(GetXmlRootAttributeElementName)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to get the DatItem type from the name
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user