mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 04:23:12 +00:00
Split meta filter from property filters
Closes #4009 was never implemented to work with SAV_Database... until now!
This commit is contained in:
parent
ce9a3d0104
commit
5fcf82c827
1 changed files with 16 additions and 2 deletions
|
@ -35,6 +35,7 @@ public sealed class SearchSettings
|
|||
public CloneDetectionMethod SearchClones { get; set; }
|
||||
public string BatchInstructions { get; init; } = string.Empty;
|
||||
private IReadOnlyList<StringInstruction> BatchFilters { get; set; } = Array.Empty<StringInstruction>();
|
||||
private IReadOnlyList<StringInstruction> BatchFiltersMeta { get; set; } = Array.Empty<StringInstruction>();
|
||||
|
||||
public readonly List<ushort> Moves = new();
|
||||
|
||||
|
@ -62,7 +63,7 @@ public sealed class SearchSettings
|
|||
/// <returns>Search results that match all criteria</returns>
|
||||
public IEnumerable<PKM> Search(IEnumerable<PKM> list)
|
||||
{
|
||||
BatchFilters = StringInstruction.GetFilters(BatchInstructions);
|
||||
InitializeFilters();
|
||||
var result = SearchInner(list);
|
||||
|
||||
if (SearchClones != CloneDetectionMethod.None)
|
||||
|
@ -81,7 +82,7 @@ public sealed class SearchSettings
|
|||
/// <returns>Search results that match all criteria</returns>
|
||||
public IEnumerable<SlotCache> Search(IEnumerable<SlotCache> list)
|
||||
{
|
||||
BatchFilters = StringInstruction.GetFilters(BatchInstructions);
|
||||
InitializeFilters();
|
||||
var result = SearchInner(list);
|
||||
|
||||
if (SearchClones != CloneDetectionMethod.None)
|
||||
|
@ -94,6 +95,17 @@ public sealed class SearchSettings
|
|||
return result;
|
||||
}
|
||||
|
||||
private void InitializeFilters()
|
||||
{
|
||||
var filters = StringInstruction.GetFilters(BatchInstructions);
|
||||
var meta = filters.Where(z => Core.BatchFilters.FilterMeta.Any(x => x.IsMatch(z.PropertyName))).ToList();
|
||||
if (meta.Count != 0)
|
||||
filters.RemoveAll(meta.Contains);
|
||||
BatchFilters = filters;
|
||||
BatchFiltersMeta = meta;
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<PKM> SearchInner(IEnumerable<PKM> list)
|
||||
{
|
||||
foreach (var pk in list)
|
||||
|
@ -109,6 +121,8 @@ public sealed class SearchSettings
|
|||
foreach (var entry in list)
|
||||
{
|
||||
var pk = entry.Entity;
|
||||
if (BatchFiltersMeta.Count != 0 && !BatchEditing.IsFilterMatchMeta(BatchFiltersMeta, entry))
|
||||
continue;
|
||||
if (!IsSearchMatch(pk))
|
||||
continue;
|
||||
yield return entry;
|
||||
|
|
Loading…
Reference in a new issue