Update batch editing

Permit all possible properties in the dropdown, handle can't write cases
(many) as well as can't read (I don't think there are any of these).

https://projectpokemon.org/home/forums/topic/45789-how-to-require-a-pkm-equals-a-shiny-pid-in-batch-editor/?do=findComment&comment=232757
This commit is contained in:
Kurt 2018-06-13 18:52:09 -07:00
parent 39daa6c65d
commit dcfeff7bf3
2 changed files with 23 additions and 5 deletions

View file

@ -21,7 +21,7 @@ namespace PKHeX.Core
public static readonly string[] CustomProperties = { PROP_LEGAL };
public static readonly string[][] Properties = GetPropArray();
private static readonly Dictionary<string, PropertyInfo>[] Props = Types.Select(z => ReflectUtil.GetAllPropertyInfoCanWritePublic(z)
private static readonly Dictionary<string, PropertyInfo>[] Props = Types.Select(z => ReflectUtil.GetAllPropertyInfoPublic(z)
.GroupBy(p => p.Name).Select(g => g.First()).ToDictionary(p => p.Name))
.ToArray();
@ -38,12 +38,12 @@ namespace PKHeX.Core
var p = new string[Types.Length][];
for (int i = 0; i < p.Length; i++)
{
var pz = ReflectUtil.GetPropertiesCanWritePublic(Types[i]);
var pz = ReflectUtil.GetPropertiesPublic(Types[i]);
p[i] = pz.Concat(CustomProperties).OrderBy(a => a).ToArray();
}
// Properties for any PKM
var any = ReflectUtil.GetPropertiesCanWritePublic(typeof(PK1)).Union(p.SelectMany(a => a)).OrderBy(a => a).ToArray();
var any = ReflectUtil.GetPropertiesPublic(typeof(PK1)).Union(p.SelectMany(a => a)).OrderBy(a => a).ToArray();
// Properties shared by all PKM
var all = p.Aggregate(new HashSet<string>(p[0]), (h, e) => { h.IntersectWith(e); return h; }).OrderBy(a => a).ToArray();
@ -87,7 +87,7 @@ namespace PKHeX.Core
return null;
}
int index = typeIndex == Props.Length - 1 ? 0 : typeIndex - 1; // All vs Specific
int index = typeIndex -1 >= Props.Length ? 0 : typeIndex - 1; // All vs Specific
var pr = Props[index];
if (!pr.TryGetValue(propertyName, out var info))
return null;
@ -209,7 +209,7 @@ namespace PKHeX.Core
try
{
var tmp = SetPKMProperty(cmd, info, pi);
if (result != ModifyResult.Modified)
if (tmp != ModifyResult.Modified)
result = tmp;
}
catch (Exception ex) { Debug.WriteLine(MsgBEModifyFail + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue); }
@ -241,6 +241,9 @@ namespace PKHeX.Core
if (!props.TryGetValue(cmd.PropertyName, out var pi))
return ModifyResult.Error;
if (!pi.CanWrite)
return ModifyResult.Error;
object val = cmd.Random ? (object)cmd.RandomValue : cmd.PropertyValue;
ReflectUtil.SetValue(pi, pkm, val);
return ModifyResult.Modified;
@ -286,6 +289,8 @@ namespace PKHeX.Core
return true;
if (!ReflectUtil.HasProperty(pkm, cmd.PropertyName, out var pi))
return false;
if (!pi.CanRead)
return false;
return pi.IsValueEqual(pkm, cmd.PropertyValue) == cmd.Evaluator;
}
@ -302,6 +307,8 @@ namespace PKHeX.Core
return true;
if (!props.TryGetValue(cmd.PropertyName, out var pi))
return false;
if (!pi.CanRead)
return false;
return pi.IsValueEqual(pkm, cmd.PropertyValue) == cmd.Evaluator;
}

View file

@ -44,6 +44,17 @@ namespace PKHeX.Core
return type.GetTypeInfo().GetAllTypeInfo().SelectMany(GetAllProperties)
.Where(p => p.CanWrite && p.SetMethod.IsPublic);
}
public static IEnumerable<PropertyInfo> GetAllPropertyInfoPublic(Type type)
{
return type.GetTypeInfo().GetAllTypeInfo().SelectMany(GetAllProperties)
.Where(p => (p.CanRead && p.GetMethod.IsPublic) || (p.CanWrite && p.SetMethod.IsPublic));
}
public static IEnumerable<string> GetPropertiesPublic(Type type)
{
return GetAllPropertyInfoPublic(type).Select(p => p.Name)
.Distinct()
;
}
public static IEnumerable<string> GetPropertiesCanWritePublicDeclared(Type type)
{