Update ownership sort

gen4 and below saves don't provide an accurate Version/Game; ignore the
version check if it is not a valid game ID.

secondary sort to current OT name so that same-named OT (ignoring case)
are immediately after the current save's pkms.
This commit is contained in:
Kurt 2018-04-23 08:25:32 -07:00
parent e25e3fcc19
commit 505877763b
2 changed files with 6 additions and 3 deletions

View file

@ -120,5 +120,6 @@
default: return false;
}
}
public static bool IsValid(this GameVersion g) => 0 < g && g <= GameVersion.RB;
}
}

View file

@ -108,7 +108,8 @@ namespace PKHeX.Core
public static IEnumerable<PKM> OrderByOwnership(this IEnumerable<PKM> list, ITrainerInfo trainer)
{
return list.InitialSortBy()
.ThenByDescending(trainer.IsOriginalHandler) // true first
.ThenByDescending(p => trainer.IsOriginalHandler(p, ((GameVersion)trainer.Game).IsValid())) // true first
.ThenByDescending(p => string.Equals(p.OT_Name, trainer.OT, StringComparison.CurrentCultureIgnoreCase))
.OrderByTrainer()
.ThenBy(p => p.Species)
.FinalSortBy();
@ -168,12 +169,13 @@ namespace PKHeX.Core
/// </summary>
/// <param name="trainer">The <see cref="ITrainerInfo"/> requesting the check.</param>
/// <param name="pk">Pokémon data</param>
/// <param name="checkGame">Toggle to check the game's version or not</param>
/// <returns>True if OT, false if not OT.</returns>
private static bool IsOriginalHandler(this ITrainerInfo trainer, PKM pk)
private static bool IsOriginalHandler(this ITrainerInfo trainer, PKM pk, bool checkGame)
{
if (pk.Format >= 6)
return pk.CurrentHandler != 1;
if (trainer.Game != pk.Version)
if (checkGame && trainer.Game != pk.Version)
return false;
if (trainer.TID != pk.TID || trainer.SID != pk.SID)
return false;