using System;
namespace PKHeX.Core;
public static class EntityGender
{
///
/// Translates a Gender string to Gender integer.
///
/// Gender string
/// Gender integer
public static int GetFromString(ReadOnlySpan s)
{
if (s.Length != 1)
return 2;
return GetFromChar(s[0]);
}
///
/// Translates a Gender char to Gender integer.
///
public static int GetFromChar(char c) => c switch
{
'♂' or 'M' => 0,
'♀' or 'F' => 1,
_ => 2,
};
///
/// Gets the gender ID of the species based on the Personality ID.
///
/// National Dex ID.
/// Personality ID.
/// Gender ID (0/1/2)
/// This method should only be used for Generations 3-5 origin.
public static int GetFromPID(ushort species, uint pid)
{
var gt = PKX.Personal[species].Gender;
return GetFromPIDAndRatio(pid, gt);
}
public static int GetFromPIDAndRatio(uint pid, byte gr) => gr switch
{
PersonalInfo.RatioMagicGenderless => 2,
PersonalInfo.RatioMagicFemale => 1,
PersonalInfo.RatioMagicMale => 0,
_ => (pid & 0xFF) < gr ? 1 : 0,
};
}