Adds switch and swap into event to party.

This commit is contained in:
Deukhoofd 2020-10-31 16:13:10 +01:00
parent 813cf65331
commit 506f10b085
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 7 additions and 0 deletions

View File

@ -8,6 +8,11 @@ namespace PkmnLibSharp.Battling
{ {
public class PokemonParty : PointerWrapper, IEnumerable<Pokemon?> public class PokemonParty : PointerWrapper, IEnumerable<Pokemon?>
{ {
public delegate void OnSwitchDelegate(ulong a, ulong b);
public event OnSwitchDelegate? OnSwitch;
public delegate void OnSwapIntoDelegate(ulong a);
public event OnSwapIntoDelegate? OnSwapInto;
private Pokemon?[]? _cache; private Pokemon?[]? _cache;
private ReadOnlyNativePtrArray<Pokemon>? _party; private ReadOnlyNativePtrArray<Pokemon>? _party;
@ -43,6 +48,7 @@ namespace PkmnLibSharp.Battling
var temp = _cache![indexA]; var temp = _cache![indexA];
_cache[indexA] = _cache[indexB]; _cache[indexA] = _cache[indexB];
_cache[indexB] = temp; _cache[indexB] = temp;
OnSwitch?.Invoke(indexA, indexB);
} }
public Pokemon? SwapInto(ulong indexA, Pokemon? pokemon) public Pokemon? SwapInto(ulong indexA, Pokemon? pokemon)
@ -52,6 +58,7 @@ namespace PkmnLibSharp.Battling
if (pokemon != null) pkmnPtr = pokemon.Ptr; if (pokemon != null) pkmnPtr = pokemon.Ptr;
Creaturelib.Generated.CreatureParty.SwapInto(ref ptr, Ptr, indexA, pkmnPtr).Assert(); Creaturelib.Generated.CreatureParty.SwapInto(ref ptr, Ptr, indexA, pkmnPtr).Assert();
_cache![indexA] = pokemon; _cache![indexA] = pokemon;
OnSwapInto?.Invoke(indexA);
if (TryResolvePointer(ptr, out Pokemon? newPokemon)) if (TryResolvePointer(ptr, out Pokemon? newPokemon))
return newPokemon!; return newPokemon!;
return Constructor.Active.ConstructPokemon(ptr)!; return Constructor.Active.ConstructPokemon(ptr)!;