mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-14 16:27:21 +00:00
Add ObjectType custom filter logic
This commit is contained in:
parent
2abf95cdf8
commit
2083201ee1
1 changed files with 12 additions and 1 deletions
|
@ -25,7 +25,7 @@ namespace PKHeX.Core
|
|||
typeof (PK2), typeof (SK2), typeof (PK1),
|
||||
};
|
||||
|
||||
public static readonly List<string> CustomProperties = new() { PROP_LEGAL, PROP_RIBBONS };
|
||||
public static readonly List<string> CustomProperties = new() { PROP_LEGAL, PROP_TYPENAME, PROP_RIBBONS };
|
||||
public static readonly string[][] Properties = GetPropArray();
|
||||
|
||||
private static readonly Dictionary<string, PropertyInfo>[] Props = Types.Select(z => ReflectUtil.GetAllPropertyInfoPublic(z)
|
||||
|
@ -38,6 +38,7 @@ namespace PKHeX.Core
|
|||
private const string CONST_BYTES = "$[]";
|
||||
|
||||
private const string PROP_LEGAL = "Legal";
|
||||
private const string PROP_TYPENAME = "ObjectType";
|
||||
private const string PROP_RIBBONS = "Ribbons";
|
||||
private const string IdentifierContains = nameof(PKM.Identifier) + "Contains";
|
||||
|
||||
|
@ -192,6 +193,12 @@ namespace PKHeX.Core
|
|||
{
|
||||
foreach (var cmd in filters)
|
||||
{
|
||||
if (cmd.PropertyName is PROP_TYPENAME)
|
||||
{
|
||||
if ((obj.GetType().Name == cmd.PropertyValue) != cmd.Evaluator)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReflectUtil.HasProperty(obj, cmd.PropertyName, out var pi))
|
||||
return false;
|
||||
try
|
||||
|
@ -434,6 +441,10 @@ namespace PKHeX.Core
|
|||
(pkm, cmd) => new LegalityAnalysis(pkm).Valid == cmd.Evaluator,
|
||||
(info, cmd) => info.Legality.Valid == cmd.Evaluator),
|
||||
|
||||
new ComplexFilter(PROP_TYPENAME,
|
||||
(pkm, cmd) => (pkm.GetType().Name == cmd.PropertyValue) == cmd.Evaluator,
|
||||
(info, cmd) => (info.Entity.GetType().Name == cmd.PropertyValue) == cmd.Evaluator),
|
||||
|
||||
new ComplexFilter(IdentifierContains,
|
||||
(pkm, cmd) => pkm.Identifier?.Contains(cmd.PropertyValue) == cmd.Evaluator,
|
||||
(info, cmd) => info.Entity.Identifier?.Contains(cmd.PropertyValue) == cmd.Evaluator),
|
||||
|
|
Loading…
Reference in a new issue