Update to .NET 10

Revise GameUtil to check all game branches
Closes #408
This commit is contained in:
Kurt 2026-01-02 10:45:29 -06:00
parent 5bd7003a60
commit 6e6ced878c
4 changed files with 84 additions and 124 deletions

View File

@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<LangVersion>13</LangVersion>
<LangVersion>14</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<NeutralLanguage>en</NeutralLanguage>
<Product>pkNX</Product>
<Company>Project Pokémon</Company>

View File

@ -43,9 +43,9 @@ pkNX also provides some utility to extract from supported container types, e.g.
## Building
pkNX is a Windows Forms application which requires [.NET 9.0](https://dotnet.microsoft.com/download/dotnet/9.0).
pkNX is a Windows Forms application which requires [.NET 10.0](https://dotnet.microsoft.com/download/dotnet/10.0).
The executable can be built with any compiler that supports C# 13.
The executable can be built with any compiler that supports C# 14.
## Dependencies

View File

@ -7,25 +7,6 @@ namespace pkNX.Structures;
/// </summary>
public static class GameUtil
{
/// <summary>
/// Gets a Version ID from the end of that Generation
/// </summary>
/// <param name="generation">Generation ID</param>
/// <returns>Version ID from requested generation. If none, return <see cref="Invalid"/>.</returns>
public static GameVersion GetVersion(int generation) => generation switch
{
1 => RBY,
2 => C,
3 => E,
4 => SS,
5 => W2,
6 => AS,
7 => UM,
8 => SH,
9 => VL,
_ => Invalid,
};
/// <summary>
/// Gets the Generation the <see cref="GameVersion"/> belongs to.
/// </summary>
@ -40,113 +21,92 @@ public static int GetGeneration(this GameVersion game)
if (Gen5.Contains(game)) return 5;
if (Gen6.Contains(game)) return 6;
if (Gen7.Contains(game)) return 7;
if (Gen8.Contains(game)) return 8;
if (Gen9.Contains(game)) return 9;
if (Gen7b.Contains(game)) return 7;
if (SWSH.Contains(game)) return 8;
if (game is PLA) return 8;
if (BDSP.Contains(game)) return 8;
if (SV.Contains(game)) return 9;
if (game is ZA) return 9;
return -1;
}
/// <summary>
/// Gets the Generation the <see cref="GameVersion"/> belongs to.
/// Checks if the <see cref="version"/> version (or subset versions) is equivalent to <see cref="g2"/>.
/// </summary>
/// <param name="game">Game to retrieve the generation for</param>
/// <returns>Generation ID</returns>
public static int GetMaxSpeciesID(this GameVersion game)
{
if (Gen1.Contains(game)) return 151;
if (Gen2.Contains(game)) return 251;
if (Gen3.Contains(game)) return 384;
if (Gen4.Contains(game)) return 493;
if (Gen5.Contains(game)) return 649;
if (Gen6.Contains(game)) return Legal.MaxSpeciesID_6;
if (Gen7.Contains(game) || Gen7b.Contains(game))
{
if (SM.Contains(game))
return 802;
if (USUM.Contains(game))
return 807;
return Legal.MaxSpeciesID_7_GG;
}
if (Gen8.Contains(game))
{
if (SWSH.Contains(game))
return Legal.MaxSpeciesID_8;
return Legal.MaxSpeciesID_8a;
}
if (game is ZA)
return Legal.MaxSpeciesID_9a;
if (Gen9.Contains(game))
{
return Legal.MaxSpeciesID_9;
}
return -1;
}
/// <summary>
/// Checks if the <see cref="g1"/> version (or subset versions) is equivalent to <see cref="g2"/>.
/// </summary>
/// <param name="g1">Version (set)</param>
/// <param name="version">Version (set)</param>
/// <param name="g2">Individual version</param>
public static bool Contains(this GameVersion g1, int g2) => g1.Contains((GameVersion)g2);
/// <summary>
/// Checks if the <see cref="g1"/> version (or subset versions) is equivalent to <see cref="g2"/>.
/// </summary>
/// <param name="g1">Version (set)</param>
/// <param name="g2">Individual version</param>
public static bool Contains(this GameVersion g1, GameVersion g2)
public static bool Contains(this GameVersion version, GameVersion g2)
{
if (g1 == g2 || g1 == Any)
if (version == g2 || version == Any)
return true;
return g1 switch
{
RB => g2 is RD or BU or GN,
RBY or Stadium => RB.Contains(g2) || g2 == YW,
Gen1 => RBY.Contains(g2) || g2 == Stadium,
GS => g2 is GD or SV,
GSC or Stadium2 => GS.Contains(g2) || g2 == C,
Gen2 => GSC.Contains(g2) || g2 == Stadium2,
RS => g2 is R or S,
RSE => RS.Contains(g2) || g2 == E,
FRLG => g2 is FR or LG,
COLO or XD => g2 == CXD,
CXD => g2 is COLO or XD,
RSBOX => RS.Contains(g2) || g2 == E || FRLG.Contains(g2),
Gen3 => RSE.Contains(g2) || FRLG.Contains(g2) || CXD.Contains(g2) || g2 == RSBOX,
DP => g2 is D or P,
HGSS => g2 is HG or SS,
DPPt => DP.Contains(g2) || g2 == Pt,
BATREV => DP.Contains(g2) || g2 == Pt || HGSS.Contains(g2),
Gen4 => DPPt.Contains(g2) || HGSS.Contains(g2) || g2 == BATREV,
BW => g2 is B or W,
B2W2 => g2 is B2 or W2,
Gen5 => BW.Contains(g2) || B2W2.Contains(g2),
XY => g2 is X or Y,
ORAS => g2 is OR or AS,
Gen6 => XY.Contains(g2) || ORAS.Contains(g2),
SM => g2 is SN or MN,
USUM => g2 is US or UM,
GG => g2 is GP or GE,
Gen7 => SM.Contains(g2) || USUM.Contains(g2),
Gen7b => GG.Contains(g2) || GO == g2,
SWSH => g2 is SW or SH,
PLA => g2 is PLA,
Gen8 => SWSH.Contains(g2) || PLA.Contains(g2),
SV => g2 is SL or VL,
ZA => g2 is ZA,
Gen9 => SV.Contains(g2) || ZA.Contains(g2),
_ => false,
};
if (version.IsValidSavedVersion())
return false;
return version.ContainsFromLumped(g2);
}
/// <summary>
/// Most recent game ID utilized by official games.
/// </summary>
internal const GameVersion HighestGameID = RB - 1;
/// <summary>
/// Indicates if the <see cref="GameVersion"/> value is a value used by the games or is an aggregate indicator.
/// </summary>
public static bool IsValidSavedVersion(this GameVersion version) => version is > 0 and <= HighestGameID;
/// <summary>
/// Checks if the <see cref="g1"/> version (or subset versions) is equivalent to <see cref="version1"/>.
/// </summary>
/// <param name="g1">Version (set)</param>
/// <param name="version1">Individual version</param>
public static bool ContainsFromLumped(this GameVersion g1, GameVersion version1) => g1 switch
{
RB => version1 is RD or BU or GN,
RBY => version1 is RD or BU or GN or YW or RB,
Stadium => version1 is RD or BU or GN or YW or RB or RBY,
StadiumJ => version1 is RD or BU or GN or YW or RB or RBY,
Gen1 => version1 is RD or BU or GN or YW or RB or RBY or Stadium,
GS => version1 is GD or SI,
GSC => version1 is GD or SI or C or GS,
Stadium2 => version1 is GD or SI or C or GS or GSC,
Gen2 => version1 is GD or SI or C or GS or GSC or Stadium2,
RS => version1 is R or S,
RSE => version1 is R or S or E or RS,
FRLG => version1 is FR or LG,
RSBOX => version1 is R or S or E or FR or LG,
Gen3 => version1 is R or S or E or FR or LG or CXD or RSBOX or RS or RSE or FRLG,
COLO => version1 is CXD,
XD => version1 is CXD,
DP => version1 is D or P,
HGSS => version1 is HG or SS,
DPPt => version1 is D or P or Pt or DP,
Gen4 => version1 is D or P or Pt or HG or SS or BATREV or DP or HGSS or DPPt,
BW => version1 is B or W,
B2W2 => version1 is B2 or W2,
Gen5 => version1 is B or W or B2 or W2 or BW or B2W2,
XY => version1 is X or Y,
ORAS => version1 is OR or AS,
Gen6 => version1 is X or Y or OR or AS or XY or ORAS,
SM => version1 is SN or MN,
USUM => version1 is US or UM,
Gen7 => version1 is SN or MN or US or UM or SM or USUM,
GG => version1 is GP or GE,
Gen7b => version1 is GP or GE or GO or GG,
SWSH => version1 is SW or SH,
BDSP => version1 is BD or SP,
Gen8 => version1 is SW or SH or BD or SP or SWSH or BDSP or PLA,
SV => version1 is SL or VL,
Gen9 => version1 is SL or VL or SV or ZA,
_ => false,
};
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows</TargetFramework>
<TargetFramework>net10.0-windows</TargetFramework>
<RootNamespace>pkNX.WinForms</RootNamespace>
<NeutralLanguage>en</NeutralLanguage>
<Company>Project Pokémon</Company>