Implements Formes iterator.
This commit is contained in:
@@ -100,5 +100,15 @@ namespace Creaturelib.Generated
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureSpecies_GetRandomGender")]
|
||||
internal static extern Gender GetRandomGender(IntPtr p, IntPtr random);
|
||||
|
||||
/// <param name="p">CreatureSpecies *</param>
|
||||
/// <returns>long unsigned int</returns>
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureSpecies_GetVariantsCount")]
|
||||
internal static extern ulong GetVariantsCount(IntPtr p);
|
||||
|
||||
/// <param name="p">CreatureSpecies *</param>
|
||||
/// <returns>const const SpeciesVariant * *</returns>
|
||||
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_CreatureSpecies_GetVariants")]
|
||||
internal static extern IntPtr GetVariants(IntPtr p);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ namespace Pkmnlib.Generated
|
||||
/// <param name="growthRate">const char *</param>
|
||||
/// <param name="captureRate">unsigned char</param>
|
||||
/// <param name="baseHappiness">unsigned char</param>
|
||||
/// <param name="eggGroupsRaw">const const char * *</param>
|
||||
/// <param name="eggGroupsLength">long unsigned int</param>
|
||||
/// <returns>unsigned char</returns>
|
||||
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_PokemonSpecies_Construct")]
|
||||
internal static extern byte Construct(ref IntPtr @out, ushort id, IntPtr name, IntPtr defaultForme, float genderRatio, IntPtr growthRate, byte captureRate, byte baseHappiness);
|
||||
internal static extern byte Construct(ref IntPtr @out, ushort id, IntPtr name, IntPtr defaultForme, float genderRatio, IntPtr growthRate, byte captureRate, byte baseHappiness, IntPtr eggGroupsRaw, ulong eggGroupsLength);
|
||||
|
||||
/// <param name="p">const PokemonSpecies *</param>
|
||||
/// <returns>void</returns>
|
||||
@@ -52,5 +54,16 @@ namespace Pkmnlib.Generated
|
||||
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_PokemonSpecies_GetEvolutions")]
|
||||
internal static extern byte GetEvolutions(IntPtr p, ref IntPtr @out);
|
||||
|
||||
/// <param name="p">const PokemonSpecies *</param>
|
||||
/// <returns>long unsigned int</returns>
|
||||
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_PokemonSpecies_GetEggGroupCount")]
|
||||
internal static extern ulong GetEggGroupCount(IntPtr p);
|
||||
|
||||
/// <param name="p">const PokemonSpecies *</param>
|
||||
/// <param name="index">long unsigned int</param>
|
||||
/// <returns>const char *</returns>
|
||||
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_PokemonSpecies_GetEggGroup")]
|
||||
internal static extern IntPtr GetEggGroup(IntPtr p, ulong index);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,27 @@ namespace PkmnLibSharp.Library
|
||||
private LearnableMoves? _moves;
|
||||
private string? _name;
|
||||
private ReadOnlyArray<byte>? _types;
|
||||
|
||||
public Forme(string name, float height, float weight, uint baseExperience, byte[] types,
|
||||
ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseSpecialAttack,
|
||||
ushort baseSpecialDefense, ushort baseSpeed, IReadOnlyCollection<string> abilities,
|
||||
IReadOnlyCollection<string> hiddenAbilities,
|
||||
LearnableMoves moves)
|
||||
{
|
||||
var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray();
|
||||
var hiddenAbilitiesConverted = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
|
||||
var ab = abilitiesConverted.ArrayPtr();
|
||||
var hab = hiddenAbilitiesConverted.ArrayPtr();
|
||||
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
|
||||
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
|
||||
baseSpecialDefense, baseSpeed, ab, (ulong) abilities.Count, hab,
|
||||
(ulong) hiddenAbilities.Count, moves.Ptr);
|
||||
foreach (var intPtr in abilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
foreach (var intPtr in hiddenAbilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
internal Forme(IntPtr parent) : base(parent)
|
||||
{
|
||||
@@ -112,29 +133,7 @@ namespace PkmnLibSharp.Library
|
||||
{
|
||||
return Types[index];
|
||||
}
|
||||
|
||||
public Forme(string name, float height, float weight, uint baseExperience, byte[] types,
|
||||
ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseSpecialAttack,
|
||||
ushort baseSpecialDefense, ushort baseSpeed, IReadOnlyCollection<string> abilities,
|
||||
IReadOnlyCollection<string> hiddenAbilities,
|
||||
LearnableMoves moves)
|
||||
{
|
||||
var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray();
|
||||
var hiddenAbilitiesConverted = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
|
||||
var ab = abilitiesConverted.ArrayPtr();
|
||||
var hab = hiddenAbilitiesConverted.ArrayPtr();
|
||||
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
|
||||
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
|
||||
baseSpecialDefense, baseSpeed, ab, (ulong) abilities.Count, hab,
|
||||
(ulong) hiddenAbilities.Count, moves.Ptr);
|
||||
var f = new Forme(ptr);
|
||||
foreach (var intPtr in abilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
foreach (var intPtr in hiddenAbilitiesConverted)
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
|
||||
public byte GetRandomAbility(Random rand)
|
||||
{
|
||||
return SpeciesVariant.GetRandomTalent(Ptr, rand.Ptr);
|
||||
|
||||
@@ -15,12 +15,13 @@ namespace PkmnLibSharp.Library
|
||||
}
|
||||
|
||||
public Species(ushort id, string name, Forme defaultForme, float genderRatio, string growthRate,
|
||||
byte captureRate, byte baseHappiness)
|
||||
byte captureRate, byte baseHappiness, string[] eggGroups)
|
||||
{
|
||||
var ptr = IntPtr.Zero;
|
||||
var eggGroupsPtr = eggGroups.ArrayPtr();
|
||||
PokemonSpecies.Construct(ref ptr, id, name.ToPtr(), defaultForme.Ptr, genderRatio,
|
||||
growthRate.ToPtr(), captureRate, baseHappiness).Assert();
|
||||
_formes.Add("default", defaultForme);
|
||||
growthRate.ToPtr(), captureRate, baseHappiness, eggGroupsPtr, (ulong) eggGroups.Length).Assert();
|
||||
_formeCache.Add("default", defaultForme);
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
@@ -30,6 +31,18 @@ namespace PkmnLibSharp.Library
|
||||
public string Name => _name ??= CreatureSpecies.GetName(Ptr).PtrString()!;
|
||||
public string GrowthRate => _growthRate ??= CreatureSpecies.GetGrowthRate(Ptr).PtrString()!;
|
||||
|
||||
public ReadOnlyNativePtrArray<Forme> Formes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_formes != null) return _formes;
|
||||
var startPtr = CreatureSpecies.GetVariants(Ptr);
|
||||
var size = CreatureSpecies.GetVariantsCount(Ptr);
|
||||
_formes = new ReadOnlyNativePtrArray<Forme>(startPtr, (int) size);
|
||||
return _formes;
|
||||
}
|
||||
}
|
||||
|
||||
public ReadOnlyNativePtrArray<EvolutionData> Evolutions
|
||||
{
|
||||
get
|
||||
@@ -50,19 +63,19 @@ namespace PkmnLibSharp.Library
|
||||
|
||||
public bool TryGetForme(string s, out Forme? forme)
|
||||
{
|
||||
if (_formes.TryGetValue(s, out forme))
|
||||
if (_formeCache.TryGetValue(s, out forme))
|
||||
return true;
|
||||
var ptr = IntPtr.Zero;
|
||||
if (CreatureSpecies.TryGetVariant(Ptr, s.ToPtr(), ref ptr) == MarshalHelper.True)
|
||||
{
|
||||
if (TryResolvePointer(ptr, out forme))
|
||||
{
|
||||
_formes.Add(s, forme!);
|
||||
_formeCache.Add(s, forme!);
|
||||
return true;
|
||||
}
|
||||
|
||||
forme = new Forme(ptr);
|
||||
_formes.Add(s, forme);
|
||||
_formeCache.Add(s, forme);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,23 +84,23 @@ namespace PkmnLibSharp.Library
|
||||
|
||||
public Forme GetForme(string s)
|
||||
{
|
||||
if (_formes.TryGetValue(s, out var forme))
|
||||
if (_formeCache.TryGetValue(s, out var forme))
|
||||
return forme;
|
||||
var ptr = IntPtr.Zero;
|
||||
CreatureSpecies.GetVariant(ref ptr, Ptr, s.ToPtr()).Assert();
|
||||
if (TryResolvePointer(ptr, out Forme? f))
|
||||
{
|
||||
_formes.Add(s, f!);
|
||||
_formeCache.Add(s, f!);
|
||||
return f!;
|
||||
}
|
||||
forme = new Forme(ptr);
|
||||
_formes.Add(s, forme);
|
||||
_formeCache.Add(s, forme);
|
||||
return forme;
|
||||
}
|
||||
|
||||
public void SetForme(string s, Forme forme)
|
||||
{
|
||||
_formes.Add(s, forme);
|
||||
_formeCache.Add(s, forme);
|
||||
CreatureSpecies.SetVariant(Ptr, s.ToPtr(), forme.Ptr).Assert();
|
||||
}
|
||||
|
||||
@@ -104,15 +117,16 @@ namespace PkmnLibSharp.Library
|
||||
private string? _name;
|
||||
private string? _growthRate;
|
||||
|
||||
private readonly Dictionary<string, Forme> _formes =
|
||||
private readonly Dictionary<string, Forme> _formeCache =
|
||||
new Dictionary<string, Forme>(StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
private ReadOnlyNativePtrArray<EvolutionData>? _evolutions;
|
||||
private ReadOnlyNativePtrArray<Forme>? _formes;
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var forme in _formes)
|
||||
foreach (var forme in _formeCache)
|
||||
{
|
||||
forme.Value.MarkAsDeleted();
|
||||
}
|
||||
|
||||
BIN
PkmnLibSharp/Native/libCreatureLib.so
(Stored with Git LFS)
BIN
PkmnLibSharp/Native/libCreatureLib.so
(Stored with Git LFS)
Binary file not shown.
BIN
PkmnLibSharp/Native/libpkmnLib.so
(Stored with Git LFS)
BIN
PkmnLibSharp/Native/libpkmnLib.so
(Stored with Git LFS)
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user