-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dynamically lookup PieceCategory.Max
- Loading branch information
1 parent
00906b2
commit b9bd3ee
Showing
4 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Jotunn.Utils | ||
{ | ||
internal static class PieceUtils | ||
{ | ||
public static int MaxPieceCategory { get; } = GetMaxPieceCategory(); | ||
|
||
private static int GetMaxPieceCategory() | ||
{ | ||
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) | ||
{ | ||
return values[indexOfMax]; | ||
} | ||
|
||
Logger.LogWarning("Could not find Piece.PieceCategory.Max, using fallback value 4"); | ||
return 4; | ||
} | ||
} | ||
} |