Skip to content

Commit

Permalink
chore: simplefied parsing of vanilla max category
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed May 1, 2024
1 parent 5ed1b0c commit a9888c9
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions JotunnLib/Utils/PieceUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ namespace Jotunn.Utils
{
internal static class PieceUtils
{
public static int VanillaMaxPieceCategory { get; } = GetMaxPieceCategory();
public static int VanillaMaxPieceCategory { get; } = GetVanillaMaxPieceCategory();

private static int GetMaxPieceCategory()
private static int GetVanillaMaxPieceCategory()
{
var indexOfMax = Array.IndexOf(Enum.GetNames(typeof(Piece.PieceCategory)), nameof(Piece.PieceCategory.Max));
var values = Enum.GetValues(typeof(Piece.PieceCategory)).Cast<int>().ToArray();

if (indexOfMax >= 0)
try
{
return values[indexOfMax];
return (int)Enum.Parse(typeof(Piece.PieceCategory), nameof(Piece.PieceCategory.Max));
}
catch (Exception e)
{
Logger.LogWarning("Could not find Piece.PieceCategory.Max, using fallback value 4");
return 4;
}

Logger.LogWarning("Could not find Piece.PieceCategory.Max, using fallback value 4");
return 4;
}
}
}

0 comments on commit a9888c9

Please sign in to comment.