mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-07-24 12:50:12 -05:00
* Update to .NET 10 * Property fields * API signature updates * Extension method blocks * Completed dark mode support Outside of my control: - vertical tab control (pkm editor) - datetimepicker controls - lgpe event flags (no idea) - some control types having white-borders when they should really be gray Box background is 50% transparency to effectively darken the image. * Custom legality report popup * Event diff dialog, version select dialog * Add quick overwrite popup for export sav * Extension methods * Dark Mode: glow currently editing sprite * Add invalid encounter hint for trade evolutions * Extension properties * Append legality hint on hover card * Slot image loading: clear the screen-reader description if a slot is empty/invalid, rather than retain the previous description. Changing boxes would easily confuse users on this.
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Interface that exposes a <see cref="Version"/> to see which version the data originated in.
|
|
/// </summary>
|
|
public interface IVersion
|
|
{
|
|
/// <summary>
|
|
/// The version the data originated in.
|
|
/// </summary>
|
|
GameVersion Version { get; }
|
|
}
|
|
|
|
public static partial class Extensions
|
|
{
|
|
extension(IVersion v)
|
|
{
|
|
private bool CanBeReceivedBy(GameVersion version) => v.Version.Contains(version);
|
|
|
|
/// <summary>
|
|
/// Gets a compatible saved version value for the given <see cref="IVersion"/>.
|
|
/// </summary>
|
|
/// <param name="prefer">Preferred version to use, if possible.</param>
|
|
public GameVersion GetCompatibleVersion(GameVersion prefer)
|
|
{
|
|
if (!v.CanBeReceivedBy(prefer))
|
|
return v.GetSingleVersion();
|
|
if (!prefer.IsValidSavedVersion())
|
|
return prefer.GetSingleVersion();
|
|
return prefer;
|
|
}
|
|
|
|
public GameVersion GetSingleVersion()
|
|
{
|
|
var version = v.Version;
|
|
if (version.IsValidSavedVersion())
|
|
return version;
|
|
return version.GetSingleVersion();
|
|
}
|
|
}
|
|
|
|
public static GameVersion GetSingleVersion(this GameVersion lump)
|
|
{
|
|
const int max = (int)GameUtil.HighestGameID;
|
|
var rnd = Util.Rand;
|
|
while (true) // this isn't optimal, but is low maintenance
|
|
{
|
|
var game = (GameVersion)rnd.Next(1, max);
|
|
if (!lump.Contains(game))
|
|
continue;
|
|
if (game == GameVersion.BU)
|
|
continue; // Ignore this one; only can be Japanese language.
|
|
return game;
|
|
}
|
|
}
|
|
}
|