Fix off-by-1 for Hidden Power hover preview card

This commit is contained in:
Kurt 2023-12-29 10:07:37 -08:00
parent 50209c4f0d
commit 9897630b08
2 changed files with 19 additions and 2 deletions

View file

@ -71,6 +71,23 @@ public static class HiddenPower
/// </summary> /// </summary>
public const int TypeCount = 16; public const int TypeCount = 16;
/// <summary>
/// Gets the Type Name index of the input Hidden Power Type
/// </summary>
/// <param name="type">Fetched Hidden Power Type</param>
/// <param name="index">Type Name index</param>
/// <returns>True if the input Hidden Power Type is valid</returns>
public static bool TryGetTypeIndex(int type, out byte index)
{
if ((uint)type >= TypeCount)
{
index = default;
return false;
}
index = (byte)(type + 1); // Normal type is not a valid Hidden Power type
return true;
}
private static ReadOnlySpan<byte> SixBitType => private static ReadOnlySpan<byte> SixBitType =>
[ [
// (low-bit mash) * 15 / 63 // (low-bit mash) * 15 / 63

View file

@ -23,8 +23,8 @@ public partial class MoveDisplay : UserControl
var name = moves[move]; var name = moves[move];
if (move == (int)Core.Move.HiddenPower && pk.Context is not EntityContext.Gen8a) if (move == (int)Core.Move.HiddenPower && pk.Context is not EntityContext.Gen8a)
{ {
type = (byte)pk.HPType; if (HiddenPower.TryGetTypeIndex(pk.HPType, out type))
name = $"{name} ({GameInfo.Strings.types[type]}) [{pk.HPPower}]"; name = $"{name} ({GameInfo.Strings.types[type]}) [{pk.HPPower}]";
} }
var size = PokePreview.MeasureSize(name, L_Move.Font); var size = PokePreview.MeasureSize(name, L_Move.Font);