Refactor entire library in line with new PkmnLib
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
2448f3bfb5
commit
a8a6b775b3
|
@ -1,70 +1,56 @@
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.DynamicData.LearnedMove;
|
using Interface = PkmnLibSharp.FFI.DynamicData.LearnedMove;
|
||||||
|
|
||||||
namespace PkmnLibSharp.DynamicData
|
namespace PkmnLibSharp.DynamicData
|
||||||
{
|
{
|
||||||
public class LearnedMove : ExternPointer<LearnedMove.CacheData>
|
public class LearnedMove : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
private LearnedMove(FFIHandle handle) : base(handle){}
|
||||||
|
|
||||||
|
public static LearnedMove Create(MoveData moveData, MoveLearnMethod learnMethod)
|
||||||
{
|
{
|
||||||
public MoveData? MoveData { get; internal set; }
|
var handle = Interface.learned_move_new(moveData.Handle, learnMethod);
|
||||||
public MoveLearnMethod? LearnMethod { get; internal set; }
|
return Resolver.Instance.ResolveLearnedMove(handle.Resolve());
|
||||||
}
|
|
||||||
|
|
||||||
internal LearnedMove(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public LearnedMove(MoveData moveData, MoveLearnMethod learnMethod)
|
|
||||||
{
|
|
||||||
InitializePointer(Interface.learned_move_new(moveData.Ptr, learnMethod), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MoveData? _moveData;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The immutable move information of the move.
|
/// The immutable move information of the move.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MoveData MoveData => Cache.MoveData ??= new MoveData(Interface.learned_move_move_data(Ptr), true);
|
public MoveData MoveData => _moveData ??= Resolver.Instance.ResolveMoveData(Interface.learned_move_move_data(Handle).Resolve());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximal power points for this move.
|
/// The maximal power points for this move.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte MaxPP => Interface.learned_move_max_pp(Ptr);
|
public byte MaxPP => Interface.learned_move_max_pp(Handle);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of remaining power points. If this is 0, we can not use the move anymore.
|
/// The amount of remaining power points. If this is 0, we can not use the move anymore.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte RemainingPP => Interface.learned_move_remaining_pp(Ptr);
|
public byte RemainingPP => Interface.learned_move_remaining_pp(Handle);
|
||||||
|
|
||||||
|
private MoveLearnMethod? _learnMethod;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The way the move was learned.
|
/// The way the move was learned.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MoveLearnMethod LearnMethod => Cache.LearnMethod ??= Interface.learned_move_learn_method(Ptr);
|
public MoveLearnMethod LearnMethod => _learnMethod ??= Interface.learned_move_learn_method(Handle);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Try and reduce the PP by a certain amount. If the amount is higher than the current remaining uses,
|
/// Try and reduce the PP by a certain amount. If the amount is higher than the current remaining uses,
|
||||||
/// return false. Otherwise, reduce the PP, and return true.
|
/// return false. Otherwise, reduce the PP, and return true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool TryUse(byte amount) => Interface.learned_move_try_use(Ptr, amount) == 1;
|
public bool TryUse(byte amount) => Interface.learned_move_try_use(Handle, amount) == 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the remaining PP to the max amount of PP.
|
/// Set the remaining PP to the max amount of PP.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RestoreAllUses() => Interface.learned_move_restore_all_uses(Ptr);
|
public void RestoreAllUses() => Interface.learned_move_restore_all_uses(Handle);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
|
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RestoreUses(byte amount) => Interface.learned_move_restore_uses(Ptr, amount);
|
public void RestoreUses(byte amount) => Interface.learned_move_restore_uses(Handle, amount);
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
protected override void Destructor() => Interface.learned_move_drop(Ptr);
|
|
||||||
|
|
||||||
~LearnedMove()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MoveLearnMethod : byte
|
public enum MoveLearnMethod : byte
|
||||||
|
|
|
@ -4,19 +4,19 @@ using Interface = PkmnLibSharp.FFI.DynamicData.Libraries.BattleStatCalculator;
|
||||||
|
|
||||||
namespace PkmnLibSharp.DynamicData.Libraries
|
namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
public abstract class BattleStatCalculator : ExternPointer<object>
|
public abstract class BattleStatCalculator : HandleType
|
||||||
{
|
{
|
||||||
protected BattleStatCalculator(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner){}
|
protected BattleStatCalculator(FFIHandle handle) : base(handle){}
|
||||||
|
|
||||||
protected override object CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.battle_stat_calculator_drop(Ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Gen7BattleStatCalculator : BattleStatCalculator
|
public class Gen7BattleStatCalculator : BattleStatCalculator
|
||||||
{
|
{
|
||||||
public Gen7BattleStatCalculator() : base(Interface.gen_7_battle_stat_calculator_new(), true)
|
protected Gen7BattleStatCalculator(FFIHandle handle) : base(handle){}
|
||||||
|
|
||||||
|
public static Gen7BattleStatCalculator Create()
|
||||||
{
|
{
|
||||||
|
var handle = Interface.gen_7_battle_stat_calculator_new();
|
||||||
|
return Resolver.Instance.ResolveGen7BattleStatCalculator(handle.Resolve());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,22 +4,23 @@ using Interface = PkmnLibSharp.FFI.DynamicData.Libraries.DamageLibrary;
|
||||||
|
|
||||||
namespace PkmnLibSharp.DynamicData.Libraries
|
namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
public abstract class DamageLibrary : ExternPointer<object>
|
public abstract class DamageLibrary : HandleType
|
||||||
{
|
{
|
||||||
protected DamageLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
protected DamageLibrary(FFIHandle ptr) : base(ptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override object CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.damage_library_drop(Ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Gen7DamageLibrary : DamageLibrary
|
public class Gen7DamageLibrary : DamageLibrary
|
||||||
{
|
{
|
||||||
public Gen7DamageLibrary(bool hasRandomness) : base(
|
public Gen7DamageLibrary(FFIHandle ptr) : base(ptr)
|
||||||
Interface.gen_7_damage_library_new((byte)(hasRandomness ? 1 : 0)), true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Gen7DamageLibrary Create(bool hasRandomness)
|
||||||
|
{
|
||||||
|
var handle = Interface.gen_7_damage_library_new((byte)(hasRandomness ? 1 : 0));
|
||||||
|
return Resolver.Instance.ResolveGen7DamageLibrary(handle.Resolve());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,31 +4,23 @@ using Interface = PkmnLibSharp.FFI.DynamicData.Libraries.DynamicLibrary;
|
||||||
|
|
||||||
namespace PkmnLibSharp.DynamicData.Libraries
|
namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
public class DynamicLibrary : ExternPointer<DynamicLibrary.CacheData>
|
public class DynamicLibrary : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected DynamicLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
|
||||||
public StaticData.Libraries.StaticData? StaticData { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal DynamicLibrary(IdentifiablePointer ptr) : base(ptr, false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicLibrary(StaticData.Libraries.StaticData staticData, BattleStatCalculator statCalculator,
|
public static DynamicLibrary Create(StaticData.Libraries.StaticData staticData,
|
||||||
DamageLibrary damageLibrary, MiscLibrary miscLibrary, ScriptResolver scriptResolver) : base(
|
BattleStatCalculator statCalculator, DamageLibrary damageLibrary, MiscLibrary miscLibrary,
|
||||||
Interface.dynamic_library_new(staticData.TakeOwnershipAndInvalidate(),
|
ScriptResolver scriptResolver)
|
||||||
statCalculator.TakeOwnershipAndInvalidate(), damageLibrary.TakeOwnershipAndInvalidate(),
|
|
||||||
miscLibrary.TakeOwnershipAndInvalidate(), scriptResolver.TakeOwnershipAndInvalidate()), true)
|
|
||||||
{
|
{
|
||||||
|
var handle = Interface.dynamic_library_new(staticData.Handle, statCalculator.Handle, damageLibrary.Handle,
|
||||||
|
miscLibrary.Handle, scriptResolver.Handle);
|
||||||
|
var lib = Resolver.Instance.ResolveDynamicLibrary(handle.Resolve());
|
||||||
|
lib.StaticData = staticData;
|
||||||
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StaticData.Libraries.StaticData StaticData =>
|
public StaticData.Libraries.StaticData StaticData { get; private set; } = null!;
|
||||||
Cache.StaticData ??=
|
|
||||||
new StaticData.Libraries.StaticData(Interface.dynamic_library_get_static_data(Ptr), false);
|
|
||||||
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
protected override void Destructor() => Interface.dynamic_library_drop(Ptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,21 +4,23 @@ using Interface = PkmnLibSharp.FFI.DynamicData.Libraries.MiscLibrary;
|
||||||
|
|
||||||
namespace PkmnLibSharp.DynamicData.Libraries
|
namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
public abstract class MiscLibrary : ExternPointer<object>
|
public abstract class MiscLibrary : HandleType
|
||||||
{
|
{
|
||||||
protected MiscLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
protected MiscLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override object CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.misc_library_drop(Ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Gen7MiscLibrary : MiscLibrary
|
public class Gen7MiscLibrary : MiscLibrary
|
||||||
{
|
{
|
||||||
public Gen7MiscLibrary() : base(Interface.gen_7_misc_library_new(), true)
|
protected Gen7MiscLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Gen7MiscLibrary Create()
|
||||||
|
{
|
||||||
|
var handle = Interface.gen_7_misc_library_new();
|
||||||
|
return Resolver.Instance.ResolveGen7MiscLibrary(handle.Resolve());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,19 +5,9 @@ using Interface = PkmnLibSharp.FFI.DynamicData.Libraries.ScriptResolver;
|
||||||
|
|
||||||
namespace PkmnLibSharp.DynamicData.Libraries
|
namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
public abstract class ScriptResolver : ExternPointer<ScriptResolver.CacheData>
|
public abstract class ScriptResolver : HandleType
|
||||||
{
|
{
|
||||||
protected ScriptResolver(IdentifiablePointer ptr) : base(ptr, true){}
|
protected ScriptResolver(FFIHandle handle) : base(handle){}
|
||||||
protected ScriptResolver(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner){}
|
|
||||||
|
|
||||||
public class CacheData{}
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
Interface.script_resolver_drop(Ptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -25,6 +15,12 @@ namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EmptyScriptResolver : ScriptResolver
|
public class EmptyScriptResolver : ScriptResolver
|
||||||
{
|
{
|
||||||
public EmptyScriptResolver() : base(Interface.empty_script_resolver_new()){}
|
protected EmptyScriptResolver(FFIHandle handle) : base(handle){}
|
||||||
|
|
||||||
|
public static EmptyScriptResolver Create()
|
||||||
|
{
|
||||||
|
var handle = Interface.empty_script_resolver_new();
|
||||||
|
return Resolver.Instance.ResolveEmptyScriptResolver(handle.Resolve());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,15 @@ namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
public class WasmScriptResolver : ScriptResolver
|
public class WasmScriptResolver : ScriptResolver
|
||||||
{
|
{
|
||||||
public WasmScriptResolver() : base(Interface.webassembly_script_resolver_new(), true){}
|
protected WasmScriptResolver(FFIHandle handle) : base(handle)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WasmScriptResolver Create()
|
||||||
|
{
|
||||||
|
var handle = Interface.webassembly_script_resolver_new();
|
||||||
|
return Resolver.Instance.ResolveWasmScriptResolver(handle.Resolve());
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads a compiled WASM module into the script resolver.
|
/// Loads a compiled WASM module into the script resolver.
|
||||||
|
@ -14,7 +22,8 @@ namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
/// <param name="data">The bytes of a compiled WASM module</param>
|
/// <param name="data">The bytes of a compiled WASM module</param>
|
||||||
public void LoadBytes(byte[] data)
|
public void LoadBytes(byte[] data)
|
||||||
{
|
{
|
||||||
Interface.webassembly_script_resolver_load_wasm_from_bytes(Ptr, data.ArrayPtr(), (ulong)data.LongLength);
|
Interface.webassembly_script_resolver_load_wasm_from_bytes(Handle, data.ArrayPtr(), (ulong)data.LongLength)
|
||||||
|
.Result();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -23,7 +32,7 @@ namespace PkmnLibSharp.DynamicData.Libraries
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void FinalizeResolver()
|
public void FinalizeResolver()
|
||||||
{
|
{
|
||||||
Interface.webassembly_script_resolver_finalize(Ptr);
|
Interface.webassembly_script_resolver_finalize(Handle).Result();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,144 +8,148 @@ using Species = PkmnLibSharp.StaticData.Species;
|
||||||
|
|
||||||
namespace PkmnLibSharp.DynamicData
|
namespace PkmnLibSharp.DynamicData
|
||||||
{
|
{
|
||||||
public class Pokemon : ExternPointer<Pokemon.CacheData>
|
public class Pokemon : HandleType
|
||||||
{
|
{
|
||||||
public Pokemon(DynamicLibrary dynamicLibrary, Species species, Form form, bool hiddenAbility, byte abilityIndex,
|
protected Pokemon(FFIHandle handle) : base(handle){}
|
||||||
LevelInt level, uint uid, Gender gender, byte coloring, string nature) : base(
|
|
||||||
Interface.pokemon_new(dynamicLibrary.Ptr, species.Ptr, form.Ptr, hiddenAbility.ForeignBool(), abilityIndex,
|
public static Pokemon Create(DynamicLibrary dynamicLibrary, Species species, Form form, bool hiddenAbility, byte abilityIndex,
|
||||||
level, uid, gender, coloring, nature.ToPtr()), true)
|
LevelInt level, uint uid, Gender gender, byte coloring, string nature)
|
||||||
{
|
{
|
||||||
|
var handle = Interface.pokemon_new(dynamicLibrary.Handle, species.Handle, form.Handle, hiddenAbility.ForeignBool(),
|
||||||
|
abilityIndex, level, uid, gender, coloring, nature.ToPtr())
|
||||||
|
.Result();
|
||||||
|
return Resolver.Instance.ResolvePokemon(handle.Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DynamicLibrary? _library;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The library data the Pokemon uses.
|
/// The library data the Pokemon uses.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DynamicLibrary Library => Cache.DynamicLibrary ??= new DynamicLibrary(Interface.pokemon_library(Ptr));
|
public DynamicLibrary Library =>
|
||||||
|
_library ??= Resolver.Instance.ResolveDynamicLibrary(Interface.pokemon_library(Handle).Resolve());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The species of the Pokemon.
|
/// The species of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Species Species => new(Interface.pokemon_species(Ptr));
|
public Species Species => Resolver.Instance.ResolveSpecies(Interface.pokemon_species(Handle).Resolve());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The form of the Pokemon.
|
/// The form of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Form Form => new(Interface.pokemon_form(Ptr));
|
public Form Form => Resolver.Instance.ResolveForm(Interface.pokemon_form(Handle).Resolve());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The species that should be displayed to the user. This handles stuff like the Illusion ability.
|
/// The species that should be displayed to the user. This handles stuff like the Illusion ability.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Species DisplaySpecies => new(Interface.pokemon_display_species(Ptr));
|
public Species DisplaySpecies =>
|
||||||
|
Resolver.Instance.ResolveSpecies(Interface.pokemon_display_species(Handle).Resolve());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The form that should be displayed to the user. This handles stuff like the Illusion ability.
|
/// The form that should be displayed to the user. This handles stuff like the Illusion ability.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Form DisplayForm => new(Interface.pokemon_display_form(Ptr));
|
public Form DisplayForm => Resolver.Instance.ResolveForm(Interface.pokemon_display_form(Handle).Resolve());
|
||||||
|
|
||||||
public LevelInt Level => Interface.pokemon_level(Ptr);
|
public LevelInt Level => Interface.pokemon_level(Handle);
|
||||||
public uint Experience => Interface.pokemon_experience(Ptr);
|
public uint Experience => Interface.pokemon_experience(Handle);
|
||||||
public uint UniqueIdentifier => Interface.pokemon_unique_identifier(Ptr);
|
public uint UniqueIdentifier => Interface.pokemon_unique_identifier(Handle);
|
||||||
public Gender Gender => Interface.pokemon_gender(Ptr);
|
public Gender Gender => Interface.pokemon_gender(Handle);
|
||||||
public byte Coloring => Interface.pokemon_coloring(Ptr);
|
public byte Coloring => Interface.pokemon_coloring(Handle);
|
||||||
public bool IsShiny => Coloring == 1;
|
public bool IsShiny => Coloring == 1;
|
||||||
|
|
||||||
public Item? HeldItem
|
public Item? HeldItem
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var ptr = Interface.pokemon_held_item(Ptr);
|
var ptr = Interface.pokemon_held_item(Handle);
|
||||||
return ptr.IsNull ? null : new Item(ptr);
|
return ptr.IsNull ? null : Resolver.Instance.ResolveItem(ptr.Resolve());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasHeldItem(string name) => Interface.pokemon_has_held_item(Ptr, name.ToPtr()) == 1;
|
public bool HasHeldItem(string name) => Interface.pokemon_has_held_item(Handle, name.ToPtr()) == 1;
|
||||||
|
|
||||||
public void SetHeldItem(Item? item)
|
public void SetHeldItem(Item? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
RemoveHeldItem();
|
RemoveHeldItem();
|
||||||
else
|
else
|
||||||
Interface.pokemon_set_held_item(Ptr, item.Ptr);
|
Interface.pokemon_set_held_item(Handle, item.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveHeldItem() => Interface.pokemon_remove_held_item(Ptr);
|
public void RemoveHeldItem() => Interface.pokemon_remove_held_item(Handle);
|
||||||
|
|
||||||
public bool ConsumeHeldItem() => Interface.pokemon_consume_held_item(Ptr) == 1;
|
public bool ConsumeHeldItem() => Interface.pokemon_consume_held_item(Handle).Result() == 1;
|
||||||
|
|
||||||
public uint CurrentHealth => Interface.pokemon_current_health(Ptr);
|
public uint CurrentHealth => Interface.pokemon_current_health(Handle);
|
||||||
public uint MaxHealth => Interface.pokemon_max_health(Ptr);
|
public uint MaxHealth => Interface.pokemon_max_health(Handle);
|
||||||
public float Weight => Interface.pokemon_weight(Ptr);
|
public float Weight => Interface.pokemon_weight(Handle);
|
||||||
public float Height => Interface.pokemon_height(Ptr);
|
public float Height => Interface.pokemon_height(Handle);
|
||||||
|
|
||||||
public string? Nickname => Interface.pokemon_nickname(Ptr).PtrString();
|
public string? Nickname => Interface.pokemon_nickname(Handle).Result().PtrString();
|
||||||
public bool HasHiddenAbility => Interface.pokemon_real_ability_is_hidden(Ptr) == 1;
|
public bool HasHiddenAbility => Interface.pokemon_real_ability_is_hidden(Handle) == 1;
|
||||||
public byte AbilityIndex => Interface.pokemon_real_ability_index(Ptr);
|
public byte AbilityIndex => Interface.pokemon_real_ability_index(Handle);
|
||||||
|
|
||||||
|
private ExternValueArray<TypeIdentifier>? _types;
|
||||||
public ExternValueArray<TypeIdentifier> Types =>
|
public ExternValueArray<TypeIdentifier> Types =>
|
||||||
Cache.Types ??= new ExternValueArray<TypeIdentifier>(() => Interface.pokemon_types_length(Ptr),
|
_types ??= new ExternValueArray<TypeIdentifier>(() => Interface.pokemon_types_length(Handle),
|
||||||
arg => Interface.pokemon_types_get(Ptr, arg));
|
arg => Interface.pokemon_types_get(Handle, arg).Result());
|
||||||
|
|
||||||
public LearnedMove? LearnedMove(ulong index)
|
public LearnedMove? LearnedMove(ulong index)
|
||||||
{
|
{
|
||||||
var ptr = Interface.pokemon_learned_move_get(Ptr, index);
|
var ptr = Interface.pokemon_learned_move_get(Handle, index);
|
||||||
return ptr.IsNull ? null : new LearnedMove(ptr, false);
|
return ptr.IsNull ? null : Resolver.Instance.ResolveLearnedMove(ptr.Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StatisticSet<uint>? _flatStats;
|
||||||
public StatisticSet<uint> FlatStats =>
|
public StatisticSet<uint> FlatStats =>
|
||||||
Cache.FlatStats ??= new StatisticSet<uint>(Interface.pokemon_flat_stats(Ptr), false);
|
_flatStats ??=
|
||||||
|
Resolver.Instance.ResolveStatisticSet<uint>(Interface.pokemon_flat_stats(Handle).Resolve());
|
||||||
|
|
||||||
|
private StatisticSet<uint>? _boostedStats;
|
||||||
public StatisticSet<uint> BoostedStats =>
|
public StatisticSet<uint> BoostedStats =>
|
||||||
Cache.BoostedStats ??= new StatisticSet<uint>(Interface.pokemon_boosted_stats(Ptr), false);
|
_boostedStats ??=
|
||||||
|
Resolver.Instance.ResolveStatisticSet<uint>(Interface.pokemon_boosted_stats(Handle).Resolve());
|
||||||
|
|
||||||
public sbyte GetStatBoost(Statistic statistic) => Interface.pokemon_get_stat_boost(Ptr, statistic);
|
public sbyte GetStatBoost(Statistic statistic) => Interface.pokemon_get_stat_boost(Handle, statistic);
|
||||||
public byte GetIndividualValue(Statistic statistic) => Interface.pokemon_get_individual_value(Ptr, statistic);
|
public byte GetIndividualValue(Statistic statistic) => Interface.pokemon_get_individual_value(Handle, statistic);
|
||||||
public byte GetEffortValue(Statistic statistic) => Interface.pokemon_get_effort_value(Ptr, statistic);
|
public byte GetEffortValue(Statistic statistic) => Interface.pokemon_get_effort_value(Handle, statistic);
|
||||||
|
|
||||||
public void SetIndividualValue(Statistic statistic, byte value) =>
|
public void SetIndividualValue(Statistic statistic, byte value) =>
|
||||||
Interface.pokemon_set_individual_value(Ptr, statistic, value);
|
Interface.pokemon_set_individual_value(Handle, statistic, value).Result();
|
||||||
|
|
||||||
public void SetEffortValue(Statistic statistic, byte value) =>
|
public void SetEffortValue(Statistic statistic, byte value) =>
|
||||||
Interface.pokemon_set_effort_value(Ptr, statistic, value);
|
Interface.pokemon_set_effort_value(Handle, statistic, value).Result();
|
||||||
|
|
||||||
// TODO: Battle getter
|
// TODO: Battle getter
|
||||||
public byte BattleSideIndex => Interface.pokemon_get_battle_side_index(Ptr);
|
public byte BattleSideIndex => Interface.pokemon_get_battle_side_index(Handle);
|
||||||
public byte BattleIndex => Interface.pokemon_get_battle_index(Ptr);
|
public byte BattleIndex => Interface.pokemon_get_battle_index(Handle);
|
||||||
public bool IsAbilityOverriden => Interface.pokemon_is_ability_overriden(Ptr) == 1;
|
public bool IsAbilityOverriden => Interface.pokemon_is_ability_overriden(Handle) == 1;
|
||||||
public Ability ActiveAbility => new(Interface.pokemon_active_ability(Ptr));
|
|
||||||
public bool AllowedExperienceGain => Interface.pokemon_allowed_experience_gain(Ptr) == 1;
|
|
||||||
public Nature Nature => new(Interface.pokemon_nature(Ptr));
|
|
||||||
|
|
||||||
public void RecalculateFlatStats() => Interface.pokemon_recalculate_flat_stats(Ptr);
|
public Ability ActiveAbility =>
|
||||||
public void RecalculateBoostedStats() => Interface.pokemon_recalculate_boosted_stats(Ptr);
|
Resolver.Instance.ResolveAbility(Interface.pokemon_active_ability(Handle).Result().Resolve());
|
||||||
|
|
||||||
|
public bool AllowedExperienceGain => Interface.pokemon_allowed_experience_gain(Handle) == 1;
|
||||||
|
public Nature Nature => Resolver.Instance.ResolveNature(Interface.pokemon_nature(Handle).Resolve());
|
||||||
|
|
||||||
|
public void RecalculateFlatStats() => Interface.pokemon_recalculate_flat_stats(Handle).Result();
|
||||||
|
public void RecalculateBoostedStats() => Interface.pokemon_recalculate_boosted_stats(Handle).Result();
|
||||||
|
|
||||||
public void ChangeSpecies(Species species, Form form) =>
|
public void ChangeSpecies(Species species, Form form) =>
|
||||||
Interface.pokemon_change_species(Ptr, species.Ptr, form.Ptr);
|
Interface.pokemon_change_species(Handle, species.Handle, form.Handle).Result();
|
||||||
|
|
||||||
public void ChangeForm(Form form) => Interface.pokemon_change_form(Ptr, form.Ptr);
|
public void ChangeForm(Form form) => Interface.pokemon_change_form(Handle, form.Handle).Result();
|
||||||
|
|
||||||
public bool IsUsable => Interface.pokemon_is_usable(Ptr) == 1;
|
public bool IsUsable => Interface.pokemon_is_usable(Handle) == 1;
|
||||||
public bool IsFainted => Interface.pokemon_is_fainted(Ptr) == 1;
|
public bool IsFainted => Interface.pokemon_is_fainted(Handle) == 1;
|
||||||
public bool IsOnBattleField => Interface.pokemon_is_on_battlefield(Ptr) == 1;
|
public bool IsOnBattleField => Interface.pokemon_is_on_battlefield(Handle) == 1;
|
||||||
|
|
||||||
public void Damage(uint amount, DamageSource source) => Interface.pokemon_damage(Ptr, amount, source);
|
public void Damage(uint amount, DamageSource source) => Interface.pokemon_damage(Handle, amount, source).Result();
|
||||||
|
|
||||||
public bool Heal(uint amount, bool allowRevive) =>
|
public bool Heal(uint amount, bool allowRevive) =>
|
||||||
Interface.pokemon_heal(Ptr, amount, allowRevive.ForeignBool()) == 1;
|
Interface.pokemon_heal(Handle, amount, allowRevive.ForeignBool()) == 1;
|
||||||
|
|
||||||
public void LearnMove(string moveName, MoveLearnMethod learnMethod) =>
|
public void LearnMove(string moveName, MoveLearnMethod learnMethod) =>
|
||||||
Interface.pokemon_learn_move(Ptr, moveName.ToPtr(), learnMethod);
|
Interface.pokemon_learn_move(Handle, moveName.ToPtr(), learnMethod).Result();
|
||||||
|
|
||||||
public void ClearStatus() => Interface.pokemon_clear_status(Ptr);
|
public void ClearStatus() => Interface.pokemon_clear_status(Handle);
|
||||||
|
|
||||||
public class CacheData
|
|
||||||
{
|
|
||||||
public DynamicLibrary? DynamicLibrary { get; set; }
|
|
||||||
public ExternValueArray<TypeIdentifier>? Types { get; set; }
|
|
||||||
public StatisticSet<uint>? FlatStats { get; set; }
|
|
||||||
public StatisticSet<uint>? BoostedStats { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
protected override void Destructor() => Interface.pokemon_drop(Ptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -88,7 +88,7 @@ namespace PkmnLibSharp.DynamicData
|
||||||
|
|
||||||
protected virtual Pokemon Finalize(Species species, Form form, Item? heldItem)
|
protected virtual Pokemon Finalize(Species species, Form form, Item? heldItem)
|
||||||
{
|
{
|
||||||
var pokemon = new Pokemon(_library, species, form, _hiddenAbility, _abilityIndex, _level,
|
var pokemon = Pokemon.Create(_library, species, form, _hiddenAbility, _abilityIndex, _level,
|
||||||
_identifier ?? (uint)_random.Next(), _gender!.Value, _coloring, _natureName!);
|
_identifier ?? (uint)_random.Next(), _gender!.Value, _coloring, _natureName!);
|
||||||
if (heldItem != null)
|
if (heldItem != null)
|
||||||
pokemon.SetHeldItem(heldItem);
|
pokemon.SetHeldItem(heldItem);
|
||||||
|
@ -96,7 +96,7 @@ namespace PkmnLibSharp.DynamicData
|
||||||
{
|
{
|
||||||
pokemon.LearnMove(move.name, move.method);
|
pokemon.LearnMove(move.name, move.method);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pokemon;
|
return pokemon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ namespace PkmnLibSharp.DynamicData
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(_natureName))
|
if (string.IsNullOrEmpty(_natureName))
|
||||||
{
|
{
|
||||||
using var nature = _library.StaticData.NatureLibrary.GetRandomNature((ulong)_randomSeed);
|
var nature = _library.StaticData.NatureLibrary.GetRandomNature((ulong)_randomSeed);
|
||||||
_natureName = _library.StaticData.NatureLibrary.GetNatureName(nature);
|
_natureName = _library.StaticData.NatureLibrary.GetNatureName(nature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.DynamicData;
|
using PkmnLibSharp.DynamicData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.DynamicData
|
namespace PkmnLibSharp.FFI.DynamicData
|
||||||
{
|
{
|
||||||
|
@ -10,55 +11,49 @@ namespace PkmnLibSharp.FFI.DynamicData
|
||||||
/// Instantiate a new learned move.
|
/// Instantiate a new learned move.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer learned_move_new(IntPtr move, MoveLearnMethod learnMethod);
|
internal static extern FFIHandleValue learned_move_new(FFIHandleValue move, MoveLearnMethod learnMethod);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Drops a learned move.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void learned_move_drop(IntPtr value);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The immutable move information of the move.
|
/// The immutable move information of the move.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer learned_move_move_data(IntPtr value);
|
internal static extern FFIHandleValue learned_move_move_data(FFIHandleValue value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximal power points for this move.
|
/// The maximal power points for this move.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte learned_move_max_pp(IntPtr value);
|
internal static extern byte learned_move_max_pp(FFIHandleValue value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of remaining power points. If this is 0, we can not use the move anymore.
|
/// The amount of remaining power points. If this is 0, we can not use the move anymore.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte learned_move_remaining_pp(IntPtr value);
|
internal static extern byte learned_move_remaining_pp(FFIHandleValue value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The way the move was learned.
|
/// The way the move was learned.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern MoveLearnMethod learned_move_learn_method(IntPtr value);
|
internal static extern MoveLearnMethod learned_move_learn_method(FFIHandleValue value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Try and reduce the PP by a certain amount. If the amount is higher than the current uses,
|
/// Try and reduce the PP by a certain amount. If the amount is higher than the current uses,
|
||||||
/// return 0. Otherwise, reduce the PP, and return 1.
|
/// return 0. Otherwise, reduce the PP, and return 1.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte learned_move_try_use(IntPtr value, byte amount);
|
internal static extern byte learned_move_try_use(FFIHandleValue value, byte amount);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the remaining PP to the max amount of PP.
|
/// Set the remaining PP to the max amount of PP.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void learned_move_restore_all_uses(IntPtr value);
|
internal static extern void learned_move_restore_all_uses(FFIHandleValue value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
|
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void learned_move_restore_uses(IntPtr value, byte amount);
|
internal static extern void learned_move_restore_uses(FFIHandleValue value, byte amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.DynamicData;
|
using PkmnLibSharp.DynamicData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
|
@ -10,13 +11,6 @@ namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
/// Creates a new Gen 7 battle stat calculator
|
/// Creates a new Gen 7 battle stat calculator
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer gen_7_battle_stat_calculator_new();
|
internal static extern FFIHandleValue gen_7_battle_stat_calculator_new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new Gen 7 battle stat calculator
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void battle_stat_calculator_drop(IntPtr ptr);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
|
@ -11,12 +12,6 @@ namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
/// <param name="hasRandomness">whether or not a random damage modifier (0.85x - 1.00x) is applied to the
|
/// <param name="hasRandomness">whether or not a random damage modifier (0.85x - 1.00x) is applied to the
|
||||||
/// calculated damage. 0 for not, 1 for true</param>
|
/// calculated damage. 0 for not, 1 for true</param>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer gen_7_damage_library_new(byte hasRandomness);
|
internal static extern FFIHandleValue gen_7_damage_library_new(byte hasRandomness);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Drops a DamageLibrary.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void damage_library_drop(IntPtr ptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
|
@ -9,20 +10,14 @@ namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
/// Instantiates a new DynamicLibrary with given parameters.
|
/// Instantiates a new DynamicLibrary with given parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer dynamic_library_new(IntPtr staticData, IntPtr statCalculator,
|
internal static extern FFIHandleValue dynamic_library_new(FFIHandleValue staticData, FFIHandleValue statCalculator,
|
||||||
IntPtr damageLibrary, IntPtr miscLibrary, IntPtr scriptResolver);
|
FFIHandleValue damageLibrary, FFIHandleValue miscLibrary, FFIHandleValue scriptResolver);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Drops a dynamic library.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void dynamic_library_drop(IntPtr dynamicLibrary);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The static data is the immutable storage data for this library.
|
/// The static data is the immutable storage data for this library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer dynamic_library_get_static_data(IntPtr dynamicLibrary);
|
internal static extern FFIHandleValue dynamic_library_get_static_data(FFIHandleValue dynamicLibrary);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
|
@ -9,12 +10,6 @@ namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
/// Instantiates a new MiscLibrary.
|
/// Instantiates a new MiscLibrary.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer gen_7_misc_library_new();
|
internal static extern FFIHandleValue gen_7_misc_library_new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Drops a MiscLibrary.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void misc_library_drop(IntPtr ptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
{
|
{
|
||||||
|
@ -9,14 +11,8 @@ namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
/// Instantiates a basic empty script resolver, that always returns None.
|
/// Instantiates a basic empty script resolver, that always returns None.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer empty_script_resolver_new();
|
internal static extern FFIHandleValue empty_script_resolver_new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Drops a script resolver.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void script_resolver_drop(IntPtr ptr);
|
|
||||||
|
|
||||||
// WASM is a feature flag in the crate, and can be disabled. If disabled, these entry points do not exist. In
|
// WASM is a feature flag in the crate, and can be disabled. If disabled, these entry points do not exist. In
|
||||||
// this case it's recommended to remove the WASM compile flag from the csproj as well.
|
// this case it's recommended to remove the WASM compile flag from the csproj as well.
|
||||||
#if WASM
|
#if WASM
|
||||||
|
@ -24,20 +20,22 @@ namespace PkmnLibSharp.FFI.DynamicData.Libraries
|
||||||
/// Instantiates a new WebAssemblyScriptResolver.
|
/// Instantiates a new WebAssemblyScriptResolver.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer webassembly_script_resolver_new();
|
internal static extern FFIHandleValue webassembly_script_resolver_new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load a compiled WASM module.
|
/// Load a compiled WASM module.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void webassembly_script_resolver_load_wasm_from_bytes(IntPtr resolver, IntPtr byteArray,
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult webassembly_script_resolver_load_wasm_from_bytes(FFIHandleValue resolver, IntPtr byteArray,
|
||||||
ulong arrayLength);
|
ulong arrayLength);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tells the script resolver we're done loading wasm modules, and to finalize the resolver.
|
/// Tells the script resolver we're done loading wasm modules, and to finalize the resolver.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void webassembly_script_resolver_finalize(IntPtr resolver);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult webassembly_script_resolver_finalize(FFIHandleValue resolver);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using PkmnLibSharp.DynamicData;
|
using PkmnLibSharp.DynamicData;
|
||||||
using PkmnLibSharp.FFI.StaticData;
|
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.DynamicData
|
namespace PkmnLibSharp.FFI.DynamicData
|
||||||
{
|
{
|
||||||
|
@ -12,227 +13,223 @@ namespace PkmnLibSharp.FFI.DynamicData
|
||||||
/// Instantiates a new Pokemon.
|
/// Instantiates a new Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_new(IntPtr dynamicLibrary, IntPtr species, IntPtr form,
|
internal static extern NativeResult<FFIHandleValue> pokemon_new(FFIHandleValue dynamicLibrary,
|
||||||
byte hiddenAbility, byte abilityIndex, LevelInt level, uint uniqueIdentifier, Gender gender, byte coloring,
|
FFIHandleValue species, FFIHandleValue form, byte hiddenAbility, byte abilityIndex, LevelInt level,
|
||||||
IntPtr natureName);
|
uint uniqueIdentifier, Gender gender, byte coloring, IntPtr natureName);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Drops an Arc reference held by the FFI.
|
|
||||||
/// </summary>
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void pokemon_drop(IntPtr pokemon);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The library data of the Pokemon.
|
/// The library data of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_library(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_library(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The species of the Pokemon.
|
/// The species of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_species(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_species(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The form of the Pokemon.
|
/// The form of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_form(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_form(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The species that should be displayed to the user. This handles stuff like the Illusion ability.
|
/// The species that should be displayed to the user. This handles stuff like the Illusion ability.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_display_species(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_display_species(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The form that should be displayed to the user. This handles stuff like the Illusion ability.
|
/// The form that should be displayed to the user. This handles stuff like the Illusion ability.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_display_form(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_display_form(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern LevelInt pokemon_level(IntPtr pokemon);
|
internal static extern LevelInt pokemon_level(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern uint pokemon_experience(IntPtr pokemon);
|
internal static extern uint pokemon_experience(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern uint pokemon_unique_identifier(IntPtr pokemon);
|
internal static extern uint pokemon_unique_identifier(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern Gender pokemon_gender(IntPtr pokemon);
|
internal static extern Gender pokemon_gender(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_coloring(IntPtr pokemon);
|
internal static extern byte pokemon_coloring(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the held item of a Pokemon
|
/// Gets the held item of a Pokemon
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_held_item(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_held_item(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether the Pokemon is holding a specific item.
|
/// Checks whether the Pokemon is holding a specific item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_has_held_item(IntPtr pokemon, IntPtr itemName);
|
internal static extern byte pokemon_has_held_item(FFIHandleValue pokemon, IntPtr itemName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Changes the held item of the Pokemon. Returns the previously held item.
|
/// Changes the held item of the Pokemon. Returns the previously held item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_set_held_item(IntPtr pokemon, IntPtr item);
|
internal static extern IdentifiablePointer pokemon_set_held_item(FFIHandleValue pokemon, FFIHandle item);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the held item from the Pokemon. Returns the previously held item.
|
/// Removes the held item from the Pokemon. Returns the previously held item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_remove_held_item(IntPtr pokemon);
|
internal static extern IdentifiablePointer pokemon_remove_held_item(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Makes the Pokemon uses its held item.
|
/// Makes the Pokemon uses its held item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_consume_held_item(IntPtr pokemon);
|
internal static extern NativeResult<byte> pokemon_consume_held_item(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern uint pokemon_current_health(IntPtr pokemon);
|
internal static extern uint pokemon_current_health(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern uint pokemon_max_health(IntPtr pokemon);
|
internal static extern uint pokemon_max_health(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern float pokemon_weight(IntPtr pokemon);
|
internal static extern float pokemon_weight(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern float pokemon_height(IntPtr pokemon);
|
internal static extern float pokemon_height(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An optional nickname of the Pokemon.
|
/// An optional nickname of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IntPtr pokemon_nickname(IntPtr pokemon);
|
internal static extern NativeResult<IntPtr> pokemon_nickname(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the actual ability on the form is a hidden ability.
|
/// Whether the actual ability on the form is a hidden ability.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_real_ability_is_hidden(IntPtr pokemon);
|
internal static extern byte pokemon_real_ability_is_hidden(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The index of the actual ability on the form.
|
/// The index of the actual ability on the form.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_real_ability_index(IntPtr pokemon);
|
internal static extern byte pokemon_real_ability_index(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern ulong pokemon_types_length(IntPtr pokemon);
|
internal static extern ulong pokemon_types_length(FFIHandleValue pokemon);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern TypeIdentifier pokemon_types_get(IntPtr pokemon, ulong index);
|
internal static extern NativeResult<TypeIdentifier> pokemon_types_get(FFIHandleValue pokemon, ulong index);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a learned move of the Pokemon. Index should generally be below [`MAX_MOVES`], you will get
|
/// Gets a learned move of the Pokemon. Index should generally be below [`MAX_MOVES`], you will get
|
||||||
/// a null pointer otherwise.
|
/// a null pointer otherwise.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_learned_move_get(IntPtr pokemon, ulong index);
|
internal static extern FFIHandleValue pokemon_learned_move_get(FFIHandleValue pokemon, ulong index);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The stats of the Pokemon when disregarding any stat boosts.
|
/// The stats of the Pokemon when disregarding any stat boosts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_flat_stats(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_flat_stats(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The stats of the Pokemon including the stat boosts.
|
/// The stats of the Pokemon including the stat boosts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_boosted_stats(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_boosted_stats(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the stat boosts for a specific stat.
|
/// Get the stat boosts for a specific stat.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern sbyte pokemon_get_stat_boost(IntPtr pokemon, Statistic statistic);
|
internal static extern sbyte pokemon_get_stat_boost(FFIHandleValue pokemon, Statistic statistic);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Change a boosted stat by a certain amount.
|
/// Change a boosted stat by a certain amount.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern sbyte pokemon_change_stat_boost(IntPtr pokemon, Statistic statistic, sbyte diffAmount,
|
internal static extern NativeResult<sbyte> pokemon_change_stat_boost(FFIHandleValue pokemon, Statistic statistic, sbyte diffAmount,
|
||||||
byte selfInflicted);
|
byte selfInflicted);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a <a href="https://bulbapedia.bulbagarden.net/wiki/Individual_values">individual value</a> of the Pokemon.
|
/// Gets a <a href="https://bulbapedia.bulbagarden.net/wiki/Individual_values">individual value</a> of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_get_individual_value(IntPtr pokemon, Statistic statistic);
|
internal static extern byte pokemon_get_individual_value(FFIHandleValue pokemon, Statistic statistic);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Modifies a <a href="https://bulbapedia.bulbagarden.net/wiki/Individual_values">individual value</a> of the Pokemon.
|
/// Modifies a <a href="https://bulbapedia.bulbagarden.net/wiki/Individual_values">individual value</a> of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_set_individual_value(IntPtr pokemon, Statistic statistic, byte value);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult pokemon_set_individual_value(FFIHandleValue pokemon, Statistic statistic, byte value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a <a href="https://bulbapedia.bulbagarden.net/wiki/Effort_values">effort value</a> of the Pokemon.
|
/// Gets a <a href="https://bulbapedia.bulbagarden.net/wiki/Effort_values">effort value</a> of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_get_effort_value(IntPtr pokemon, Statistic statistic);
|
internal static extern byte pokemon_get_effort_value(FFIHandleValue pokemon, Statistic statistic);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Modifies a <a href="https://bulbapedia.bulbagarden.net/wiki/Effort_values">effort value</a> of the Pokemon.
|
/// Modifies a <a href="https://bulbapedia.bulbagarden.net/wiki/Effort_values">effort value</a> of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_set_effort_value(IntPtr pokemon, Statistic statistic, byte value);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult pokemon_set_effort_value(FFIHandleValue pokemon, Statistic statistic, byte value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the data for the battle the Pokemon is currently in. If the Pokemon is not in a battle, this
|
/// Gets the data for the battle the Pokemon is currently in. If the Pokemon is not in a battle, this
|
||||||
/// returns null.
|
/// returns null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_get_battle(IntPtr pokemon);
|
internal static extern IdentifiablePointer pokemon_get_battle(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the index of the side of the battle the Pokemon is in. If the Pokemon
|
/// Get the index of the side of the battle the Pokemon is in. If the Pokemon
|
||||||
/// is not on the battlefield, this always returns 0.
|
/// is not on the battlefield, this always returns 0.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_get_battle_side_index(IntPtr pokemon);
|
internal static extern byte pokemon_get_battle_side_index(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the index of the slot on the side of the battle the Pokemon is in. If the Pokemon
|
/// Get the index of the slot on the side of the battle the Pokemon is in. If the Pokemon
|
||||||
/// is not on the battlefield, this always returns 0.
|
/// is not on the battlefield, this always returns 0.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_get_battle_index(IntPtr pokemon);
|
internal static extern byte pokemon_get_battle_index(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether something overrides the ability.
|
/// Returns whether something overrides the ability.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_is_ability_overriden(IntPtr pokemon);
|
internal static extern byte pokemon_is_ability_overriden(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the currently active ability.
|
/// Returns the currently active ability.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_active_ability(IntPtr pokemon);
|
internal static extern NativeResult<FFIHandleValue> pokemon_active_ability(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not the Pokemon is allowed to gain experience.
|
/// Whether or not the Pokemon is allowed to gain experience.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_allowed_experience_gain(IntPtr pokemon);
|
internal static extern byte pokemon_allowed_experience_gain(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <a href="https://bulbapedia.bulbagarden.net/wiki/Nature">nature</a> of the Pokemon.
|
/// The <a href="https://bulbapedia.bulbagarden.net/wiki/Nature">nature</a> of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer pokemon_nature(IntPtr pokemon);
|
internal static extern FFIHandleValue pokemon_nature(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates the flat stats on the Pokemon. This should be called when for example the base
|
/// Calculates the flat stats on the Pokemon. This should be called when for example the base
|
||||||
|
@ -240,67 +237,73 @@ namespace PkmnLibSharp.FFI.DynamicData
|
||||||
/// stats, as those depend on the flat stats.
|
/// stats, as those depend on the flat stats.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_recalculate_flat_stats(IntPtr pokemon);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult pokemon_recalculate_flat_stats(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates the boosted stats on the Pokemon. This should be called when a stat boost changes.
|
/// Calculates the boosted stats on the Pokemon. This should be called when a stat boost changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_recalculate_boosted_stats(IntPtr pokemon);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult pokemon_recalculate_boosted_stats(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Change the species of the Pokemon.
|
/// Change the species of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_change_species(IntPtr pokemon, IntPtr species, IntPtr form);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult pokemon_change_species(FFIHandleValue pokemon, FFIHandleValue species, FFIHandleValue form);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Change the form of the Pokemon.
|
/// Change the form of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_change_form(IntPtr pokemon, IntPtr form);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult pokemon_change_form(FFIHandleValue pokemon, FFIHandleValue form);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not the Pokemon is usable in a battle.
|
/// Whether or not the Pokemon is usable in a battle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_is_usable(IntPtr pokemon);
|
internal static extern byte pokemon_is_usable(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether the Pokemon is fainted.
|
/// Returns whether the Pokemon is fainted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_is_fainted(IntPtr pokemon);
|
internal static extern byte pokemon_is_fainted(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not the Pokemon is on the battlefield.
|
/// Whether or not the Pokemon is on the battlefield.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_is_on_battlefield(IntPtr pokemon);
|
internal static extern byte pokemon_is_on_battlefield(FFIHandleValue pokemon);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Damages the Pokemon by a certain amount of damage, from a damage source.
|
/// Damages the Pokemon by a certain amount of damage, from a damage source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_damage(IntPtr pokemon, uint damage, DamageSource damageSource);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult pokemon_damage(FFIHandleValue pokemon, uint damage, DamageSource damageSource);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Heals the Pokemon by a specific amount. Unless allowRevive is set to 1, this will not
|
/// Heals the Pokemon by a specific amount. Unless allowRevive is set to 1, this will not
|
||||||
/// heal if the Pokemon has 0 health. If the amount healed is 0, this will return false.
|
/// heal if the Pokemon has 0 health. If the amount healed is 0, this will return false.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern byte pokemon_heal(IntPtr pokemon, uint damage, byte allowRevive);
|
internal static extern byte pokemon_heal(FFIHandleValue pokemon, uint damage, byte allowRevive);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Learn a move.
|
/// Learn a move.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_learn_move(IntPtr pokemon, IntPtr moveName, MoveLearnMethod learnMethod);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult pokemon_learn_move(FFIHandleValue pokemon, IntPtr moveName, MoveLearnMethod learnMethod);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the current non-volatile status from the Pokemon.
|
/// Removes the current non-volatile status from the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void pokemon_clear_status(IntPtr pokemon);
|
internal static extern void pokemon_clear_status(FFIHandleValue pokemon);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
|
namespace PkmnLibSharp.FFI
|
||||||
|
{
|
||||||
|
internal struct NativeResult
|
||||||
|
{
|
||||||
|
private readonly IntPtr Error = IntPtr.Zero;
|
||||||
|
|
||||||
|
internal NativeResult(IntPtr error)
|
||||||
|
{
|
||||||
|
Error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Result()
|
||||||
|
{
|
||||||
|
if (Error != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
throw new PkmnLibException(Error.PtrString()!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal struct NativeResult<T> where T : new()
|
||||||
|
{
|
||||||
|
private readonly IntPtr Error = IntPtr.Zero;
|
||||||
|
private readonly T Data = new();
|
||||||
|
|
||||||
|
internal NativeResult(IntPtr error, T data)
|
||||||
|
{
|
||||||
|
Error = error;
|
||||||
|
Data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Result()
|
||||||
|
{
|
||||||
|
if (Error != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
throw new PkmnLibException(Error.PtrString()!);
|
||||||
|
}
|
||||||
|
return Data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PkmnLibException : Exception
|
||||||
|
{
|
||||||
|
internal PkmnLibException(string message) : base(message){}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,26 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class Ability
|
internal static class Ability
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer ability_new(IntPtr name, IntPtr effect, IntPtr parameters, ulong size);
|
internal static extern NativeResult<FFIHandleValue> ability_new(IntPtr name, IntPtr effect, IntPtr parameters, ulong size);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void ability_drop(IntPtr value);
|
internal static extern NativeResult<IntPtr> ability_name(FFIHandleValue handle);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern string ability_name(IntPtr value);
|
internal static extern NativeResult<IntPtr> ability_effect(FFIHandleValue handle);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern string ability_effect(IntPtr value);
|
internal static extern ulong ability_parameter_length(FFIHandleValue handle);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern ulong ability_parameter_length(IntPtr value);
|
internal static extern FFIHandleValue ability_parameter_get(FFIHandleValue handle, ulong index);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IdentifiablePointer ability_parameter_get(IntPtr value, ulong index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,39 +1,37 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class EffectParameter
|
internal static class EffectParameter
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer effect_parameter_new_bool(byte value);
|
internal static extern FFIHandleValue effect_parameter_new_bool(byte value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer effect_parameter_new_int(long value);
|
internal static extern FFIHandleValue effect_parameter_new_int(long value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer effect_parameter_new_float(float value);
|
internal static extern FFIHandleValue effect_parameter_new_float(float value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer effect_parameter_new_string(IntPtr value);
|
internal static extern NativeResult<FFIHandleValue> effect_parameter_new_string(IntPtr value);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
internal static extern byte effect_parameter_get_type(FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void effect_parameter_drop(IntPtr value);
|
internal static extern NativeResult<byte> effect_parameter_get_as_bool(FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern byte effect_parameter_get_type(IntPtr value);
|
internal static extern NativeResult<long> effect_parameter_get_as_int(FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern byte effect_parameter_get_as_bool(IntPtr value);
|
internal static extern NativeResult<float> effect_parameter_get_as_float(FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern long effect_parameter_get_as_int(IntPtr value);
|
internal static extern NativeResult<IntPtr> effect_parameter_get_as_string(FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern float effect_parameter_get_as_float(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern IntPtr effect_parameter_get_as_string(IntPtr value);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,57 +1,55 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class Form
|
internal static class Form
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer form_new(IntPtr name, float height, float weight,
|
internal static extern NativeResult<FFIHandleValue> form_new(IntPtr name, float height, float weight,
|
||||||
uint baseExperience, IntPtr types, ulong typesLength, IntPtr baseStats, IntPtr abilities,
|
uint baseExperience, IntPtr types, ulong typesLength, FFIHandleValue baseStats, IntPtr abilities,
|
||||||
ulong abilitiesLength, IntPtr hiddenAbilities, ulong hiddenAbilitiesLength, IntPtr learnableMoves,
|
ulong abilitiesLength, IntPtr hiddenAbilities, ulong hiddenAbilitiesLength, FFIHandleValue learnableMoves,
|
||||||
IntPtr flags, ulong flagsLength);
|
IntPtr flags, ulong flagsLength);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
internal static extern NativeResult<IntPtr> form_name(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void form_drop(IntPtr ptr);
|
internal static extern float form_height(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr form_name(IntPtr ptr);
|
internal static extern float form_weight(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern float form_height(IntPtr ptr);
|
internal static extern uint form_base_experience(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern float form_weight(IntPtr ptr);
|
internal static extern ulong form_types_length(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern uint form_base_experience(IntPtr ptr);
|
internal static extern TypeIdentifier form_types_get(FFIHandleValue ptr, ulong index);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern ulong form_types_length(IntPtr ptr);
|
internal static extern FFIHandleValue form_base_stats(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern TypeIdentifier form_types_get(IntPtr ptr, ulong index);
|
internal static extern ulong form_abilities_length(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer form_base_stats(IntPtr ptr);
|
internal static extern IntPtr form_abilities_get(FFIHandleValue ptr, ulong index);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern ulong form_abilities_length(IntPtr ptr);
|
internal static extern ulong form_hidden_abilities_length(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr form_abilities_get(IntPtr ptr, ulong index);
|
internal static extern IntPtr form_hidden_abilities_get(FFIHandleValue ptr, ulong index);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern ulong form_hidden_abilities_length(IntPtr ptr);
|
internal static extern FFIHandleValue form_moves(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr form_hidden_abilities_get(IntPtr ptr, ulong index);
|
internal static extern byte form_has_flag(FFIHandleValue ptr, IntPtr flag);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern IntPtr form_moves(IntPtr ptr);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern byte form_has_flag(IntPtr ptr, IntPtr flag);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,21 +1,19 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class GrowthRate
|
internal static class GrowthRate
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IntPtr growth_rate_lookup_new(IntPtr array, ulong length);
|
internal static extern FFIHandleValue growth_rate_lookup_new(IntPtr array, ulong length);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void growth_rate_lookup_drop(IntPtr p);
|
internal static extern LevelInt growth_rate_calculate_level(FFIHandleValue p, uint experience);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern LevelInt growth_rate_calculate_level(IntPtr p, uint experience);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern uint growth_rate_calculate_experience(IntPtr p, LevelInt level);
|
internal static extern NativeResult<uint> growth_rate_calculate_experience(FFIHandleValue p, LevelInt level);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,32 +1,30 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class Item
|
internal static class Item
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer item_new(IntPtr name, ItemCategory category, BattleItemCategory battleCategory,
|
internal static extern NativeResult<FFIHandleValue> item_new(IntPtr name, ItemCategory category, BattleItemCategory battleCategory,
|
||||||
int price, IntPtr flags, ulong flagsLength);
|
int price, IntPtr flags, ulong flagsLength);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void item_drop(IntPtr ptr);
|
internal static extern NativeResult<IntPtr> item_name(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr item_name(IntPtr ptr);
|
internal static extern ItemCategory item_category(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern ItemCategory item_category(IntPtr ptr);
|
internal static extern BattleItemCategory item_battle_category(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern BattleItemCategory item_battle_category(IntPtr ptr);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern int item_price(IntPtr ptr);
|
internal static extern int item_price(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern byte item_has_flag(IntPtr p, IntPtr flag);
|
internal static extern byte item_has_flag(FFIHandleValue p, IntPtr flag);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,16 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class LearnableMoves
|
internal static class LearnableMoves
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr learnable_moves_new();
|
internal static extern FFIHandleValue learnable_moves_new();
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void learnable_moves_drop(IntPtr p);
|
internal static extern void learnable_moves_add_level_move(FFIHandleValue p, LevelInt level, IntPtr moveName);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern void learnable_moves_add_level_move(IntPtr p, LevelInt level, IntPtr moveName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +1,25 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class AbilityLibrary
|
internal static class AbilityLibrary
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer ability_library_new(ulong capacity);
|
internal static extern FFIHandleValue ability_library_new(ulong capacity);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void ability_library_drop(IntPtr ptr);
|
internal static extern void ability_library_add(FFIHandleValue ptr, IntPtr key, FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IdentifiablePointer ability_library_get(IntPtr ptr, IntPtr key);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IntPtr ability_library_get_key_by_index(IntPtr ptr, ulong index);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void ability_library_add(IntPtr ptr, IntPtr key, IntPtr value);
|
internal static extern FFIHandleValue ability_library_get(FFIHandleValue ptr, IntPtr key);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern ulong ability_library_len(IntPtr ptr);
|
internal static extern IntPtr ability_library_get_key_by_index(FFIHandleValue ptr, ulong index);
|
||||||
|
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern ulong ability_library_len(FFIHandleValue ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,24 +1,22 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class GrowthRateLibrary
|
internal static class GrowthRateLibrary
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer growth_rate_library_new(ulong capacity);
|
internal static extern FFIHandleValue growth_rate_library_new(ulong capacity);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void growth_rate_library_drop(IntPtr ptr);
|
internal static extern NativeResult<LevelInt> growth_rate_library_calculate_level(FFIHandleValue ptr, IntPtr growthRate, uint experience);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern LevelInt growth_rate_library_calculate_level(IntPtr ptr, IntPtr growthRate, uint experience);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern uint growth_rate_library_calculate_experience(IntPtr ptr, IntPtr growthRate, LevelInt level);
|
internal static extern NativeResult<uint> growth_rate_library_calculate_experience(FFIHandleValue ptr, IntPtr growthRate, LevelInt level);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern uint growth_rate_library_add_growth_rate(IntPtr ptr, IntPtr name, IntPtr growthRate);
|
internal static extern void growth_rate_library_add_growth_rate(FFIHandleValue ptr, IntPtr name, FFIHandleValue growthRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class ItemLibrary
|
internal static class ItemLibrary
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer item_library_new(ulong capacity);
|
internal static extern FFIHandleValue item_library_new(ulong capacity);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void item_library_drop(IntPtr ptr);
|
internal static extern FFIHandleValue item_library_get(FFIHandleValue ptr, IntPtr key);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer item_library_get(IntPtr ptr, IntPtr key);
|
internal static extern IntPtr item_library_get_key_by_index(FFIHandleValue ptr, ulong index);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IntPtr item_library_get_key_by_index(IntPtr ptr, ulong index);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void item_library_add(IntPtr ptr, IntPtr key, IntPtr value);
|
internal static extern void item_library_add(FFIHandleValue ptr, IntPtr key, FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern ulong item_library_len(IntPtr ptr);
|
internal static extern ulong item_library_len(FFIHandleValue ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,22 +1,23 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class LibrarySettings
|
internal static class LibrarySettings
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer library_settings_new(LevelInt maxLevel, uint shinyRate);
|
internal static extern NativeResult<FFIHandleValue> library_settings_new(LevelInt maxLevel, uint shinyRate);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void library_settings_drop(IntPtr ptr);
|
internal static extern void library_settings_drop(IntPtr ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern LevelInt library_settings_maximum_level(IntPtr ptr);
|
internal static extern LevelInt library_settings_maximum_level(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern uint library_settings_shiny_rate(IntPtr ptr);
|
internal static extern uint library_settings_shiny_rate(FFIHandleValue ptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class MoveLibrary
|
internal static class MoveLibrary
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer move_library_new(ulong capacity);
|
internal static extern FFIHandleValue move_library_new(ulong capacity);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void move_library_drop(IntPtr ptr);
|
internal static extern IdentifiablePointer move_library_get(FFIHandleValue ptr, IntPtr key);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer move_library_get(IntPtr ptr, IntPtr key);
|
internal static extern IntPtr move_library_get_key_by_index(FFIHandleValue ptr, ulong index);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IntPtr move_library_get_key_by_index(IntPtr ptr, ulong index);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void move_library_add(IntPtr ptr, IntPtr key, IntPtr value);
|
internal static extern void move_library_add(FFIHandleValue ptr, IntPtr key, FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern ulong move_library_len(IntPtr ptr);
|
internal static extern ulong move_library_len(FFIHandleValue ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class NatureLibrary
|
internal static class NatureLibrary
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer nature_library_new(ulong capacity);
|
internal static extern FFIHandleValue nature_library_new(ulong capacity);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void nature_library_drop(IntPtr ptr);
|
internal static extern void nature_library_load_nature(FFIHandleValue ptr, IntPtr name, FFIHandleValue nature);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void nature_library_load_nature(IntPtr ptr, IntPtr name, IntPtr nature);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer nature_library_get_nature(IntPtr ptr, IntPtr name);
|
internal static extern FFIHandleValue nature_library_get_nature(FFIHandleValue ptr, IntPtr name);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer nature_library_get_random_nature(IntPtr ptr, ulong seed);
|
internal static extern NativeResult<FFIHandleValue> nature_library_get_random_nature(FFIHandleValue ptr, ulong seed);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IntPtr nature_library_get_nature_name(IntPtr ptr, IntPtr nature);
|
internal static extern IntPtr nature_library_get_nature_name(FFIHandleValue ptr, FFIHandleValue nature);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class SpeciesLibrary
|
internal static class SpeciesLibrary
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer species_library_new(ulong capacity);
|
internal static extern FFIHandleValue species_library_new(ulong capacity);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void species_library_drop(IntPtr ptr);
|
internal static extern FFIHandleValue species_library_get(FFIHandleValue ptr, IntPtr key);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer species_library_get(IntPtr ptr, IntPtr key);
|
internal static extern IntPtr species_library_get_key_by_index(FFIHandleValue ptr, ulong index);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IntPtr species_library_get_key_by_index(IntPtr ptr, ulong index);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void species_library_add(IntPtr ptr, IntPtr key, IntPtr value);
|
internal static extern void species_library_add(FFIHandleValue ptr, IntPtr key, FFIHandleValue value);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern ulong species_library_len(IntPtr ptr);
|
internal static extern ulong species_library_len(FFIHandleValue ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,40 +1,41 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class StaticData
|
internal static class StaticData
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_new(IntPtr settings, IntPtr speciesLibrary,
|
internal static extern FFIHandleValue static_data_new(FFIHandleValue settings, FFIHandleValue speciesLibrary,
|
||||||
IntPtr moveLibrary, IntPtr itemLibrary, IntPtr growthRateLibrary, IntPtr typeLibrary, IntPtr natureLibrary,
|
FFIHandleValue moveLibrary, FFIHandleValue itemLibrary, FFIHandleValue growthRateLibrary, FFIHandleValue typeLibrary,
|
||||||
IntPtr abilityLibrary);
|
FFIHandleValue natureLibrary, FFIHandleValue abilityLibrary);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void static_data_drop(IntPtr ptr);
|
internal static extern void static_data_drop(IntPtr ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_settings(IntPtr ptr);
|
internal static extern FFIHandleValue static_data_settings(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_species(IntPtr ptr);
|
internal static extern FFIHandleValue static_data_species(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_moves(IntPtr ptr);
|
internal static extern FFIHandleValue static_data_moves(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_items(IntPtr ptr);
|
internal static extern FFIHandleValue static_data_items(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_growth_rates(IntPtr ptr);
|
internal static extern FFIHandleValue static_data_growth_rates(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_types(IntPtr ptr);
|
internal static extern FFIHandleValue static_data_types(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_natures(IntPtr ptr);
|
internal static extern FFIHandleValue static_data_natures(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_data_abilities(IntPtr ptr);
|
internal static extern FFIHandleValue static_data_abilities(FFIHandleValue ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,37 +1,35 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
namespace PkmnLibSharp.FFI.StaticData.Libraries
|
||||||
{
|
{
|
||||||
internal static class TypeLibrary
|
internal static class TypeLibrary
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer type_library_new(ulong capacity);
|
internal static extern FFIHandleValue type_library_new(ulong capacity);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern TypeIdentifier type_library_get_type_id(FFIHandleValue ptr, IntPtr name, IntPtr success);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void type_library_drop(IntPtr ptr);
|
internal static extern IntPtr type_library_get_type_name(FFIHandleValue ptr, TypeIdentifier typeIdentifier,
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern TypeIdentifier type_library_get_type_id(IntPtr ptr, IntPtr name, IntPtr success);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IntPtr type_library_get_type_name(IntPtr ptr, TypeIdentifier typeIdentifier,
|
|
||||||
IntPtr success);
|
IntPtr success);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern float type_library_get_single_effectiveness(IntPtr ptr, TypeIdentifier attacking,
|
internal static extern float type_library_get_single_effectiveness(FFIHandleValue ptr, TypeIdentifier attacking,
|
||||||
TypeIdentifier defending);
|
TypeIdentifier defending);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern float type_library_get_effectiveness(IntPtr ptr, TypeIdentifier attacking,
|
internal static extern float type_library_get_effectiveness(FFIHandleValue ptr, TypeIdentifier attacking,
|
||||||
IntPtr defending, ulong defendingLength);
|
IntPtr defending, ulong defendingLength);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern TypeIdentifier type_library_register_type(IntPtr ptr, IntPtr name);
|
internal static extern TypeIdentifier type_library_register_type(FFIHandleValue ptr, IntPtr name);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void type_library_set_effectiveness(IntPtr ptr, TypeIdentifier attacking,
|
internal static extern void type_library_set_effectiveness(FFIHandleValue ptr, TypeIdentifier attacking,
|
||||||
TypeIdentifier defending, float effectiveness);
|
TypeIdentifier defending, float effectiveness);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,67 +1,62 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class MoveData
|
internal static class MoveData
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer move_data_new(IntPtr name, TypeIdentifier moveType, MoveCategory category,
|
internal static extern NativeResult<FFIHandleValue> move_data_new(IntPtr name, TypeIdentifier moveType, MoveCategory category,
|
||||||
byte basePower, byte accuracy, byte baseUsages, MoveTarget target, sbyte priority, IntPtr secondaryEffect,
|
byte basePower, byte accuracy, byte baseUsages, MoveTarget target, sbyte priority, FFIHandleValue secondaryEffect,
|
||||||
IntPtr flags, ulong flagsLength);
|
IntPtr flags, ulong flagsLength);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void move_data_drop(IntPtr p);
|
internal static extern NativeResult<IntPtr> move_data_name(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr move_data_name(IntPtr p);
|
internal static extern TypeIdentifier move_data_move_type(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern TypeIdentifier move_data_move_type(IntPtr p);
|
internal static extern MoveCategory move_data_category(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern MoveCategory move_data_category(IntPtr p);
|
internal static extern byte move_data_base_power(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern byte move_data_base_power(IntPtr p);
|
internal static extern byte move_data_accuracy(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern byte move_data_accuracy(IntPtr p);
|
internal static extern byte move_data_base_usages(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern byte move_data_base_usages(IntPtr p);
|
internal static extern MoveTarget move_data_target(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern MoveTarget move_data_target(IntPtr p);
|
internal static extern sbyte move_data_priority(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern sbyte move_data_priority(IntPtr p);
|
internal static extern FFIHandleValue move_data_secondary_effect(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer move_data_secondary_effect(IntPtr p);
|
internal static extern byte move_data_has_flag(FFIHandleValue p, IntPtr flag);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern byte move_data_has_flag(IntPtr p, IntPtr flag);
|
|
||||||
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer secondary_effect_new(float chance, IntPtr effectName, IntPtr parameters,
|
internal static extern FFIHandleValue secondary_effect_new(float chance, IntPtr effectName, IntPtr parameters,
|
||||||
ulong parametersLength);
|
ulong parametersLength);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void secondary_effect_drop(IntPtr p);
|
internal static extern float secondary_effect_chance(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern float secondary_effect_chance(IntPtr p);
|
internal static extern NativeResult<IntPtr> secondary_effect_effect_name(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern IntPtr secondary_effect_effect_name(IntPtr p);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern ulong secondary_effect_parameter_length(IntPtr p);
|
internal static extern ulong secondary_effect_parameter_length(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer secondary_effect_parameter_get(IntPtr p, ulong index);
|
internal static extern FFIHandleValue secondary_effect_parameter_get(FFIHandleValue p, ulong index);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,25 +1,23 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class Nature
|
internal static class Nature
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer nature_new(Statistic increaseStat, Statistic decreaseStat, float increaseModifier,
|
internal static extern FFIHandleValue nature_new(Statistic increaseStat, Statistic decreaseStat, float increaseModifier,
|
||||||
float decreaseModifier);
|
float decreaseModifier);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void nature_drop(IntPtr p);
|
internal static extern Statistic nature_increased_stat(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern Statistic nature_increased_stat(IntPtr p);
|
internal static extern Statistic nature_decreased_stat(FFIHandleValue p);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern Statistic nature_decreased_stat(IntPtr p);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern float nature_get_stat_modifier(IntPtr p, Statistic statistic);
|
internal static extern float nature_get_stat_modifier(FFIHandleValue p, Statistic statistic);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,41 +1,41 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class Species
|
internal static class Species
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer species_new(ushort id, IntPtr name, float genderRate, IntPtr growthRate,
|
internal static extern NativeResult<FFIHandleValue> species_new(ushort id, IntPtr name, float genderRate, IntPtr growthRate,
|
||||||
byte captureRate, IntPtr defaultForm, IntPtr flags, ulong flagsLength);
|
byte captureRate, FFIHandleValue defaultForm, IntPtr flags, ulong flagsLength);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void species_drop(IntPtr ptr);
|
internal static extern ushort species_id(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern ushort species_id(IntPtr ptr);
|
internal static extern IntPtr species_name(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
internal static extern IntPtr species_name(IntPtr ptr);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern float species_gender_rate(IntPtr ptr);
|
internal static extern float species_gender_rate(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr species_growth_rate(IntPtr ptr);
|
internal static extern IntPtr species_growth_rate(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern byte species_capture_rate(IntPtr ptr);
|
internal static extern byte species_capture_rate(FFIHandleValue ptr);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr species_add_form(IntPtr ptr, IntPtr name, IntPtr form);
|
[MustUseReturnValue]
|
||||||
|
internal static extern NativeResult species_add_form(FFIHandleValue ptr, IntPtr name, FFIHandleValue form);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IdentifiablePointer species_get_form(IntPtr ptr, IntPtr name);
|
internal static extern FFIHandleValue species_get_form(FFIHandleValue ptr, IntPtr name);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern Gender species_get_random_gender(IntPtr ptr, ulong seed);
|
internal static extern Gender species_get_random_gender(FFIHandleValue ptr, ulong seed);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,69 +1,17 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class StaticStatisticSet
|
internal static class StaticStatisticSet
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_statistic_set_u8_new(byte hp, byte attack, byte defense,
|
internal static extern FFIHandleValue static_statistic_set_u16_new(ushort hp, ushort attack, ushort defense,
|
||||||
byte specialAttack, byte specialDefense, byte speed);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IdentifiablePointer static_statistic_set_u16_new(ushort hp, ushort attack, ushort defense,
|
|
||||||
ushort specialAttack, ushort specialDefense, ushort speed);
|
ushort specialAttack, ushort specialDefense, ushort speed);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer static_statistic_set_u32_new(uint hp, uint attack, uint defense,
|
internal static extern ushort static_statistic_set_u16_get_stat(FFIHandleValue value, Statistic statistic);
|
||||||
uint specialAttack, uint specialDefense, uint speed);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IdentifiablePointer static_statistic_set_i8_new(sbyte hp, sbyte attack, sbyte defense,
|
|
||||||
sbyte specialAttack, sbyte specialDefense, sbyte speed);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IdentifiablePointer static_statistic_set_i16_new(short hp, short attack, short defense,
|
|
||||||
short specialAttack, short specialDefense, short speed);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IdentifiablePointer static_statistic_set_i32_new(int hp, int attack, int defense, int specialAttack,
|
|
||||||
int specialDefense, int speed);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void static_statistic_set_u8_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void static_statistic_set_u16_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void static_statistic_set_u32_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void static_statistic_set_i8_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void static_statistic_set_i16_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void static_statistic_set_i32_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern byte static_statistic_set_u8_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern ushort static_statistic_set_u16_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern uint static_statistic_set_u32_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern sbyte static_statistic_set_i8_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern short static_statistic_set_i16_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern int static_statistic_set_i32_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,125 +1,58 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.FFI.StaticData
|
namespace PkmnLibSharp.FFI.StaticData
|
||||||
{
|
{
|
||||||
internal static class StatisticSet
|
internal static class StatisticSet
|
||||||
{
|
{
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer statistic_set_u8_new(byte hp, byte attack, byte defense, byte specialAttack,
|
internal static extern FFIHandleValue statistic_set_u8_new(byte hp, byte attack, byte defense, byte specialAttack,
|
||||||
byte specialDefense, byte speed);
|
byte specialDefense, byte speed);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer statistic_set_u16_new(ushort hp, ushort attack, ushort defense,
|
internal static extern FFIHandleValue statistic_set_u32_new(uint hp, uint attack, uint defense, uint specialAttack,
|
||||||
ushort specialAttack, ushort specialDefense, ushort speed);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern IdentifiablePointer statistic_set_u32_new(uint hp, uint attack, uint defense, uint specialAttack,
|
|
||||||
uint specialDefense, uint speed);
|
uint specialDefense, uint speed);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer statistic_set_i8_new(sbyte hp, sbyte attack, sbyte defense, sbyte specialAttack,
|
internal static extern FFIHandleValue statistic_set_i8_new(sbyte hp, sbyte attack, sbyte defense, sbyte specialAttack,
|
||||||
sbyte specialDefense, sbyte speed);
|
sbyte specialDefense, sbyte speed);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern byte statistic_set_u8_get_stat(FFIHandleValue value, Statistic statistic);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern uint statistic_set_u32_get_stat(FFIHandleValue value, Statistic statistic);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer statistic_set_i16_new(short hp, short attack, short defense, short specialAttack,
|
internal static extern sbyte statistic_set_i8_get_stat(FFIHandleValue value, Statistic statistic);
|
||||||
short specialDefense, short speed);
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern void statistic_set_u8_set_stat(FFIHandleValue value, Statistic statistic, byte v);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern void statistic_set_u32_set_stat(FFIHandleValue value, Statistic statistic, uint v);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern IdentifiablePointer statistic_set_i32_new(int hp, int attack, int defense, int specialAttack,
|
internal static extern void statistic_set_i8_set_stat(FFIHandleValue value, Statistic statistic, sbyte v);
|
||||||
int specialDefense, int speed);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void statistic_set_u8_drop(IntPtr value);
|
internal static extern void statistic_set_u8_increase_stat(FFIHandleValue value, Statistic statistic, byte v);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern void statistic_set_u32_increase_stat(FFIHandleValue value, Statistic statistic, uint v);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void statistic_set_u16_drop(IntPtr value);
|
internal static extern void statistic_set_i8_increase_stat(FFIHandleValue value, Statistic statistic, sbyte v);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern void statistic_set_u8_decrease_stat(FFIHandleValue value, Statistic statistic, byte v);
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
internal static extern void statistic_set_u32_decrease_stat(FFIHandleValue value, Statistic statistic, uint v);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
internal static extern void statistic_set_u32_drop(IntPtr value);
|
internal static extern void statistic_set_i8_decrease_stat(FFIHandleValue value, Statistic statistic, sbyte v);
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i8_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i16_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i32_drop(IntPtr value);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern byte statistic_set_u8_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern ushort statistic_set_u16_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern uint statistic_set_u32_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern sbyte statistic_set_i8_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern short statistic_set_i16_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern int statistic_set_i32_get_stat(IntPtr value, Statistic statistic);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u8_set_stat(IntPtr value, Statistic statistic, byte v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u16_set_stat(IntPtr value, Statistic statistic, ushort v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u32_set_stat(IntPtr value, Statistic statistic, uint v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i8_set_stat(IntPtr value, Statistic statistic, sbyte v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i16_set_stat(IntPtr value, Statistic statistic, short v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i32_set_stat(IntPtr value, Statistic statistic, int v);
|
|
||||||
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u8_increase_stat(IntPtr value, Statistic statistic, byte v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u16_increase_stat(IntPtr value, Statistic statistic, ushort v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u32_increase_stat(IntPtr value, Statistic statistic, uint v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i8_increase_stat(IntPtr value, Statistic statistic, sbyte v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i16_increase_stat(IntPtr value, Statistic statistic, short v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i32_increase_stat(IntPtr value, Statistic statistic, int v);
|
|
||||||
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u8_decrease_stat(IntPtr value, Statistic statistic, byte v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u16_decrease_stat(IntPtr value, Statistic statistic, ushort v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_u32_decrease_stat(IntPtr value, Statistic statistic, uint v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i8_decrease_stat(IntPtr value, Statistic statistic, sbyte v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i16_decrease_stat(IntPtr value, Statistic statistic, short v);
|
|
||||||
|
|
||||||
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
internal static extern void statistic_set_i32_decrease_stat(IntPtr value, Statistic statistic, int v);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,71 +1,33 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Ability;
|
using Interface = PkmnLibSharp.FFI.StaticData.Ability;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class Ability : ExternPointer<Ability.CacheData>
|
public class Ability : HandleType
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
private string? _name;
|
||||||
public class CacheData
|
public string Name => _name ??= Interface.ability_name(Handle).Result().PtrString()!;
|
||||||
|
|
||||||
|
private string? _effect;
|
||||||
|
public string Effect => _effect ??= Interface.ability_effect(Handle).Result().PtrString()!;
|
||||||
|
|
||||||
|
public IReadOnlyList<EffectParameter> Parameters { get; private set; } = null!;
|
||||||
|
|
||||||
|
protected Ability(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
public string? Name { get; internal set; }
|
|
||||||
public string? Effect { get; internal set; }
|
|
||||||
public DisposableCachedExternArray<EffectParameter>? Parameters { get; internal set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ability(string name, string effect, IReadOnlyCollection<EffectParameter> parameters)
|
public static Ability Create(string name, string effect, IReadOnlyList<EffectParameter> parameters)
|
||||||
{
|
{
|
||||||
// Passing effect parameters to Rust gives Rust full control over them, and means it can move it. As such
|
var parameterArray = parameters.Select(x => (FFIHandleValue)x.Handle).ToArray();
|
||||||
// we remove ownership and invalidate the passed parameters.
|
|
||||||
var parameterArray = parameters.Select(x => x.TakeOwnershipAndInvalidate()).ToArray();
|
|
||||||
var arrayPtr = parameterArray.ArrayPtr();
|
var arrayPtr = parameterArray.ArrayPtr();
|
||||||
InitializePointer(Interface.ability_new(name.ToPtr(), effect.ToPtr(), arrayPtr, (ulong)parameters.Count),
|
var handle = Interface.ability_new(name.ToPtr(), effect.ToPtr(), arrayPtr, (ulong)parameterArray.LongLength)
|
||||||
true);
|
.Result();
|
||||||
}
|
var ability = Resolver.Instance.ResolveAbility(handle.Resolve());
|
||||||
|
ability.Parameters = parameters;
|
||||||
internal Ability(IdentifiablePointer ptr) : base(ptr, true)
|
return ability;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Name => Cache.Name ?? (Cache.Name = Interface.ability_name(Ptr));
|
|
||||||
public string Effect => Cache.Effect ?? (Cache.Effect = Interface.ability_effect(Ptr));
|
|
||||||
|
|
||||||
public IReadOnlyList<EffectParameter> Parameters =>
|
|
||||||
Cache.Parameters ??= new DisposableCachedExternArray<EffectParameter>(
|
|
||||||
Interface.ability_parameter_length(Ptr),
|
|
||||||
#pragma warning disable IDISP012
|
|
||||||
arg => new EffectParameter(Interface.ability_parameter_get(Ptr, arg), false));
|
|
||||||
#pragma warning restore IDISP012
|
|
||||||
|
|
||||||
|
|
||||||
protected override CacheData CreateCache()
|
|
||||||
{
|
|
||||||
return new CacheData();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
Interface.ability_drop(Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
|
||||||
if (Cache.Parameters == null) return;
|
|
||||||
for (var index = 0; index < Cache.Parameters.Count; index++)
|
|
||||||
{
|
|
||||||
Cache.Parameters.GetCachedValue(index)?.Invalidate();
|
|
||||||
}
|
|
||||||
Cache.Parameters.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
~Ability()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,88 +1,59 @@
|
||||||
using System;
|
using System;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.EffectParameter;
|
using Interface = PkmnLibSharp.FFI.StaticData.EffectParameter;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class EffectParameter : ExternPointer<EffectParameter.CacheData>
|
public class EffectParameter : HandleType
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
private ParameterType? _type;
|
||||||
public class CacheData
|
public ParameterType? Type => _type ??= (ParameterType)Interface.effect_parameter_get_type(Handle);
|
||||||
|
|
||||||
|
private object? _data;
|
||||||
|
|
||||||
|
public object Data
|
||||||
{
|
{
|
||||||
public ParameterType? Type { get; internal set; }
|
get
|
||||||
public object? Data { get; internal set; }
|
{
|
||||||
|
_data ??= Type switch
|
||||||
|
{
|
||||||
|
ParameterType.Bool => Interface.effect_parameter_get_as_bool(Handle).Result() == 1,
|
||||||
|
ParameterType.Int => Interface.effect_parameter_get_as_int(Handle).Result(),
|
||||||
|
ParameterType.Float => Interface.effect_parameter_get_as_float(Handle).Result(),
|
||||||
|
ParameterType.String => Interface.effect_parameter_get_as_string(Handle).Result().PtrString()!,
|
||||||
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
|
};
|
||||||
|
return _data!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal EffectParameter(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
protected EffectParameter(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public EffectParameter(bool b) : base(Interface.effect_parameter_new_bool(b.ForeignBool()), true)
|
public static EffectParameter FromBool(bool b) =>
|
||||||
{
|
Resolver.Instance.ResolveEffectParameter(Interface.effect_parameter_new_bool(b.ForeignBool()).Resolve());
|
||||||
}
|
|
||||||
|
|
||||||
public EffectParameter(long l) : base(Interface.effect_parameter_new_int(l), true)
|
public static EffectParameter FromLong(long l) =>
|
||||||
{
|
Resolver.Instance.ResolveEffectParameter(Interface.effect_parameter_new_int(l).Resolve());
|
||||||
}
|
|
||||||
|
|
||||||
public EffectParameter(float f) : base(Interface.effect_parameter_new_float(f), true)
|
public static EffectParameter FromFloat(float f) =>
|
||||||
{
|
Resolver.Instance.ResolveEffectParameter(Interface.effect_parameter_new_float(f).Resolve());
|
||||||
}
|
|
||||||
|
|
||||||
public EffectParameter(string s) : base(Interface.effect_parameter_new_string(s.ToPtr()), true)
|
public static EffectParameter FromString(string s) =>
|
||||||
{
|
Resolver.Instance.ResolveEffectParameter(Interface.effect_parameter_new_string(s.ToPtr()).Result().Resolve());
|
||||||
}
|
|
||||||
|
public static implicit operator EffectParameter(bool b) => FromBool(b);
|
||||||
|
public static implicit operator EffectParameter(long l) => FromLong(l);
|
||||||
|
public static implicit operator EffectParameter(float f) => FromFloat(f);
|
||||||
|
public static implicit operator EffectParameter(string s) => FromString(s);
|
||||||
|
|
||||||
public enum ParameterType : byte
|
public enum ParameterType : byte
|
||||||
{
|
{
|
||||||
Bool = 0,
|
Bool = 0,
|
||||||
Int = 1,
|
Int = 1,
|
||||||
Float = 2,
|
Float = 2,
|
||||||
String = 3
|
String = 3,
|
||||||
}
|
|
||||||
|
|
||||||
public ParameterType Type
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var cache = Cache.Type;
|
|
||||||
if (cache.HasValue)
|
|
||||||
return cache.Value;
|
|
||||||
Cache.Type = (ParameterType)Interface.effect_parameter_get_type(Ptr);
|
|
||||||
return Cache.Type.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Data
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var cache = Cache.Data;
|
|
||||||
if (cache != null)
|
|
||||||
return cache;
|
|
||||||
var type = Type;
|
|
||||||
Cache.Data = type switch
|
|
||||||
{
|
|
||||||
ParameterType.Bool => Interface.effect_parameter_get_as_bool(Ptr) == 1,
|
|
||||||
ParameterType.Int => Interface.effect_parameter_get_as_int(Ptr),
|
|
||||||
ParameterType.Float => Interface.effect_parameter_get_as_float(Ptr),
|
|
||||||
ParameterType.String => Interface.effect_parameter_get_as_string(Ptr).PtrString(),
|
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
|
||||||
};
|
|
||||||
return Cache.Data!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override CacheData CreateCache()
|
|
||||||
{
|
|
||||||
return new CacheData();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
Interface.effect_parameter_drop(Ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -90,10 +61,5 @@ namespace PkmnLibSharp.StaticData
|
||||||
var data = Data;
|
var data = Data;
|
||||||
return data is string ? $"{Type}(\"{data}\")" : $"{Type}({data})";
|
return data is string ? $"{Type}(\"{data}\")" : $"{Type}({data})";
|
||||||
}
|
}
|
||||||
|
|
||||||
~EffectParameter()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,34 +1,18 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Form;
|
using Interface = PkmnLibSharp.FFI.StaticData.Form;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class Form : ExternPointer<Form.CacheData>
|
public class Form : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected Form(FFIHandle handle) : base(handle)
|
||||||
{
|
|
||||||
public string? Name { get; internal set; }
|
|
||||||
public float? Height { get; internal set; }
|
|
||||||
public float? Weight { get; internal set; }
|
|
||||||
public uint? BaseExperience { get; internal set; }
|
|
||||||
public ulong? TypesLength { get; internal set; }
|
|
||||||
public CachedExternValueArray<TypeIdentifier>? Types { get; internal set; }
|
|
||||||
public StaticStatisticSet<ushort>? BaseStats { get; internal set; }
|
|
||||||
public CachedExternArray<string>? Abilities { get; internal set; }
|
|
||||||
public CachedExternArray<string>? HiddenAbilities { get; internal set; }
|
|
||||||
public LearnableMoves? LearnableMoves { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal Form(IdentifiablePointer formPtr) : base(formPtr, true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Form(string name, float height, float weight, uint baseExperience, TypeIdentifier[] types,
|
public static Form Create(string name, float height, float weight, uint baseExperience, TypeIdentifier[] types,
|
||||||
StaticStatisticSet<short> baseStats, IReadOnlyCollection<string> abilities,
|
StaticStatisticSet<ushort> baseStats, IReadOnlyCollection<string> abilities,
|
||||||
IReadOnlyCollection<string> hiddenAbilities, LearnableMoves learnableMoves,
|
IReadOnlyCollection<string> hiddenAbilities, LearnableMoves learnableMoves,
|
||||||
IReadOnlyCollection<string> flags)
|
IReadOnlyCollection<string> flags)
|
||||||
{
|
{
|
||||||
|
@ -38,50 +22,45 @@ namespace PkmnLibSharp.StaticData
|
||||||
var hiddenAbilitiesPtrArray = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
|
var hiddenAbilitiesPtrArray = hiddenAbilities.Select(x => x.ToPtr()).ToArray();
|
||||||
var flagsPtrArray = flags.Select(x => x.ToPtr()).ToArray();
|
var flagsPtrArray = flags.Select(x => x.ToPtr()).ToArray();
|
||||||
|
|
||||||
var ptr = Interface.form_new(name.ToPtr(), height, weight, baseExperience, typesArr, (ulong)types.Length,
|
var handle = Interface.form_new(name.ToPtr(), height, weight, baseExperience, typesArr, (ulong)types.Length,
|
||||||
baseStats.TakeOwnershipAndInvalidate(), abilitiesPtrArray.ArrayPtr(), (ulong)abilities.Count,
|
baseStats.Handle, abilitiesPtrArray.ArrayPtr(), (ulong)abilities.Count,
|
||||||
hiddenAbilitiesPtrArray.ArrayPtr(), (ulong)hiddenAbilities.Count,
|
hiddenAbilitiesPtrArray.ArrayPtr(), (ulong)hiddenAbilities.Count,
|
||||||
learnableMoves.TakeOwnershipAndInvalidate(), flagsPtrArray.ArrayPtr(), (ulong)flags.Count);
|
learnableMoves.Handle, flagsPtrArray.ArrayPtr(), (ulong)flags.Count);
|
||||||
InitializePointer(ptr, true);
|
var form = Resolver.Instance.ResolveForm(handle.Result().Resolve());
|
||||||
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string Name => Cache.Name ??= Interface.form_name(Ptr).PtrString()!;
|
private string? _name;
|
||||||
public float Height => Cache.Height ??= Interface.form_height(Ptr);
|
public string Name => _name ??= Interface.form_name(Handle).Result().PtrString()!;
|
||||||
public float Weight => Cache.Weight ??= Interface.form_weight(Ptr);
|
private float? _height;
|
||||||
public uint BaseExperience => Cache.BaseExperience ??= Interface.form_base_experience(Ptr);
|
public float Height => _height ??= Interface.form_height(Handle);
|
||||||
|
private float? _weight;
|
||||||
|
public float Weight => _weight ??= Interface.form_weight(Handle);
|
||||||
|
private uint? _baseExperience;
|
||||||
|
public uint BaseExperience => _baseExperience ??= Interface.form_base_experience(Handle);
|
||||||
|
|
||||||
|
private IReadOnlyList<TypeIdentifier>? _types;
|
||||||
public IReadOnlyList<TypeIdentifier> Types =>
|
public IReadOnlyList<TypeIdentifier> Types =>
|
||||||
Cache.Types ??= new CachedExternValueArray<TypeIdentifier>(Interface.form_types_length(Ptr),
|
_types ??= new CachedExternValueArray<TypeIdentifier>(Interface.form_types_length(Handle),
|
||||||
arg => Interface.form_types_get(Ptr, arg));
|
arg => Interface.form_types_get(Handle, arg));
|
||||||
|
|
||||||
|
private StaticStatisticSet<ushort>? _baseStats;
|
||||||
public StaticStatisticSet<ushort> BaseStats =>
|
public StaticStatisticSet<ushort> BaseStats =>
|
||||||
Cache.BaseStats ??= new StaticStatisticSet<ushort>(Interface.form_base_stats(Ptr), false);
|
_baseStats ??= Resolver.Instance.ResolveStaticStatisticSet<ushort>(Interface.form_base_stats(Handle).Resolve());
|
||||||
|
|
||||||
|
private IReadOnlyList<string>? _abilities;
|
||||||
public IReadOnlyList<string> Abilities =>
|
public IReadOnlyList<string> Abilities =>
|
||||||
Cache.Abilities ??= new CachedExternArray<string>(Interface.form_abilities_length(Ptr),
|
_abilities ??= new CachedExternArray<string>(Interface.form_abilities_length(Handle),
|
||||||
arg => Interface.form_abilities_get(Ptr, arg).PtrString()!);
|
arg => Interface.form_abilities_get(Handle, arg).PtrString()!);
|
||||||
|
|
||||||
|
private IReadOnlyList<string>? _hiddenAbilities;
|
||||||
public IReadOnlyList<string> HiddenAbilities =>
|
public IReadOnlyList<string> HiddenAbilities =>
|
||||||
Cache.HiddenAbilities ??= new CachedExternArray<string>(Interface.form_hidden_abilities_length(Ptr),
|
_hiddenAbilities ??= new CachedExternArray<string>(Interface.form_hidden_abilities_length(Handle),
|
||||||
arg => Interface.form_hidden_abilities_get(Ptr, arg).PtrString()!);
|
arg => Interface.form_hidden_abilities_get(Handle, arg).PtrString()!);
|
||||||
|
|
||||||
|
private LearnableMoves? _learnableMoves;
|
||||||
public LearnableMoves LearnableMoves =>
|
public LearnableMoves LearnableMoves =>
|
||||||
Cache.LearnableMoves ??= new LearnableMoves(Interface.form_moves(Ptr), false);
|
_learnableMoves ??= Resolver.Instance.ResolveLearnableMoves(Interface.form_moves(Handle).Resolve());
|
||||||
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new CacheData();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.form_drop(Ptr);
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
|
||||||
Cache.LearnableMoves?.Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
~Form()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,56 +1,37 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.GrowthRate;
|
using Interface = PkmnLibSharp.FFI.StaticData.GrowthRate;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public abstract class GrowthRate : ExternPointer<object>
|
public abstract class GrowthRate : HandleType
|
||||||
{
|
{
|
||||||
protected internal GrowthRate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal GrowthRate(IntPtr ptr, bool isOwner) : base(ptr, isOwner)
|
protected internal GrowthRate(FFIHandle ptr) : base(ptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public LevelInt CalculateLevel(uint experience)
|
public LevelInt CalculateLevel(uint experience)
|
||||||
{
|
{
|
||||||
return Interface.growth_rate_calculate_level(Ptr, experience);
|
return Interface.growth_rate_calculate_level(Handle, experience);
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint CalculateExperience(LevelInt level)
|
public uint CalculateExperience(LevelInt level)
|
||||||
{
|
{
|
||||||
Debug.Assert(level >= 1);
|
return Interface.growth_rate_calculate_experience(Handle, level).Result();
|
||||||
return Interface.growth_rate_calculate_experience(Ptr, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
Interface.growth_rate_lookup_drop(Ptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LookupGrowthRate : GrowthRate
|
public class LookupGrowthRate : GrowthRate
|
||||||
{
|
{
|
||||||
public LookupGrowthRate(uint[] experienceArray)
|
protected LookupGrowthRate(FFIHandle handle) : base(handle){}
|
||||||
|
|
||||||
|
public static LookupGrowthRate Create(uint[] experienceArray)
|
||||||
{
|
{
|
||||||
var arrayPtr = experienceArray.ArrayPtr();
|
var arrayPtr = experienceArray.ArrayPtr();
|
||||||
var ptr = Interface.growth_rate_lookup_new(arrayPtr, (ulong)experienceArray.Length);
|
var ptr = Interface.growth_rate_lookup_new(arrayPtr, (ulong)experienceArray.Length);
|
||||||
InitializePointer(ptr, true);
|
return Resolver.Instance.ResolveLookupGrowthRate(ptr.Resolve());
|
||||||
}
|
|
||||||
|
|
||||||
protected override object CreateCache()
|
|
||||||
{
|
|
||||||
return new object();
|
|
||||||
}
|
|
||||||
|
|
||||||
~LookupGrowthRate()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +61,7 @@ namespace PkmnLibSharp.StaticData
|
||||||
arr[i - 1] = 4 * Power3(i) / 5;
|
arr[i - 1] = 4 * Power3(i) / 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LookupGrowthRate(arr);
|
return LookupGrowthRate.Create(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LookupGrowthRate MediumFast(LevelInt maxLevel)
|
public static LookupGrowthRate MediumFast(LevelInt maxLevel)
|
||||||
|
@ -92,7 +73,7 @@ namespace PkmnLibSharp.StaticData
|
||||||
arr[i - 1] = Power3(i);
|
arr[i - 1] = Power3(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LookupGrowthRate(arr);
|
return LookupGrowthRate.Create(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LookupGrowthRate MediumSlow(LevelInt maxLevel)
|
public static LookupGrowthRate MediumSlow(LevelInt maxLevel)
|
||||||
|
@ -104,7 +85,7 @@ namespace PkmnLibSharp.StaticData
|
||||||
arr[i - 1] = 6 * Power3(i) / 5 - 15 * Power2(i) + 100 * i - 140;
|
arr[i - 1] = 6 * Power3(i) / 5 - 15 * Power2(i) + 100 * i - 140;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LookupGrowthRate(arr);
|
return LookupGrowthRate.Create(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LookupGrowthRate Slow(LevelInt maxLevel)
|
public static LookupGrowthRate Slow(LevelInt maxLevel)
|
||||||
|
@ -115,7 +96,7 @@ namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
arr[i - 1] = 5 * Power3(i) / 4;
|
arr[i - 1] = 5 * Power3(i) / 4;
|
||||||
}
|
}
|
||||||
return new LookupGrowthRate(arr);
|
return LookupGrowthRate.Create(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LookupGrowthRate Erratic(LevelInt maxLevel)
|
public static LookupGrowthRate Erratic(LevelInt maxLevel)
|
||||||
|
@ -143,7 +124,7 @@ namespace PkmnLibSharp.StaticData
|
||||||
arr[i - 1] = Power3(i) * (160 - i) / 100;
|
arr[i - 1] = Power3(i) * (160 - i) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LookupGrowthRate(arr);
|
return LookupGrowthRate.Create(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LookupGrowthRate Fluctuating(LevelInt maxLevel)
|
public static LookupGrowthRate Fluctuating(LevelInt maxLevel)
|
||||||
|
@ -166,7 +147,7 @@ namespace PkmnLibSharp.StaticData
|
||||||
arr[i - 1] = Power3(i) * (i / 2 + 32) / 50;
|
arr[i - 1] = Power3(i) * (i / 2 + 32) / 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LookupGrowthRate(arr);
|
return LookupGrowthRate.Create(arr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Item;
|
using Interface = PkmnLibSharp.FFI.StaticData.Item;
|
||||||
|
|
||||||
|
@ -84,43 +82,29 @@ namespace PkmnLibSharp.StaticData
|
||||||
MiscBattleItem,
|
MiscBattleItem,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Item : ExternPointer<Item.CacheData>
|
public class Item : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected Item(FFIHandle handle) : base(handle){}
|
||||||
{
|
|
||||||
public string? Name { get; internal set; }
|
public static Item Create(string name, ItemCategory category, BattleItemCategory battleItemCategory, int price,
|
||||||
public ItemCategory? Category { get; internal set; }
|
|
||||||
public BattleItemCategory? BattleCategory { get; internal set; }
|
|
||||||
public int? Price { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Item(string name, ItemCategory category, BattleItemCategory battleItemCategory, int price,
|
|
||||||
IEnumerable<string> flags)
|
IEnumerable<string> flags)
|
||||||
{
|
{
|
||||||
var ptrArray = flags.Select(x => x.ToPtr()).ToArray();
|
var ptrArray = flags.Select(x => x.ToPtr()).ToArray();
|
||||||
var ptrToPtrArray = ptrArray.ArrayPtr();
|
var ptrToPtrArray = ptrArray.ArrayPtr();
|
||||||
var ptr = Interface.item_new(name.ToPtr(), category, battleItemCategory, price, ptrToPtrArray,
|
var handle = Interface.item_new(name.ToPtr(), category, battleItemCategory, price, ptrToPtrArray,
|
||||||
(ulong)ptrArray.Length);
|
(ulong)ptrArray.Length);
|
||||||
InitializePointer(ptr, true);
|
return Resolver.Instance.ResolveItem(handle.Result().Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Item(IdentifiablePointer ptr) : base(ptr, true)
|
private string? _name;
|
||||||
{
|
public string Name => _name ??= Interface.item_name(Handle).Result().PtrString()!;
|
||||||
}
|
private ItemCategory? _category;
|
||||||
|
public ItemCategory Category => _category ??= Interface.item_category(Handle);
|
||||||
|
private BattleItemCategory? _battleCategory;
|
||||||
|
public BattleItemCategory BattleCategory => _battleCategory ??= Interface.item_battle_category(Handle);
|
||||||
|
private int? _price;
|
||||||
|
public int Price => _price ??= Interface.item_price(Handle);
|
||||||
|
|
||||||
public string Name => Cache.Name ??= Interface.item_name(Ptr).PtrString()!;
|
public bool HasFlag(string flag) => Interface.item_has_flag(Handle, flag.ToPtr()) == 1;
|
||||||
public ItemCategory Category => Cache.Category ??= Interface.item_category(Ptr);
|
|
||||||
public BattleItemCategory BattleCategory => Cache.BattleCategory ??= Interface.item_battle_category(Ptr);
|
|
||||||
public int Price => Cache.Price ??= Interface.item_price(Ptr);
|
|
||||||
|
|
||||||
public bool HasFlag(string flag) => Interface.item_has_flag(Ptr, flag.ToPtr()) == 1;
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new CacheData();
|
|
||||||
protected override void Destructor() => Interface.item_drop(Ptr);
|
|
||||||
|
|
||||||
~Item()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,36 +1,28 @@
|
||||||
using System;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.LearnableMoves;
|
using Interface = PkmnLibSharp.FFI.StaticData.LearnableMoves;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class LearnableMoves : ExternPointer<object>
|
public class LearnableMoves : HandleType
|
||||||
{
|
{
|
||||||
internal LearnableMoves(IntPtr ptr, bool isOwner) : base(ptr, isOwner)
|
protected LearnableMoves(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public LearnableMoves() : base(Interface.learnable_moves_new(), true)
|
public static LearnableMoves Create()
|
||||||
{
|
{
|
||||||
|
var handle = Interface.learnable_moves_new();
|
||||||
|
return Resolver.Instance.ResolveLearnableMoves(handle.Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLevelMove(LevelInt level, string moveName)
|
public void AddLevelMove(LevelInt level, string moveName)
|
||||||
{
|
{
|
||||||
Interface.learnable_moves_add_level_move(Ptr, level, moveName.ToPtr());
|
Interface.learnable_moves_add_level_move(Handle, level, moveName.ToPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLevelMove(LevelInt level, MoveData move)
|
public void AddLevelMove(LevelInt level, MoveData move)
|
||||||
{
|
{
|
||||||
Interface.learnable_moves_add_level_move(Ptr, level, move.Name.ToPtr());
|
Interface.learnable_moves_add_level_move(Handle, level, move.Name.ToPtr());
|
||||||
}
|
|
||||||
|
|
||||||
protected override object CreateCache() => new object();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.learnable_moves_drop(Ptr);
|
|
||||||
|
|
||||||
~LearnableMoves()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using BackingLevelInt = System.Byte;
|
using BackingLevelInt = System.Byte;
|
||||||
|
// ReSharper disable BuiltInTypeReferenceStyle
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using PkmnLibSharp.FFI;
|
using PkmnLibSharp.FFI;
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.AbilityLibrary;
|
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.AbilityLibrary;
|
||||||
|
@ -7,41 +8,19 @@ namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class AbilityLibrary : DataLibrary<Ability>
|
public class AbilityLibrary : DataLibrary<Ability>
|
||||||
{
|
{
|
||||||
public AbilityLibrary(ulong capacity) : base(Interface.ability_library_new(capacity), true)
|
protected AbilityLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal AbilityLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
public static AbilityLibrary Create(ulong capacity)
|
||||||
{
|
{
|
||||||
|
var handle = Interface.ability_library_new(capacity).Resolve();
|
||||||
|
var self = Resolver.Instance.ResolveAbilityLibrary(handle);
|
||||||
|
self.ReserveCapacity(capacity);
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Destructor() => Interface.ability_library_drop(Ptr);
|
protected override void AddNative(string key, Ability value) =>
|
||||||
|
Interface.ability_library_add(Handle, key.ToPtr(), value.Handle);
|
||||||
public override void Add(string key, Ability value) =>
|
|
||||||
Interface.ability_library_add(Ptr, key.ToPtr(), value.TakeOwnershipAndInvalidate());
|
|
||||||
|
|
||||||
public override int Count => (int)Interface.ability_library_len(Ptr);
|
|
||||||
|
|
||||||
protected override Ability? GetValueByKey(string key)
|
|
||||||
{
|
|
||||||
var ptr = Interface.ability_library_get(Ptr, key.ToPtr());
|
|
||||||
return ptr.Ptr == IntPtr.Zero ? null : new Ability(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string? GetKeyByIndex(ulong index) =>
|
|
||||||
Interface.ability_library_get_key_by_index(Ptr, index).PtrString();
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
|
||||||
foreach (var value in Cache.ValueCache.Values)
|
|
||||||
{
|
|
||||||
value.Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~AbilityLibrary()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,101 +1,49 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData.Libraries
|
namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public abstract class DataLibrary<T> : ExternPointer<DataLibrary<T>.CacheData>, IReadOnlyDictionary<string, T>
|
public abstract class DataLibrary<T> : HandleType, IReadOnlyDictionary<string, T> where T : HandleType
|
||||||
{
|
{
|
||||||
protected DataLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
private Dictionary<string, T> _backingDictionary = new(StringComparer.InvariantCultureIgnoreCase);
|
||||||
|
|
||||||
|
protected DataLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CacheData
|
protected void ReserveCapacity(ulong capacity)
|
||||||
{
|
{
|
||||||
public List<string>? KeyCache { get; internal set; }
|
_backingDictionary = new Dictionary<string, T>((int)capacity, StringComparer.InvariantCultureIgnoreCase);
|
||||||
public Dictionary<string, T> ValueCache { get; } = new();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void Add(string key, T value);
|
|
||||||
public abstract int Count { get; }
|
|
||||||
|
|
||||||
protected abstract T? GetValueByKey(string key);
|
|
||||||
|
|
||||||
public bool ContainsKey(string key)
|
|
||||||
{
|
|
||||||
return GetValueByKey(key) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryGetValue(string key, [NotNullWhen(true)] out T value)
|
|
||||||
{
|
|
||||||
if (Cache.ValueCache.TryGetValue(key, out value) && value != null)
|
|
||||||
return true;
|
|
||||||
var v = GetValueByKey(key);
|
|
||||||
if (v != null)
|
|
||||||
{
|
|
||||||
Cache.ValueCache.Add(key, v);
|
|
||||||
value = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
return v != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T this[string key]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (!TryGetValue(key, out var value))
|
|
||||||
throw new KeyNotFoundException($"Value with key `{key}` was not found");
|
|
||||||
return value!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract string? GetKeyByIndex(ulong index);
|
|
||||||
|
|
||||||
public IEnumerable<string> Keys
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (Cache.KeyCache == null)
|
|
||||||
{
|
|
||||||
Cache.KeyCache = new List<string>(Count);
|
|
||||||
for (ulong i = 0; i < (ulong)Count; i++)
|
|
||||||
{
|
|
||||||
var key = GetKeyByIndex(i);
|
|
||||||
if (key == null)
|
|
||||||
break;
|
|
||||||
Cache.KeyCache.Add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Cache.KeyCache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<T> Values
|
|
||||||
{
|
|
||||||
get { return Keys.Select(key => this[key]); }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
|
|
||||||
public IEnumerator<KeyValuePair<string, T>> GetEnumerator()
|
public IEnumerator<KeyValuePair<string, T>> GetEnumerator()
|
||||||
{
|
{
|
||||||
return Keys.Select(key => new KeyValuePair<string, T>(key, this[key])).GetEnumerator();
|
return _backingDictionary.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
{
|
{
|
||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
~DataLibrary()
|
protected abstract void AddNative(string key, T value);
|
||||||
|
|
||||||
|
public void Add(string key, T value)
|
||||||
{
|
{
|
||||||
Dispose();
|
AddNative(key, value);
|
||||||
|
_backingDictionary.Add(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Count => _backingDictionary.Count;
|
||||||
|
public bool ContainsKey(string key) => _backingDictionary.ContainsKey(key);
|
||||||
|
|
||||||
|
public bool TryGetValue(string key, out T value) => _backingDictionary.TryGetValue(key, out value);
|
||||||
|
|
||||||
|
public T this[string key] => _backingDictionary[key];
|
||||||
|
|
||||||
|
public IEnumerable<string> Keys => _backingDictionary.Keys;
|
||||||
|
public IEnumerable<T> Values => _backingDictionary.Values;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,43 +1,43 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Collections.Generic;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.GrowthRateLibrary;
|
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.GrowthRateLibrary;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData.Libraries
|
namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class GrowthRateLibrary : ExternPointer<object>
|
public class GrowthRateLibrary : HandleType
|
||||||
{
|
{
|
||||||
public GrowthRateLibrary(ulong capacity) : base(Interface.growth_rate_library_new(capacity), true)
|
// ReSharper disable once CollectionNeverQueried.Local
|
||||||
|
private Dictionary<string, GrowthRate> _growthRates = new();
|
||||||
|
|
||||||
|
protected GrowthRateLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal GrowthRateLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[MustUseReturnValue]
|
|
||||||
public LevelInt CalculateLevel(string growthRate, uint experience) =>
|
|
||||||
Interface.growth_rate_library_calculate_level(Ptr, growthRate.ToPtr(), experience);
|
|
||||||
|
|
||||||
[MustUseReturnValue]
|
|
||||||
public uint CalculateExperience(string growthRate, LevelInt level)
|
|
||||||
{
|
|
||||||
Debug.Assert(level >= 1);
|
|
||||||
return Interface.growth_rate_library_calculate_experience(Ptr, growthRate.ToPtr(), level);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddGrowthRate(string name, GrowthRate growthRate) =>
|
|
||||||
Interface.growth_rate_library_add_growth_rate(Ptr, name.ToPtr(), growthRate.TakeOwnershipAndInvalidate());
|
|
||||||
|
|
||||||
protected override object CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.growth_rate_library_drop(Ptr);
|
|
||||||
|
|
||||||
~GrowthRateLibrary()
|
public static GrowthRateLibrary Create(ulong capacity)
|
||||||
{
|
{
|
||||||
Dispose();
|
var handle = Interface.growth_rate_library_new(capacity);
|
||||||
|
var lib = Resolver.Instance.ResolveGrowthRateLibrary(handle.Resolve());
|
||||||
|
if (capacity > 0)
|
||||||
|
lib._growthRates = new Dictionary<string, GrowthRate>((int)capacity, StringComparer.InvariantCultureIgnoreCase);
|
||||||
|
return lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MustUseReturnValue]
|
||||||
|
public LevelInt CalculateLevel(string name, uint experience) =>
|
||||||
|
Interface.growth_rate_library_calculate_level(Handle, name.ToPtr(), experience).Result();
|
||||||
|
|
||||||
|
[MustUseReturnValue]
|
||||||
|
public uint CalculateExperience(string name, LevelInt level)
|
||||||
|
{
|
||||||
|
return Interface.growth_rate_library_calculate_experience(Handle, name.ToPtr(), level).Result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddGrowthRate(string name, GrowthRate growthRate)
|
||||||
|
{
|
||||||
|
Interface.growth_rate_library_add_growth_rate(Handle, name.ToPtr(), growthRate.Handle);
|
||||||
|
_growthRates.Add(name, growthRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,41 +7,19 @@ namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class ItemLibrary : DataLibrary<Item>
|
public class ItemLibrary : DataLibrary<Item>
|
||||||
{
|
{
|
||||||
public ItemLibrary(ulong capacity) : base(Interface.item_library_new(capacity), true)
|
protected ItemLibrary(FFIHandle handle) : base(handle){}
|
||||||
|
|
||||||
|
public static ItemLibrary Create(ulong capacity)
|
||||||
{
|
{
|
||||||
|
var handle = Interface.item_library_new(capacity).Resolve();
|
||||||
|
var self = Resolver.Instance.ResolveItemLibrary(handle);
|
||||||
|
self.ReserveCapacity(capacity);
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal ItemLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
protected override void AddNative(string key, Item value)
|
||||||
{
|
{
|
||||||
}
|
Interface.item_library_add(Handle, key.ToPtr(), value.Handle);
|
||||||
|
|
||||||
protected override void Destructor() => Interface.item_library_drop(Ptr);
|
|
||||||
|
|
||||||
public override void Add(string key, Item value) =>
|
|
||||||
Interface.item_library_add(Ptr, key.ToPtr(), value.TakeOwnershipAndInvalidate());
|
|
||||||
|
|
||||||
public override int Count => (int)Interface.item_library_len(Ptr);
|
|
||||||
|
|
||||||
protected override Item? GetValueByKey(string key)
|
|
||||||
{
|
|
||||||
var ptr = Interface.item_library_get(Ptr, key.ToPtr());
|
|
||||||
return ptr.Ptr == IntPtr.Zero ? null : new Item(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string? GetKeyByIndex(ulong index) =>
|
|
||||||
Interface.item_library_get_key_by_index(Ptr, index).PtrString();
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
|
||||||
foreach (var value in Cache.ValueCache.Values)
|
|
||||||
{
|
|
||||||
value.Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~ItemLibrary()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,13 +8,9 @@ namespace PkmnLibSharp.StaticData.Libraries
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This library holds several misc settings for the library.
|
/// This library holds several misc settings for the library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LibrarySettings : ExternPointer<LibrarySettings.CacheData>
|
public class LibrarySettings : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected LibrarySettings(FFIHandle handle) : base(handle) {}
|
||||||
{
|
|
||||||
public LevelInt? MaxLevel { get; internal set; }
|
|
||||||
public uint? ShinyRate { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="LibrarySettings"/>
|
/// <inheritdoc cref="LibrarySettings"/>
|
||||||
/// <param name="maxLevel">The highest level a Pokemon can be.</param>
|
/// <param name="maxLevel">The highest level a Pokemon can be.</param>
|
||||||
|
@ -22,35 +18,23 @@ namespace PkmnLibSharp.StaticData.Libraries
|
||||||
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
|
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
|
||||||
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
|
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
|
||||||
/// </param>
|
/// </param>
|
||||||
public LibrarySettings(LevelInt maxLevel, uint shinyRate)
|
public static LibrarySettings Create(LevelInt maxLevel, uint shinyRate)
|
||||||
{
|
|
||||||
Debug.Assert(maxLevel >= 1);
|
|
||||||
Debug.Assert(shinyRate >= 1);
|
|
||||||
InitializePointer(Interface.library_settings_new(maxLevel, shinyRate), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal LibrarySettings(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
{
|
||||||
|
var handle = Interface.library_settings_new(maxLevel, shinyRate).Result();
|
||||||
|
return Resolver.Instance.ResolveLibrarySettings(handle.Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LevelInt? _maxLevel;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The highest level a Pokemon can be.
|
/// The highest level a Pokemon can be.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LevelInt MaxLevel => Cache.MaxLevel ??= Interface.library_settings_maximum_level(Ptr);
|
public LevelInt MaxLevel => _maxLevel ??= Interface.library_settings_maximum_level(Handle);
|
||||||
|
|
||||||
|
private uint? _shinyRate;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
|
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
|
||||||
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
|
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint ShinyRate => Cache.ShinyRate ??= Interface.library_settings_shiny_rate(Ptr);
|
public uint ShinyRate => _shinyRate ??= Interface.library_settings_shiny_rate(Handle);
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.library_settings_drop(Ptr);
|
|
||||||
|
|
||||||
~LibrarySettings()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,44 +8,19 @@ namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class MoveLibrary : DataLibrary<MoveData>
|
public class MoveLibrary : DataLibrary<MoveData>
|
||||||
{
|
{
|
||||||
public MoveLibrary(ulong capacity) : base(Interface.move_library_new(capacity), true)
|
protected MoveLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal MoveLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
Interface.move_library_drop(Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Add(string key, MoveData value) =>
|
|
||||||
Interface.move_library_add(Ptr, key.ToPtr(), value.TakeOwnershipAndInvalidate());
|
|
||||||
|
|
||||||
public override int Count => (int)Interface.move_library_len(Ptr);
|
|
||||||
|
|
||||||
protected override MoveData? GetValueByKey(string key)
|
|
||||||
{
|
|
||||||
var ptr = Interface.move_library_get(Ptr, key.ToPtr());
|
|
||||||
return ptr.Ptr == IntPtr.Zero ? null : new MoveData(ptr, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string? GetKeyByIndex(ulong index) =>
|
|
||||||
Interface.move_library_get_key_by_index(Ptr, index).PtrString();
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
|
||||||
foreach (var value in Cache.ValueCache.Values)
|
|
||||||
{
|
|
||||||
value.Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~MoveLibrary()
|
public static MoveLibrary Create(ulong capacity)
|
||||||
{
|
{
|
||||||
Dispose();
|
var handle = Interface.move_library_new(capacity);
|
||||||
|
return Resolver.Instance.ResolveMoveLibrary(handle.Resolve());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void AddNative(string key, MoveData value)
|
||||||
|
{
|
||||||
|
Interface.move_library_add(Handle, key.ToPtr(), value.Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PkmnLibSharp.FFI;
|
using PkmnLibSharp.FFI;
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
|
@ -7,65 +8,50 @@ using Interface = PkmnLibSharp.FFI.StaticData.Libraries.NatureLibrary;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData.Libraries
|
namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class NatureLibrary : ExternPointer<NatureLibrary.CacheData>
|
public class NatureLibrary : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
private Dictionary<string, Nature> _natures = new();
|
||||||
{
|
|
||||||
public Dictionary<string, Nature> Natures { get; } = new(StringComparer.InvariantCultureIgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NatureLibrary(ulong capacity) : base(Interface.nature_library_new(capacity), true)
|
protected NatureLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal NatureLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
public static NatureLibrary Create(ulong capacity)
|
||||||
{
|
{
|
||||||
}
|
var handle = Interface.nature_library_new(capacity);
|
||||||
|
var lib = Resolver.Instance.ResolveNatureLibrary(handle.Resolve());
|
||||||
public Optional<Nature> TryGetNature(string name)
|
if (capacity > 0)
|
||||||
{
|
lib._natures = new Dictionary<string, Nature>((int)capacity, StringComparer.InvariantCultureIgnoreCase);
|
||||||
if (Cache.Natures.TryGetValue(name, out var nature))
|
return lib;
|
||||||
return nature;
|
|
||||||
var naturePtr = Interface.nature_library_get_nature(Ptr, name.ToPtr());
|
|
||||||
if (naturePtr.Ptr == IntPtr.Zero)
|
|
||||||
return Optional<Nature>.None();
|
|
||||||
nature = new Nature(naturePtr);
|
|
||||||
Cache.Natures.Add(name, nature);
|
|
||||||
return nature;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Nature GetRandomNature(ulong seed)
|
public bool TryGetNature(string name, [NotNullWhen(true)] out Nature? nature)
|
||||||
{
|
{
|
||||||
return new Nature(Interface.nature_library_get_random_nature(Ptr, seed));
|
if (_natures.TryGetValue(name, out nature))
|
||||||
|
return true;
|
||||||
|
var naturePtr = Interface.nature_library_get_nature(Handle, name.ToPtr());
|
||||||
|
if (naturePtr.Handle == 0)
|
||||||
|
return false;
|
||||||
|
nature = Resolver.Instance.ResolveNature(naturePtr.Resolve());
|
||||||
|
_natures.Add(name, nature);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Nature GetRandomNature(ulong seed)
|
||||||
|
{
|
||||||
|
return Resolver.Instance.ResolveNature(Interface.nature_library_get_random_nature(Handle, seed).Result().Resolve());
|
||||||
|
}
|
||||||
|
|
||||||
public string GetNatureName(Nature nature)
|
public string GetNatureName(Nature nature)
|
||||||
{
|
{
|
||||||
var fd = Cache.Natures.FirstOrDefault(x => x.Value == nature);
|
var fd = _natures.FirstOrDefault(x => x.Value == nature);
|
||||||
return fd.Key ?? Interface.nature_library_get_nature_name(Ptr, nature.Ptr).PtrString()!;
|
return fd.Key ?? Interface.nature_library_get_nature_name(Handle, nature.Handle).PtrString()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadNature(string name, Nature nature) =>
|
public void LoadNature(string name, Nature nature)
|
||||||
Interface.nature_library_load_nature(Ptr, name.ToPtr(), nature.TakeOwnershipAndInvalidate());
|
|
||||||
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.nature_library_drop(Ptr);
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
{
|
||||||
base.InvalidateChildren();
|
Interface.nature_library_load_nature(Handle, name.ToPtr(), nature.Handle);
|
||||||
foreach (var nature in Cache.Natures.Values)
|
_natures.Add(name, nature);
|
||||||
{
|
|
||||||
nature.Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~NatureLibrary()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,3 @@
|
||||||
using System;
|
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.SpeciesLibrary;
|
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.SpeciesLibrary;
|
||||||
|
|
||||||
|
@ -7,41 +5,22 @@ namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class SpeciesLibrary : DataLibrary<Species>
|
public class SpeciesLibrary : DataLibrary<Species>
|
||||||
{
|
{
|
||||||
public SpeciesLibrary(ulong capacity) : base(Interface.species_library_new(capacity), true)
|
protected SpeciesLibrary(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal SpeciesLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.species_library_drop(Ptr);
|
|
||||||
|
|
||||||
public override void Add(string key, Species value) =>
|
|
||||||
Interface.species_library_add(Ptr, key.ToPtr(), value.TakeOwnershipAndInvalidate());
|
|
||||||
|
|
||||||
public override int Count => (int)Interface.species_library_len(Ptr);
|
|
||||||
|
|
||||||
protected override Species? GetValueByKey(string key)
|
|
||||||
{
|
|
||||||
var ptr = Interface.species_library_get(Ptr, key.ToPtr());
|
|
||||||
return ptr.Ptr == IntPtr.Zero ? null : new Species(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string? GetKeyByIndex(ulong index) =>
|
public static SpeciesLibrary Create(ulong capacity)
|
||||||
Interface.species_library_get_key_by_index(Ptr, index).PtrString();
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
{
|
||||||
foreach (var value in Cache.ValueCache.Values)
|
var handle = Interface.species_library_new(capacity);
|
||||||
{
|
var lib = Resolver.Instance.ResolveSpeciesLibrary(handle.Resolve());
|
||||||
value.Invalidate();
|
if (capacity > 0)
|
||||||
}
|
lib.ReserveCapacity(capacity);
|
||||||
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
~SpeciesLibrary()
|
protected override void AddNative(string key, Species value)
|
||||||
{
|
{
|
||||||
Dispose();
|
Interface.species_library_add(Handle, key.ToPtr(), value.Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,82 +1,40 @@
|
||||||
using JetBrains.Annotations;
|
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.StaticData;
|
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.StaticData;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData.Libraries
|
namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class StaticData : ExternPointer<StaticData.CacheData>
|
public class StaticData : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected StaticData(FFIHandle handle) : base(handle)
|
||||||
{
|
|
||||||
public LibrarySettings? Settings { get; internal set; }
|
|
||||||
public SpeciesLibrary? SpeciesLibrary { get; internal set; }
|
|
||||||
public MoveLibrary? MoveLibrary { get; internal set; }
|
|
||||||
public ItemLibrary? ItemLibrary { get; internal set; }
|
|
||||||
public GrowthRateLibrary? GrowthRateLibrary { get; internal set; }
|
|
||||||
public TypeLibrary? TypeLibrary { get; internal set; }
|
|
||||||
public NatureLibrary? NatureLibrary { get; internal set; }
|
|
||||||
public AbilityLibrary? AbilityLibrary { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal StaticData(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner){}
|
|
||||||
|
|
||||||
public StaticData(LibrarySettings settings, SpeciesLibrary speciesLibrary, MoveLibrary moveLibrary,
|
|
||||||
ItemLibrary itemLibrary, GrowthRateLibrary growthRateLibrary, TypeLibrary typeLibrary,
|
|
||||||
NatureLibrary natureLibrary, AbilityLibrary abilityLibrary) : base(
|
|
||||||
Interface.static_data_new(settings.TakeOwnershipAndInvalidate(),
|
|
||||||
speciesLibrary.TakeOwnershipAndInvalidate(), moveLibrary.TakeOwnershipAndInvalidate(),
|
|
||||||
itemLibrary.TakeOwnershipAndInvalidate(), growthRateLibrary.TakeOwnershipAndInvalidate(),
|
|
||||||
typeLibrary.TakeOwnershipAndInvalidate(), natureLibrary.TakeOwnershipAndInvalidate(),
|
|
||||||
abilityLibrary.TakeOwnershipAndInvalidate()), true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public LibrarySettings LibrarySettings =>
|
public static StaticData Create(LibrarySettings settings, SpeciesLibrary speciesLibrary,
|
||||||
Cache.Settings ??= new LibrarySettings(Interface.static_data_settings(Ptr), false);
|
MoveLibrary moveLibrary, ItemLibrary itemLibrary, GrowthRateLibrary growthRateLibrary,
|
||||||
|
TypeLibrary typeLibrary, NatureLibrary natureLibrary, AbilityLibrary abilityLibrary)
|
||||||
public SpeciesLibrary SpeciesLibrary =>
|
|
||||||
Cache.SpeciesLibrary ??= new SpeciesLibrary(Interface.static_data_species(Ptr), false);
|
|
||||||
|
|
||||||
public MoveLibrary MoveLibrary =>
|
|
||||||
Cache.MoveLibrary ??= new MoveLibrary(Interface.static_data_moves(Ptr), false);
|
|
||||||
|
|
||||||
public ItemLibrary ItemLibrary =>
|
|
||||||
Cache.ItemLibrary ??= new ItemLibrary(Interface.static_data_items(Ptr), false);
|
|
||||||
|
|
||||||
public GrowthRateLibrary GrowthRateLibrary =>
|
|
||||||
Cache.GrowthRateLibrary ??= new GrowthRateLibrary(Interface.static_data_growth_rates(Ptr), false);
|
|
||||||
|
|
||||||
public TypeLibrary TypeLibrary =>
|
|
||||||
Cache.TypeLibrary ??= new TypeLibrary(Interface.static_data_types(Ptr), false);
|
|
||||||
|
|
||||||
public NatureLibrary NatureLibrary =>
|
|
||||||
Cache.NatureLibrary ??= new NatureLibrary(Interface.static_data_natures(Ptr), false);
|
|
||||||
|
|
||||||
public AbilityLibrary AbilityLibrary =>
|
|
||||||
Cache.AbilityLibrary ??= new AbilityLibrary(Interface.static_data_abilities(Ptr), false);
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.static_data_drop(Ptr);
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
{
|
||||||
if (!HasCache)
|
var handle = Interface.static_data_new(settings.Handle, speciesLibrary.Handle, moveLibrary.Handle,
|
||||||
return;
|
itemLibrary.Handle, growthRateLibrary.Handle, typeLibrary.Handle, natureLibrary.Handle,
|
||||||
Cache.Settings?.Invalidate();
|
abilityLibrary.Handle);
|
||||||
Cache.SpeciesLibrary?.Invalidate();
|
var data = Resolver.Instance.ResolveStaticData(handle.Resolve());
|
||||||
Cache.MoveLibrary?.Invalidate();
|
data.LibrarySettings = settings;
|
||||||
Cache.ItemLibrary?.Invalidate();
|
data.SpeciesLibrary = speciesLibrary;
|
||||||
Cache.GrowthRateLibrary?.Invalidate();
|
data.MoveLibrary = moveLibrary;
|
||||||
Cache.TypeLibrary?.Invalidate();
|
data.ItemLibrary = itemLibrary;
|
||||||
Cache.NatureLibrary?.Invalidate();
|
data.GrowthRateLibrary = growthRateLibrary;
|
||||||
Cache.AbilityLibrary?.Invalidate();
|
data.TypeLibrary = typeLibrary;
|
||||||
|
data.NatureLibrary = natureLibrary;
|
||||||
|
data.AbilityLibrary = abilityLibrary;
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
~StaticData()
|
public LibrarySettings LibrarySettings { get; private set; } = null!;
|
||||||
{
|
public SpeciesLibrary SpeciesLibrary { get; private set; } = null!;
|
||||||
Dispose();
|
public MoveLibrary MoveLibrary { get; private set; } = null!;
|
||||||
}
|
public ItemLibrary ItemLibrary { get; private set; } = null!;
|
||||||
|
public GrowthRateLibrary GrowthRateLibrary { get; private set; } = null!;
|
||||||
|
public TypeLibrary TypeLibrary { get; private set; } = null!;
|
||||||
|
public NatureLibrary NatureLibrary { get; private set; } = null!;
|
||||||
|
public AbilityLibrary AbilityLibrary { get; private set; } = null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,32 +7,31 @@ using Interface = PkmnLibSharp.FFI.StaticData.Libraries.TypeLibrary;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData.Libraries
|
namespace PkmnLibSharp.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class TypeLibrary : ExternPointer<TypeLibrary.CacheData>
|
public class TypeLibrary : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
public Dictionary<string, TypeIdentifier> TypeCache { get; private set; } =
|
||||||
{
|
new(StringComparer.InvariantCultureIgnoreCase);
|
||||||
public Dictionary<string, TypeIdentifier> TypeCache { get; } =
|
|
||||||
new(StringComparer.InvariantCultureIgnoreCase);
|
protected TypeLibrary(FFIHandle handle) : base(handle){}
|
||||||
}
|
|
||||||
|
public static TypeLibrary Create(ulong capacity)
|
||||||
public TypeLibrary(ulong capacity) : base(Interface.type_library_new(capacity), true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
internal TypeLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
{
|
||||||
|
var handle = Interface.type_library_new(capacity);
|
||||||
|
var lib = Resolver.Instance.ResolveTypeLibrary(handle.Resolve());
|
||||||
|
lib.TypeCache = new Dictionary<string, TypeIdentifier>((int)capacity, StringComparer.InvariantCultureIgnoreCase);
|
||||||
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeIdentifier GetTypeId(string name)
|
public TypeIdentifier GetTypeId(string name)
|
||||||
{
|
{
|
||||||
if (Cache.TypeCache.TryGetValue(name, out var typeIdentifier))
|
if (TypeCache.TryGetValue(name, out var typeIdentifier))
|
||||||
return typeIdentifier;
|
return typeIdentifier;
|
||||||
throw new KeyNotFoundException($"No type found with name `{name}`");
|
throw new KeyNotFoundException($"No type found with name `{name}`");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTypeName(TypeIdentifier typeIdentifier)
|
public string GetTypeName(TypeIdentifier typeIdentifier)
|
||||||
{
|
{
|
||||||
var fd = Cache.TypeCache.FirstOrDefault(x => x.Value == typeIdentifier);
|
var fd = TypeCache.FirstOrDefault(x => x.Value == typeIdentifier);
|
||||||
if (fd.Key != null)
|
if (fd.Key != null)
|
||||||
return fd.Key;
|
return fd.Key;
|
||||||
throw new KeyNotFoundException($"No type found for given identifier");
|
throw new KeyNotFoundException($"No type found for given identifier");
|
||||||
|
@ -40,32 +39,22 @@ namespace PkmnLibSharp.StaticData.Libraries
|
||||||
|
|
||||||
|
|
||||||
public float GetSingleEffectiveness(TypeIdentifier attacking, TypeIdentifier defending) =>
|
public float GetSingleEffectiveness(TypeIdentifier attacking, TypeIdentifier defending) =>
|
||||||
Interface.type_library_get_single_effectiveness(Ptr, attacking, defending);
|
Interface.type_library_get_single_effectiveness(Handle, attacking, defending);
|
||||||
|
|
||||||
public float GetEffectiveness(TypeIdentifier attacking, TypeIdentifier[] defending)
|
public float GetEffectiveness(TypeIdentifier attacking, TypeIdentifier[] defending)
|
||||||
{
|
{
|
||||||
var arrayPtr = defending.ArrayPtr();
|
var arrayPtr = defending.ArrayPtr();
|
||||||
return Interface.type_library_get_effectiveness(Ptr, attacking, arrayPtr, (ulong)defending.Length);
|
return Interface.type_library_get_effectiveness(Handle, attacking, arrayPtr, (ulong)defending.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeIdentifier RegisterType(string name)
|
public TypeIdentifier RegisterType(string name)
|
||||||
{
|
{
|
||||||
var typeId = Interface.type_library_register_type(Ptr, name.ToPtr());
|
var typeId = Interface.type_library_register_type(Handle, name.ToPtr());
|
||||||
Cache.TypeCache.Add(name, typeId);
|
TypeCache.Add(name, typeId);
|
||||||
return typeId;
|
return typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetEffectiveness(TypeIdentifier attacking, TypeIdentifier defending, float effectiveness) =>
|
public void SetEffectiveness(TypeIdentifier attacking, TypeIdentifier defending, float effectiveness) =>
|
||||||
Interface.type_library_set_effectiveness(Ptr, attacking, defending, effectiveness);
|
Interface.type_library_set_effectiveness(Handle, attacking, defending, effectiveness);
|
||||||
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor() => Interface.type_library_drop(Ptr);
|
|
||||||
|
|
||||||
~TypeLibrary()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.MoveData;
|
using Interface = PkmnLibSharp.FFI.StaticData.MoveData;
|
||||||
|
|
||||||
|
@ -62,84 +60,57 @@ namespace PkmnLibSharp.StaticData
|
||||||
SelfUse,
|
SelfUse,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MoveData : ExternPointer<MoveData.CacheData>
|
public class MoveData : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected MoveData(FFIHandle handle) : base(handle) {}
|
||||||
{
|
|
||||||
public string? Name { get; internal set; }
|
public static MoveData Create(string name, TypeIdentifier moveType, MoveCategory category, byte basePower, byte accuracy,
|
||||||
public TypeIdentifier? Type { get; internal set; }
|
|
||||||
public MoveCategory? Category { get; internal set; }
|
|
||||||
public byte? BasePower { get; internal set; }
|
|
||||||
public byte? Accuracy { get; internal set; }
|
|
||||||
public byte? BaseUsages { get; internal set; }
|
|
||||||
public MoveTarget? Target { get; internal set; }
|
|
||||||
public sbyte? Priority { get; internal set; }
|
|
||||||
public SecondaryEffect? SecondaryEffect { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal MoveData(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public MoveData(string name, TypeIdentifier moveType, MoveCategory category, byte basePower, byte accuracy,
|
|
||||||
byte baseUsages, MoveTarget target, sbyte priority, SecondaryEffect? secondaryEffect,
|
byte baseUsages, MoveTarget target, sbyte priority, SecondaryEffect? secondaryEffect,
|
||||||
IEnumerable<string> flags)
|
IEnumerable<string> flags)
|
||||||
{
|
{
|
||||||
var ptrArray = flags.Select(x => x.ToPtr()).ToArray();
|
var ptrArray = flags.Select(x => x.ToPtr()).ToArray();
|
||||||
var ptrToPtrArray = ptrArray.ArrayPtr();
|
var ptrToPtrArray = ptrArray.ArrayPtr();
|
||||||
var ptr = Interface.move_data_new(name.ToPtr(), moveType, category, basePower, accuracy, baseUsages, target,
|
var handle = Interface.move_data_new(name.ToPtr(), moveType, category, basePower, accuracy, baseUsages, target,
|
||||||
priority, secondaryEffect?.TakeOwnershipAndInvalidate() ?? IntPtr.Zero, ptrToPtrArray,
|
priority, secondaryEffect?.Handle ?? FFIHandle.Zero, ptrToPtrArray,
|
||||||
(ulong)ptrArray.Length);
|
(ulong)ptrArray.Length);
|
||||||
InitializePointer(ptr, true);
|
return Resolver.Instance.ResolveMoveData(handle.Result().Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => Cache.Name ??= Interface.move_data_name(Ptr).PtrString()!;
|
private string? _name;
|
||||||
public TypeIdentifier Type => Cache.Type ??= Interface.move_data_move_type(Ptr);
|
public string Name => _name ??= Interface.move_data_name(Handle).Result().PtrString()!;
|
||||||
public byte BasePower => Cache.BasePower ??= Interface.move_data_base_power(Ptr);
|
private TypeIdentifier? _type;
|
||||||
public MoveCategory Category => Cache.Category ??= Interface.move_data_category(Ptr);
|
public TypeIdentifier Type => _type ??= Interface.move_data_move_type(Handle);
|
||||||
public byte Accuracy => Cache.Accuracy ??= Interface.move_data_accuracy(Ptr);
|
private byte? _basePower;
|
||||||
public byte BaseUsages => Cache.BaseUsages ??= Interface.move_data_base_usages(Ptr);
|
public byte BasePower => _basePower ??= Interface.move_data_base_power(Handle);
|
||||||
public MoveTarget Target => Cache.Target ??= Interface.move_data_target(Ptr);
|
private MoveCategory? _category;
|
||||||
public sbyte Priority => Cache.Priority ??= Interface.move_data_priority(Ptr);
|
public MoveCategory Category => _category ??= Interface.move_data_category(Handle);
|
||||||
|
private byte? _accuracy;
|
||||||
|
public byte Accuracy => _accuracy ??= Interface.move_data_accuracy(Handle);
|
||||||
|
private byte? _baseUsages;
|
||||||
|
public byte BaseUsages => _baseUsages ??= Interface.move_data_base_usages(Handle);
|
||||||
|
private MoveTarget? _target;
|
||||||
|
public MoveTarget Target => _target ??= Interface.move_data_target(Handle);
|
||||||
|
private sbyte? _priority;
|
||||||
|
public sbyte Priority => _priority ??= Interface.move_data_priority(Handle);
|
||||||
|
|
||||||
|
private SecondaryEffect? _secondaryEffect;
|
||||||
public SecondaryEffect? SecondaryEffect
|
public SecondaryEffect? SecondaryEffect
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Cache.SecondaryEffect != null)
|
if (_secondaryEffect != null)
|
||||||
return Cache.SecondaryEffect;
|
return _secondaryEffect;
|
||||||
var effect = Interface.move_data_secondary_effect(Ptr);
|
var effect = Interface.move_data_secondary_effect(Handle);
|
||||||
if (effect.Ptr == IntPtr.Zero)
|
if (effect.Handle == 0)
|
||||||
return null;
|
return null;
|
||||||
Cache.SecondaryEffect = new SecondaryEffect(effect, false);
|
_secondaryEffect = Resolver.Instance.ResolveSecondaryEffect(effect.Resolve());
|
||||||
return Cache.SecondaryEffect;
|
return _secondaryEffect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasFlag(string flag)
|
public bool HasFlag(string flag)
|
||||||
{
|
{
|
||||||
return Interface.move_data_has_flag(Ptr, flag.ToPtr()) == 1;
|
return Interface.move_data_has_flag(Handle, flag.ToPtr()) == 1;
|
||||||
}
|
|
||||||
|
|
||||||
protected override CacheData CreateCache()
|
|
||||||
{
|
|
||||||
return new CacheData();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
Interface.move_data_drop(Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
|
||||||
base.InvalidateChildren();
|
|
||||||
Cache.SecondaryEffect?.Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
~MoveData()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,62 +1,41 @@
|
||||||
using System;
|
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Nature;
|
using Interface = PkmnLibSharp.FFI.StaticData.Nature;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class Nature : ExternPointer<Nature.CacheData>
|
public class Nature : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected Nature(FFIHandle handle) : base(handle)
|
||||||
{
|
|
||||||
public Statistic? IncreasedStat { get; internal set; }
|
|
||||||
public Statistic? DecreasedStat { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Nature(Statistic increasedStat, Statistic decreasedStat, float increaseModifier = 1.1f,
|
|
||||||
float decreaseModifier = 0.9f) : base(
|
|
||||||
Interface.nature_new(increasedStat, decreasedStat, increaseModifier, decreaseModifier), true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Nature(IdentifiablePointer ptr) : base(ptr, true)
|
public static Nature Create(Statistic increasedStat, Statistic decreasedStat, float increaseModifier = 1.1f,
|
||||||
|
float decreaseModifier = 0.9f)
|
||||||
{
|
{
|
||||||
|
var handle = Interface.nature_new(increasedStat, decreasedStat, increaseModifier, decreaseModifier);
|
||||||
|
return Resolver.Instance.ResolveNature(handle.Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Nature NeutralNature()
|
public static Nature NeutralNature()
|
||||||
{
|
{
|
||||||
return new Nature(Statistic.HP, Statistic.HP, 1f, 1f);
|
return Create(Statistic.HP, Statistic.HP, 1f, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Statistic? _increasedStat;
|
||||||
public Statistic IncreasedStat
|
public Statistic IncreasedStat
|
||||||
{
|
{
|
||||||
get { return Cache.IncreasedStat ??= Interface.nature_increased_stat(Ptr); }
|
get { return _increasedStat ??= Interface.nature_increased_stat(Handle); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Statistic? _decreasedStat;
|
||||||
public Statistic DecreasedStat
|
public Statistic DecreasedStat
|
||||||
{
|
{
|
||||||
get { return Cache.DecreasedStat ??= Interface.nature_decreased_stat(Ptr); }
|
get { return _decreasedStat ??= Interface.nature_decreased_stat(Handle); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetStatModifier(Statistic statistic)
|
public float GetStatModifier(Statistic statistic)
|
||||||
{
|
{
|
||||||
return Interface.nature_get_stat_modifier(Ptr, statistic);
|
return Interface.nature_get_stat_modifier(Handle, statistic);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected override CacheData CreateCache()
|
|
||||||
{
|
|
||||||
return new CacheData();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
Interface.nature_drop(Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
~Nature()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,70 +1,33 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.MoveData;
|
using Interface = PkmnLibSharp.FFI.StaticData.MoveData;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class SecondaryEffect : ExternPointer<SecondaryEffect.CacheData>
|
public class SecondaryEffect : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected SecondaryEffect(FFIHandle handle) : base(handle)
|
||||||
{
|
|
||||||
public float? Chance { get; internal set; }
|
|
||||||
public string? Name { get; internal set; }
|
|
||||||
public DisposableCachedExternArray<EffectParameter>? Parameters { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal SecondaryEffect(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecondaryEffect(float chance, string effectName, IReadOnlyCollection<EffectParameter> parameters)
|
public static SecondaryEffect Create(float chance, string effectName, IReadOnlyList<EffectParameter> parameters)
|
||||||
{
|
{
|
||||||
var parameterPtrs = parameters.Select(x => x.TakeOwnershipAndInvalidate()).ToArray();
|
var parameterPtrs = parameters.Select(x => (FFIHandleValue)x.Handle).ToArray();
|
||||||
var parameterArrayPtr = parameterPtrs.ArrayPtr();
|
var parameterArrayPtr = parameterPtrs.ArrayPtr();
|
||||||
InitializePointer(
|
var handle = Interface.secondary_effect_new(chance, effectName.ToPtr(), parameterArrayPtr,
|
||||||
Interface.secondary_effect_new(chance, effectName.ToPtr(), parameterArrayPtr, (ulong)parameters.Count),
|
(ulong)parameters.Count);
|
||||||
true);
|
var effect = Resolver.Instance.ResolveSecondaryEffect(handle.Resolve());
|
||||||
|
effect.Parameters = parameters;
|
||||||
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Chance => Cache.Chance ??= Interface.secondary_effect_chance(Ptr);
|
private float? _chance;
|
||||||
public string Name => Cache.Name ?? (Cache.Name = Interface.secondary_effect_effect_name(Ptr).PtrString()!);
|
public float Chance => _chance ??= Interface.secondary_effect_chance(Handle);
|
||||||
|
|
||||||
|
private string? _name;
|
||||||
|
public string Name => _name ??= Interface.secondary_effect_effect_name(Handle).Result().PtrString()!;
|
||||||
|
|
||||||
public IReadOnlyList<EffectParameter> GetParameters()
|
public IReadOnlyList<EffectParameter> Parameters { get; private set; } = null!;
|
||||||
{
|
|
||||||
return Cache.Parameters ??= new DisposableCachedExternArray<EffectParameter>(
|
|
||||||
Interface.secondary_effect_parameter_length(Ptr),
|
|
||||||
arg => new EffectParameter(Interface.secondary_effect_parameter_get(Ptr, arg), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override CacheData CreateCache()
|
|
||||||
{
|
|
||||||
return new CacheData();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
Interface.secondary_effect_drop(Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
|
||||||
base.InvalidateChildren();
|
|
||||||
if (Cache.Parameters != null)
|
|
||||||
{
|
|
||||||
for (var index = 0; index < Cache.Parameters.Count; index++)
|
|
||||||
{
|
|
||||||
Cache.Parameters.GetCachedValue(index)?.Invalidate();
|
|
||||||
}
|
|
||||||
Cache.Parameters.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~SecondaryEffect()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,42 +2,38 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.Species;
|
using Interface = PkmnLibSharp.FFI.StaticData.Species;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class Species : ExternPointer<Species.CacheData>
|
public class Species : HandleType
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected Species(FFIHandle handle) : base(handle)
|
||||||
{
|
|
||||||
public ushort? Id { get; internal set; }
|
|
||||||
public string? Name { get; internal set; }
|
|
||||||
public float? GenderRate { get; internal set; }
|
|
||||||
public string? GrowthRate { get; internal set; }
|
|
||||||
public byte? CaptureRate { get; internal set; }
|
|
||||||
public Dictionary<string, Form> Forms { get; } = new();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal Species(IdentifiablePointer ptr) : base(ptr, true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Species(ushort id, string name, float genderRate, string growthRate, byte captureRate, Form defaultForm,
|
public static Species Create(ushort id, string name, float genderRate, string growthRate, byte captureRate, Form defaultForm,
|
||||||
IReadOnlyCollection<string> flags)
|
IReadOnlyCollection<string> flags)
|
||||||
{
|
{
|
||||||
var flagsPtrArray = flags.Select(x => x.ToPtr()).ToArray();
|
var flagsPtrArray = flags.Select(x => x.ToPtr()).ToArray();
|
||||||
var ptr = Interface.species_new(id, name.ToPtr(), genderRate, growthRate.ToPtr(), captureRate,
|
var handle = Interface.species_new(id, name.ToPtr(), genderRate, growthRate.ToPtr(), captureRate,
|
||||||
defaultForm.Ptr, flagsPtrArray.ArrayPtr(), (ulong)flags.Count);
|
defaultForm.Handle, flagsPtrArray.ArrayPtr(), (ulong)flags.Count);
|
||||||
InitializePointer(ptr, true);
|
var species = Resolver.Instance.ResolveSpecies(handle.Result().Resolve());
|
||||||
|
species._forms.Add("default", defaultForm);
|
||||||
|
return species;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ushort Id => Cache.Id ??= Interface.species_id(Ptr);
|
private ushort? _id;
|
||||||
public string Name => Cache.Name ??= Interface.species_name(Ptr).PtrString()!;
|
public ushort Id => _id ??= Interface.species_id(Handle);
|
||||||
public float GenderRate => Cache.GenderRate ??= Interface.species_gender_rate(Ptr);
|
private string? _name;
|
||||||
public string GrowthRate => Cache.GrowthRate ??= Interface.species_growth_rate(Ptr).PtrString()!;
|
public string Name => _name ??= Interface.species_name(Handle).PtrString()!;
|
||||||
public byte CaptureRate => Cache.CaptureRate ??= Interface.species_capture_rate(Ptr);
|
private float? _genderRate;
|
||||||
|
public float GenderRate => _genderRate ??= Interface.species_gender_rate(Handle);
|
||||||
|
private string? _growthRate;
|
||||||
|
public string GrowthRate => _growthRate ??= Interface.species_growth_rate(Handle).PtrString()!;
|
||||||
|
private byte? _captureRate;
|
||||||
|
public byte CaptureRate => _captureRate ??= Interface.species_capture_rate(Handle);
|
||||||
|
|
||||||
public Form DefaultForm
|
public Form DefaultForm
|
||||||
{
|
{
|
||||||
|
@ -48,42 +44,29 @@ namespace PkmnLibSharp.StaticData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Dictionary<string, Form> _forms = new(StringComparer.InvariantCultureIgnoreCase);
|
||||||
public bool TryGetForm(string formName, [NotNullWhen(true)] out Form? form)
|
public bool TryGetForm(string formName, [NotNullWhen(true)] out Form? form)
|
||||||
{
|
{
|
||||||
if (Cache.Forms.TryGetValue(formName, out form))
|
if (_forms.TryGetValue(formName, out form))
|
||||||
return true;
|
return true;
|
||||||
var formPtr = Interface.species_get_form(Ptr, formName.ToPtr());
|
var formPtr = Interface.species_get_form(Handle, formName.ToPtr());
|
||||||
if (formPtr.Ptr == IntPtr.Zero)
|
if (formPtr.Handle == 0)
|
||||||
{
|
{
|
||||||
form = null;
|
form = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
form = new Form(formPtr);
|
form = Resolver.Instance.ResolveForm(formPtr.Resolve());
|
||||||
Cache.Forms.Add(formName, form);
|
_forms.Add(formName, form);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddForm(Form form) =>
|
public void AddForm(Form form)
|
||||||
Interface.species_add_form(Ptr, form.Name.ToPtr(), form.TakeOwnershipAndInvalidate());
|
|
||||||
|
|
||||||
public Gender GetRandomGender(ulong seed) => Interface.species_get_random_gender(Ptr, seed);
|
|
||||||
|
|
||||||
protected override CacheData CreateCache() => new CacheData();
|
|
||||||
protected override void Destructor() => Interface.species_drop(Ptr);
|
|
||||||
|
|
||||||
public override void InvalidateChildren()
|
|
||||||
{
|
{
|
||||||
base.InvalidateChildren();
|
Interface.species_add_form(Handle, form.Name.ToPtr(), form.Handle).Result();
|
||||||
foreach (var form in Cache.Forms)
|
_forms.Add(form.Name, form);
|
||||||
{
|
|
||||||
form.Value.Invalidate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Species()
|
public Gender GetRandomGender(ulong seed) => Interface.species_get_random_gender(Handle, seed);
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,52 +1,26 @@
|
||||||
using System;
|
using System;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.StaticStatisticSet;
|
using Interface = PkmnLibSharp.FFI.StaticData.StaticStatisticSet;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class StaticStatisticSet<T> : ExternPointer<StaticStatisticSet<T>.CacheData> where T : struct, IConvertible
|
public class StaticStatisticSet<T> : HandleType where T : struct, IConvertible
|
||||||
{
|
{
|
||||||
public class CacheData
|
protected StaticStatisticSet(FFIHandle handle) : base(handle)
|
||||||
{
|
|
||||||
public T? HP { get; internal set; }
|
|
||||||
public T? Attack { get; internal set; }
|
|
||||||
public T? Defense { get; internal set; }
|
|
||||||
public T? SpecialAttack { get; internal set; }
|
|
||||||
public T? SpecialDefense { get; internal set; }
|
|
||||||
public T? Speed { get; internal set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal StaticStatisticSet(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public StaticStatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
public static StaticStatisticSet<T> Create(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
||||||
{
|
{
|
||||||
var p = typeof(T) switch
|
var handle = typeof(T) switch
|
||||||
{
|
{
|
||||||
{ } t when t == typeof(byte) => Interface.static_statistic_set_u8_new(Convert.ToByte(hp),
|
|
||||||
Convert.ToByte(attack), Convert.ToByte(defense), Convert.ToByte(specialAttack),
|
|
||||||
Convert.ToByte(specialDefense), Convert.ToByte(speed)),
|
|
||||||
{ } t when t == typeof(ushort) => Interface.static_statistic_set_u16_new(Convert.ToUInt16(hp),
|
{ } t when t == typeof(ushort) => Interface.static_statistic_set_u16_new(Convert.ToUInt16(hp),
|
||||||
Convert.ToUInt16(attack), Convert.ToUInt16(defense), Convert.ToUInt16(specialAttack),
|
Convert.ToUInt16(attack), Convert.ToUInt16(defense), Convert.ToUInt16(specialAttack),
|
||||||
Convert.ToUInt16(specialDefense), Convert.ToUInt16(speed)),
|
Convert.ToUInt16(specialDefense), Convert.ToUInt16(speed)),
|
||||||
{ } t when t == typeof(uint) => Interface.static_statistic_set_u32_new(Convert.ToUInt32(hp),
|
|
||||||
Convert.ToUInt32(attack), Convert.ToUInt32(defense), Convert.ToUInt32(specialAttack),
|
|
||||||
Convert.ToUInt32(specialDefense), Convert.ToUInt32(speed)),
|
|
||||||
{ } t when t == typeof(sbyte) => Interface.static_statistic_set_i8_new(Convert.ToSByte(hp),
|
|
||||||
Convert.ToSByte(attack), Convert.ToSByte(defense), Convert.ToSByte(specialAttack),
|
|
||||||
Convert.ToSByte(specialDefense), Convert.ToSByte(speed)),
|
|
||||||
{ } t when t == typeof(short) => Interface.static_statistic_set_i16_new(Convert.ToInt16(hp),
|
|
||||||
Convert.ToInt16(attack), Convert.ToInt16(defense), Convert.ToInt16(specialAttack),
|
|
||||||
Convert.ToInt16(specialDefense), Convert.ToInt16(speed)),
|
|
||||||
{ } t when t == typeof(int) => Interface.static_statistic_set_i32_new(Convert.ToInt32(hp),
|
|
||||||
Convert.ToInt32(attack), Convert.ToInt32(defense), Convert.ToInt32(specialAttack),
|
|
||||||
Convert.ToInt32(specialDefense), Convert.ToInt32(speed)),
|
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
};
|
};
|
||||||
InitializePointer(p, true);
|
return Resolver.Instance.ResolveStaticStatisticSet<T>(handle.Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
|
@ -54,86 +28,67 @@ namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
switch (statistic)
|
switch (statistic)
|
||||||
{
|
{
|
||||||
case Statistic.HP when Cache.HP.HasValue:
|
case Statistic.HP when _hp.HasValue:
|
||||||
return Cache.HP.Value;
|
return _hp.Value;
|
||||||
case Statistic.Attack when Cache.Attack.HasValue:
|
case Statistic.Attack when _attack.HasValue:
|
||||||
return Cache.Attack.Value;
|
return _attack.Value;
|
||||||
case Statistic.Defense when Cache.Defense.HasValue:
|
case Statistic.Defense when _defense.HasValue:
|
||||||
return Cache.Defense.Value;
|
return _defense.Value;
|
||||||
case Statistic.SpecialAttack when Cache.SpecialAttack.HasValue:
|
case Statistic.SpecialAttack when _specialAttack.HasValue:
|
||||||
return Cache.SpecialAttack.Value;
|
return _specialAttack.Value;
|
||||||
case Statistic.SpecialDefense when Cache.SpecialDefense.HasValue:
|
case Statistic.SpecialDefense when _specialDefense.HasValue:
|
||||||
return Cache.SpecialDefense.Value;
|
return _specialDefense.Value;
|
||||||
case Statistic.Speed when Cache.Speed.HasValue:
|
case Statistic.Speed when _speed.HasValue:
|
||||||
return Cache.Speed.Value;
|
return _speed.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
object p = typeof(T) switch
|
object p = typeof(T) switch
|
||||||
{
|
{
|
||||||
{ } t when t == typeof(byte) => Interface.static_statistic_set_u8_get_stat(Ptr, statistic),
|
{ } t when t == typeof(ushort) => Interface.static_statistic_set_u16_get_stat(Handle, statistic),
|
||||||
{ } t when t == typeof(ushort) => Interface.static_statistic_set_u16_get_stat(Ptr, statistic),
|
|
||||||
{ } t when t == typeof(uint) => Interface.static_statistic_set_u32_get_stat(Ptr, statistic),
|
|
||||||
{ } t when t == typeof(sbyte) => Interface.static_statistic_set_i8_get_stat(Ptr, statistic),
|
|
||||||
{ } t when t == typeof(short) => Interface.static_statistic_set_i16_get_stat(Ptr, statistic),
|
|
||||||
{ } t when t == typeof(int) => Interface.static_statistic_set_i32_get_stat(Ptr, statistic),
|
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
};
|
};
|
||||||
switch (statistic)
|
switch (statistic)
|
||||||
{
|
{
|
||||||
case Statistic.HP:
|
case Statistic.HP:
|
||||||
Cache.HP = (T)p;
|
_hp = (T)p;
|
||||||
break;
|
break;
|
||||||
case Statistic.Attack:
|
case Statistic.Attack:
|
||||||
Cache.Attack = (T)p;
|
_attack = (T)p;
|
||||||
break;
|
break;
|
||||||
case Statistic.Defense:
|
case Statistic.Defense:
|
||||||
Cache.Defense = (T)p;
|
_defense = (T)p;
|
||||||
break;
|
break;
|
||||||
case Statistic.SpecialAttack:
|
case Statistic.SpecialAttack:
|
||||||
Cache.SpecialAttack = (T)p;
|
_specialAttack = (T)p;
|
||||||
break;
|
break;
|
||||||
case Statistic.SpecialDefense:
|
case Statistic.SpecialDefense:
|
||||||
Cache.SpecialDefense = (T)p;
|
_specialDefense = (T)p;
|
||||||
break;
|
break;
|
||||||
case Statistic.Speed:
|
case Statistic.Speed:
|
||||||
Cache.Speed = (T)p;
|
_speed = (T)p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (T)p;
|
return (T)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private T? _hp;
|
||||||
public T HP => GetStatistic(Statistic.HP);
|
public T HP => GetStatistic(Statistic.HP);
|
||||||
|
|
||||||
|
private T? _attack;
|
||||||
public T Attack => GetStatistic(Statistic.Attack);
|
public T Attack => GetStatistic(Statistic.Attack);
|
||||||
|
|
||||||
|
private T? _defense;
|
||||||
public T Defense => GetStatistic(Statistic.Defense);
|
public T Defense => GetStatistic(Statistic.Defense);
|
||||||
|
|
||||||
|
private T? _specialAttack;
|
||||||
public T SpecialAttack => GetStatistic(Statistic.SpecialAttack);
|
public T SpecialAttack => GetStatistic(Statistic.SpecialAttack);
|
||||||
|
|
||||||
|
private T? _specialDefense;
|
||||||
public T SpecialDefense => GetStatistic(Statistic.SpecialDefense);
|
public T SpecialDefense => GetStatistic(Statistic.SpecialDefense);
|
||||||
|
|
||||||
|
private T? _speed;
|
||||||
public T Speed => GetStatistic(Statistic.Speed);
|
public T Speed => GetStatistic(Statistic.Speed);
|
||||||
|
|
||||||
|
|
||||||
protected override CacheData CreateCache()
|
|
||||||
{
|
|
||||||
return new CacheData();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
if (typeof(T) == typeof(byte)) Interface.static_statistic_set_u8_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(ushort)) Interface.static_statistic_set_u16_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(uint)) Interface.static_statistic_set_u32_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(sbyte)) Interface.static_statistic_set_i8_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(short)) Interface.static_statistic_set_i16_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(int)) Interface.static_statistic_set_i32_drop(Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
~StaticStatisticSet()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,6 +7,6 @@ namespace PkmnLibSharp.StaticData
|
||||||
Defense = 2,
|
Defense = 2,
|
||||||
SpecialAttack = 3,
|
SpecialAttack = 3,
|
||||||
SpecialDefense = 4,
|
SpecialDefense = 4,
|
||||||
Speed = 5
|
Speed = 5,
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,42 +1,32 @@
|
||||||
using System;
|
using System;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
using PkmnLibSharp.Utils;
|
using PkmnLibSharp.Utils;
|
||||||
using Interface = PkmnLibSharp.FFI.StaticData.StatisticSet;
|
using Interface = PkmnLibSharp.FFI.StaticData.StatisticSet;
|
||||||
|
|
||||||
namespace PkmnLibSharp.StaticData
|
namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
public class StatisticSet<T> : ExternPointer<object> where T : struct, IConvertible
|
public class StatisticSet<T> : HandleType where T : struct, IConvertible
|
||||||
{
|
{
|
||||||
internal StatisticSet(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
protected StatisticSet(FFIHandle handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public StatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
public static StatisticSet<T> Create(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
|
||||||
{
|
{
|
||||||
var p = typeof(T) switch
|
var handle = typeof(T) switch
|
||||||
{
|
{
|
||||||
{ } t when t == typeof(byte) => Interface.statistic_set_u8_new(Convert.ToByte(hp),
|
{ } t when t == typeof(byte) => Interface.statistic_set_u8_new(Convert.ToByte(hp),
|
||||||
Convert.ToByte(attack), Convert.ToByte(defense), Convert.ToByte(specialAttack),
|
Convert.ToByte(attack), Convert.ToByte(defense), Convert.ToByte(specialAttack),
|
||||||
Convert.ToByte(specialDefense), Convert.ToByte(speed)),
|
Convert.ToByte(specialDefense), Convert.ToByte(speed)),
|
||||||
{ } t when t == typeof(ushort) => Interface.statistic_set_u16_new(Convert.ToUInt16(hp),
|
|
||||||
Convert.ToUInt16(attack), Convert.ToUInt16(defense), Convert.ToUInt16(specialAttack),
|
|
||||||
Convert.ToUInt16(specialDefense), Convert.ToUInt16(speed)),
|
|
||||||
{ } t when t == typeof(uint) => Interface.statistic_set_u32_new(Convert.ToUInt32(hp),
|
{ } t when t == typeof(uint) => Interface.statistic_set_u32_new(Convert.ToUInt32(hp),
|
||||||
Convert.ToUInt32(attack), Convert.ToUInt32(defense), Convert.ToUInt32(specialAttack),
|
Convert.ToUInt32(attack), Convert.ToUInt32(defense), Convert.ToUInt32(specialAttack),
|
||||||
Convert.ToUInt32(specialDefense), Convert.ToUInt32(speed)),
|
Convert.ToUInt32(specialDefense), Convert.ToUInt32(speed)),
|
||||||
{ } t when t == typeof(sbyte) => Interface.statistic_set_i8_new(Convert.ToSByte(hp),
|
{ } t when t == typeof(sbyte) => Interface.statistic_set_i8_new(Convert.ToSByte(hp),
|
||||||
Convert.ToSByte(attack), Convert.ToSByte(defense), Convert.ToSByte(specialAttack),
|
Convert.ToSByte(attack), Convert.ToSByte(defense), Convert.ToSByte(specialAttack),
|
||||||
Convert.ToSByte(specialDefense), Convert.ToSByte(speed)),
|
Convert.ToSByte(specialDefense), Convert.ToSByte(speed)),
|
||||||
{ } t when t == typeof(short) => Interface.statistic_set_i16_new(Convert.ToInt16(hp),
|
|
||||||
Convert.ToInt16(attack), Convert.ToInt16(defense), Convert.ToInt16(specialAttack),
|
|
||||||
Convert.ToInt16(specialDefense), Convert.ToInt16(speed)),
|
|
||||||
{ } t when t == typeof(int) => Interface.statistic_set_i32_new(Convert.ToInt32(hp),
|
|
||||||
Convert.ToInt32(attack), Convert.ToInt32(defense), Convert.ToInt32(specialAttack),
|
|
||||||
Convert.ToInt32(specialDefense), Convert.ToInt32(speed)),
|
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
};
|
};
|
||||||
InitializePointer(p, true);
|
return Resolver.Instance.ResolveStatisticSet<T>(handle.Resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
|
@ -44,12 +34,9 @@ namespace PkmnLibSharp.StaticData
|
||||||
{
|
{
|
||||||
object p = typeof(T) switch
|
object p = typeof(T) switch
|
||||||
{
|
{
|
||||||
{ } t when t == typeof(byte) => Interface.statistic_set_u8_get_stat(Ptr, statistic),
|
{ } t when t == typeof(byte) => Interface.statistic_set_u8_get_stat(Handle, statistic),
|
||||||
{ } t when t == typeof(ushort) => Interface.statistic_set_u16_get_stat(Ptr, statistic),
|
{ } t when t == typeof(uint) => Interface.statistic_set_u32_get_stat(Handle, statistic),
|
||||||
{ } t when t == typeof(uint) => Interface.statistic_set_u32_get_stat(Ptr, statistic),
|
{ } t when t == typeof(sbyte) => Interface.statistic_set_i8_get_stat(Handle, statistic),
|
||||||
{ } t when t == typeof(sbyte) => Interface.statistic_set_i8_get_stat(Ptr, statistic),
|
|
||||||
{ } t when t == typeof(short) => Interface.statistic_set_i16_get_stat(Ptr, statistic),
|
|
||||||
{ } t when t == typeof(int) => Interface.statistic_set_i32_get_stat(Ptr, statistic),
|
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
};
|
};
|
||||||
return (T)p;
|
return (T)p;
|
||||||
|
@ -58,17 +45,12 @@ namespace PkmnLibSharp.StaticData
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void SetStatistic(Statistic statistic, T value)
|
public void SetStatistic(Statistic statistic, T value)
|
||||||
{
|
{
|
||||||
if (typeof(T) == typeof(byte)) Interface.statistic_set_u8_set_stat(Ptr, statistic, Convert.ToByte(value));
|
if (typeof(T) == typeof(byte)) Interface.statistic_set_u8_set_stat(Handle, statistic, Convert.ToByte(value));
|
||||||
else if (typeof(T) == typeof(ushort))
|
|
||||||
Interface.statistic_set_u16_set_stat(Ptr, statistic, Convert.ToUInt16(value));
|
|
||||||
else if (typeof(T) == typeof(uint))
|
else if (typeof(T) == typeof(uint))
|
||||||
Interface.statistic_set_u32_set_stat(Ptr, statistic, Convert.ToUInt32(value));
|
Interface.statistic_set_u32_set_stat(Handle, statistic, Convert.ToUInt32(value));
|
||||||
else if (typeof(T) == typeof(sbyte))
|
else if (typeof(T) == typeof(sbyte))
|
||||||
Interface.statistic_set_i8_set_stat(Ptr, statistic, Convert.ToSByte(value));
|
Interface.statistic_set_i8_set_stat(Handle, statistic, Convert.ToSByte(value));
|
||||||
else if (typeof(T) == typeof(short))
|
else throw new ArgumentOutOfRangeException();
|
||||||
Interface.statistic_set_i16_set_stat(Ptr, statistic, Convert.ToInt16(value));
|
|
||||||
else if (typeof(T) == typeof(int))
|
|
||||||
Interface.statistic_set_i32_set_stat(Ptr, statistic, Convert.ToInt32(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T HP
|
public T HP
|
||||||
|
@ -106,23 +88,5 @@ namespace PkmnLibSharp.StaticData
|
||||||
get => GetStatistic(Statistic.Speed);
|
get => GetStatistic(Statistic.Speed);
|
||||||
set => SetStatistic(Statistic.Speed, value);
|
set => SetStatistic(Statistic.Speed, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override object CreateCache() => new();
|
|
||||||
|
|
||||||
protected override void Destructor()
|
|
||||||
{
|
|
||||||
if (typeof(T) == typeof(byte)) Interface.statistic_set_u8_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(ushort)) Interface.statistic_set_u16_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(uint)) Interface.statistic_set_u32_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(sbyte)) Interface.statistic_set_i8_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(short)) Interface.statistic_set_i16_drop(Ptr);
|
|
||||||
else if (typeof(T) == typeof(int)) Interface.statistic_set_i32_drop(Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
~StatisticSet()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,70 +0,0 @@
|
||||||
using System;
|
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
|
|
||||||
namespace PkmnLibSharp.Utils
|
|
||||||
{
|
|
||||||
public abstract class BasePointer<TCache> : IDisposable
|
|
||||||
where TCache : class
|
|
||||||
{
|
|
||||||
private IntPtr _ptr;
|
|
||||||
private ulong _identifier;
|
|
||||||
private TCache? _cache;
|
|
||||||
|
|
||||||
protected BasePointer()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected BasePointer(IntPtr ptr, ulong identifier = 0)
|
|
||||||
{
|
|
||||||
_ptr = ptr;
|
|
||||||
_identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected BasePointer(IdentifiablePointer ptr)
|
|
||||||
{
|
|
||||||
_ptr = ptr.Ptr;
|
|
||||||
_identifier = ptr.Identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal void InitializePointer(IntPtr ptr, ulong identifier = 0)
|
|
||||||
{
|
|
||||||
_ptr = ptr;
|
|
||||||
_identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal void InitializePointer(IdentifiablePointer ptr)
|
|
||||||
{
|
|
||||||
_ptr = ptr.Ptr;
|
|
||||||
_identifier = ptr.Identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal ulong Identifier => _identifier;
|
|
||||||
|
|
||||||
|
|
||||||
internal virtual IntPtr Ptr => _ptr;
|
|
||||||
|
|
||||||
protected abstract TCache CreateCache();
|
|
||||||
|
|
||||||
internal TCache Cache
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_cache == null && _identifier != 0)
|
|
||||||
{
|
|
||||||
_cache = CacheHandler.GetCache<TCache>(_identifier, CreateCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _cache!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected bool HasCache => _cache != null;
|
|
||||||
|
|
||||||
protected abstract void Destructor();
|
|
||||||
public virtual void Dispose()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
|
|
||||||
namespace PkmnLibSharp.Utils
|
|
||||||
{
|
|
||||||
internal static class CacheHandler
|
|
||||||
{
|
|
||||||
private static readonly ConcurrentDictionary<ulong, object> Caches = new();
|
|
||||||
|
|
||||||
internal static T GetCache<T>(ulong id, Func<object> ctor)
|
|
||||||
{
|
|
||||||
if (!Caches.TryGetValue(id, out var cache))
|
|
||||||
{
|
|
||||||
cache = ctor();
|
|
||||||
Caches.TryAdd(id, cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cache.GetType() != typeof(T))
|
|
||||||
{
|
|
||||||
throw new InvalidCastException(
|
|
||||||
$"Can't cast from cache data `{cache.GetType().FullName}` to cache data `{typeof(T).FullName}`");
|
|
||||||
}
|
|
||||||
return (T)cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void RemoveCache(ulong id)
|
|
||||||
{
|
|
||||||
Caches.TryRemove(id, out _);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,58 +5,6 @@ using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace PkmnLibSharp.Utils
|
namespace PkmnLibSharp.Utils
|
||||||
{
|
{
|
||||||
public sealed class DisposableCachedExternArray<T> : IReadOnlyList<T>, IDisposable
|
|
||||||
where T: class, IDisposable
|
|
||||||
{
|
|
||||||
private readonly T?[] _array;
|
|
||||||
private readonly Func<ulong, T> _getItem;
|
|
||||||
|
|
||||||
public DisposableCachedExternArray(ulong size, Func<ulong, T> getItem)
|
|
||||||
{
|
|
||||||
_array = new T?[(int)size];
|
|
||||||
_getItem = getItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerator<T> GetEnumerator()
|
|
||||||
{
|
|
||||||
for (var i = 0; i < Count; i++)
|
|
||||||
{
|
|
||||||
yield return this[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
return GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Count => _array.Length;
|
|
||||||
|
|
||||||
public T this[int index]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (index >= _array.Length)
|
|
||||||
throw new ArgumentOutOfRangeException(
|
|
||||||
$"Index {index} was outside of the bounds of the external array with length {Count}");
|
|
||||||
return _array[index] ??= _getItem((ulong)index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal T? GetCachedValue(int i)
|
|
||||||
{
|
|
||||||
return _array[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
foreach (var item in _array)
|
|
||||||
{
|
|
||||||
item?.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class CachedExternArray<T> : IReadOnlyList<T>
|
public sealed class CachedExternArray<T> : IReadOnlyList<T>
|
||||||
where T: class
|
where T: class
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,133 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using PkmnLibSharp.FFI;
|
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("PkmnLibRSharp")]
|
|
||||||
namespace PkmnLibSharp.Utils
|
|
||||||
{
|
|
||||||
public abstract class ExternPointer<TCache> : BasePointer<TCache>
|
|
||||||
where TCache : class
|
|
||||||
{
|
|
||||||
private bool _isOwner;
|
|
||||||
private bool _isInvalidated;
|
|
||||||
private bool _isDisposed;
|
|
||||||
|
|
||||||
protected ExternPointer()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ExternPointer(IntPtr ptr, bool isOwner)
|
|
||||||
{
|
|
||||||
InitializePointer(ptr, isOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ExternPointer(IdentifiablePointer ptr, bool isOwner) : base(ptr)
|
|
||||||
{
|
|
||||||
_isOwner = isOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void InitializePointer(IntPtr ptr, bool isOwner)
|
|
||||||
{
|
|
||||||
InitializePointer(ptr);
|
|
||||||
_isOwner = isOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void InitializePointer(IdentifiablePointer ptr, bool isOwner)
|
|
||||||
{
|
|
||||||
InitializePointer(ptr);
|
|
||||||
_isOwner = isOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal override IntPtr Ptr
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_isInvalidated)
|
|
||||||
{
|
|
||||||
throw new Exception("Pointer was used after invalidate");
|
|
||||||
}
|
|
||||||
return base.Ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IntPtr TakeOwnership()
|
|
||||||
{
|
|
||||||
if (!_isOwner)
|
|
||||||
{
|
|
||||||
throw new Exception("Tried to take ownership of a non-owned object");
|
|
||||||
}
|
|
||||||
_isOwner = false;
|
|
||||||
return Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal IntPtr TakeOwnershipAndInvalidate()
|
|
||||||
{
|
|
||||||
var ptr = TakeOwnership();
|
|
||||||
Invalidate();
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void Invalidate()
|
|
||||||
{
|
|
||||||
_isInvalidated = true;
|
|
||||||
CacheHandler.RemoveCache(Identifier);
|
|
||||||
InvalidateChildren();
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void InvalidateChildren(){}
|
|
||||||
|
|
||||||
public override void Dispose()
|
|
||||||
{
|
|
||||||
if (_isDisposed)
|
|
||||||
return;
|
|
||||||
if (_isOwner)
|
|
||||||
{
|
|
||||||
InvalidateChildren();
|
|
||||||
if (!_isInvalidated)
|
|
||||||
Destructor();
|
|
||||||
_isOwner = false;
|
|
||||||
CacheHandler.RemoveCache(Identifier);
|
|
||||||
}
|
|
||||||
_isDisposed = true;
|
|
||||||
_isInvalidated = true;
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (obj is ExternPointer<TCache> other)
|
|
||||||
{
|
|
||||||
return Identifier == other.Identifier;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected bool Equals(ExternPointer<TCache> other)
|
|
||||||
{
|
|
||||||
if (Identifier != 0)
|
|
||||||
{
|
|
||||||
return Identifier == other.Identifier;
|
|
||||||
}
|
|
||||||
return Ptr == other.Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
if (Identifier != 0)
|
|
||||||
return (int)Identifier;
|
|
||||||
return (int)Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator ==(ExternPointer<TCache>? left, ExternPointer<TCache>? right)
|
|
||||||
{
|
|
||||||
return Equals(left, right);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator !=(ExternPointer<TCache>? left, ExternPointer<TCache>? right)
|
|
||||||
{
|
|
||||||
return !Equals(left, right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using PkmnLibSharp.FFI;
|
||||||
|
|
||||||
|
namespace PkmnLibSharp.Utils
|
||||||
|
{
|
||||||
|
internal static class FFIHandleHandler
|
||||||
|
{
|
||||||
|
private static Dictionary<ulong, WeakReference> _handleReferences = new();
|
||||||
|
|
||||||
|
internal static void ReleaseHandle(ulong handle)
|
||||||
|
{
|
||||||
|
ffi_release_handle(handle);
|
||||||
|
_handleReferences.Remove(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static FFIHandle.FFIHandleReference GetHandleReference(ulong handle)
|
||||||
|
{
|
||||||
|
if (_handleReferences.TryGetValue(handle, out var weakReference))
|
||||||
|
{
|
||||||
|
if (weakReference.IsAlive)
|
||||||
|
return (FFIHandle.FFIHandleReference)weakReference.Target;
|
||||||
|
}
|
||||||
|
var reference = new FFIHandle.FFIHandleReference(handle);
|
||||||
|
_handleReferences[handle] = new WeakReference(reference);
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
private static extern void ffi_release_handle(ulong handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal struct FFIHandleValue
|
||||||
|
{
|
||||||
|
public static implicit operator FFIHandleValue(FFIHandle handle)
|
||||||
|
{
|
||||||
|
return new FFIHandleValue(handle.Handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FFIHandleValue()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private FFIHandleValue(ulong handle)
|
||||||
|
{
|
||||||
|
Handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong Handle { get; }
|
||||||
|
public bool IsNull => Handle == 0;
|
||||||
|
|
||||||
|
public FFIHandle Resolve()
|
||||||
|
{
|
||||||
|
if (Handle == 0)
|
||||||
|
throw new NullReferenceException("Handle is null");
|
||||||
|
return new FFIHandle(Handle, FFIHandleHandler.GetHandleReference(Handle));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct FFIHandle
|
||||||
|
{
|
||||||
|
internal FFIHandle(ulong handle, FFIHandleReference handleReference)
|
||||||
|
{
|
||||||
|
Handle = handle;
|
||||||
|
_handleReference = handleReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong Handle { get; }
|
||||||
|
public static FFIHandle Zero => new(0, null!);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is only here for reference counting purposes. As soon as every handle is released, the FFIHandleReference
|
||||||
|
/// will be garbage collected, and the finalizer will be called, which will release the handle, signifying to
|
||||||
|
/// PkmnLib that we no longer need the handle.
|
||||||
|
/// </summary>
|
||||||
|
// ReSharper disable once NotAccessedField.Local
|
||||||
|
private readonly FFIHandleReference _handleReference;
|
||||||
|
|
||||||
|
internal class FFIHandleReference
|
||||||
|
{
|
||||||
|
private readonly ulong _handle;
|
||||||
|
|
||||||
|
public FFIHandleReference(ulong handle)
|
||||||
|
{
|
||||||
|
_handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
~FFIHandleReference()
|
||||||
|
{
|
||||||
|
FFIHandleHandler.ReleaseHandle(this._handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace PkmnLibSharp.Utils
|
||||||
|
{
|
||||||
|
public abstract class HandleType
|
||||||
|
{
|
||||||
|
protected internal HandleType(FFIHandle handle)
|
||||||
|
{
|
||||||
|
Handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected internal FFIHandle Handle { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,39 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace PkmnLibSharp.Utils
|
|
||||||
{
|
|
||||||
public struct Optional<T> : IDisposable
|
|
||||||
where T: IDisposable
|
|
||||||
{
|
|
||||||
public T? Value;
|
|
||||||
public bool HasValue;
|
|
||||||
|
|
||||||
private Optional(T? value, bool hasValue)
|
|
||||||
{
|
|
||||||
Value = value;
|
|
||||||
HasValue = hasValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator Optional<T>(T value)
|
|
||||||
{
|
|
||||||
return new Optional<T>(value, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator T(Optional<T> value)
|
|
||||||
{
|
|
||||||
return value.Value!;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<T> None()
|
|
||||||
{
|
|
||||||
return new Optional<T>(default, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
#pragma warning disable IDISP007
|
|
||||||
Value?.Dispose();
|
|
||||||
#pragma warning restore IDISP007
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using PkmnLibSharp.DynamicData;
|
||||||
|
using PkmnLibSharp.DynamicData.Libraries;
|
||||||
|
using PkmnLibSharp.FFI;
|
||||||
|
using PkmnLibSharp.StaticData;
|
||||||
|
using PkmnLibSharp.StaticData.Libraries;
|
||||||
|
|
||||||
|
namespace PkmnLibSharp.Utils
|
||||||
|
{
|
||||||
|
public class Resolver
|
||||||
|
{
|
||||||
|
public static Resolver Instance { get; set; } = new();
|
||||||
|
private static readonly Dictionary<FFIHandle, object> Instances = new();
|
||||||
|
|
||||||
|
protected static T GetOrCreateInstance<T>(FFIHandle handle)
|
||||||
|
{
|
||||||
|
if (!Instances.TryGetValue(handle, out var instance))
|
||||||
|
{
|
||||||
|
instance = typeof(T)
|
||||||
|
.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null,
|
||||||
|
new[] { typeof(FFIHandle) }, null)
|
||||||
|
?.Invoke(new object[] { handle });
|
||||||
|
Instances.Add(handle, instance!);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (T)instance!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual EffectParameter ResolveEffectParameter(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<EffectParameter>(handle);
|
||||||
|
|
||||||
|
public virtual Ability ResolveAbility(FFIHandle handle) => GetOrCreateInstance<Ability>(handle);
|
||||||
|
public virtual Form ResolveForm(FFIHandle handle) => GetOrCreateInstance<Form>(handle);
|
||||||
|
|
||||||
|
public virtual StaticStatisticSet<T> ResolveStaticStatisticSet<T>(FFIHandle handle)
|
||||||
|
where T : struct, IConvertible =>
|
||||||
|
GetOrCreateInstance<StaticStatisticSet<T>>(handle);
|
||||||
|
|
||||||
|
public virtual StatisticSet<T> ResolveStatisticSet<T>(FFIHandle handle) where T : struct, IConvertible =>
|
||||||
|
GetOrCreateInstance<StatisticSet<T>>(handle);
|
||||||
|
|
||||||
|
public virtual LearnableMoves ResolveLearnableMoves(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<LearnableMoves>(handle);
|
||||||
|
|
||||||
|
public virtual Item ResolveItem(FFIHandle handle) => GetOrCreateInstance<Item>(handle);
|
||||||
|
|
||||||
|
public virtual SecondaryEffect ResolveSecondaryEffect(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<SecondaryEffect>(handle);
|
||||||
|
|
||||||
|
public virtual MoveData ResolveMoveData(FFIHandle handle) => GetOrCreateInstance<MoveData>(handle);
|
||||||
|
public virtual Nature ResolveNature(FFIHandle handle) => GetOrCreateInstance<Nature>(handle);
|
||||||
|
|
||||||
|
public virtual Species ResolveSpecies(FFIHandle handle) => GetOrCreateInstance<Species>(handle);
|
||||||
|
|
||||||
|
public virtual AbilityLibrary ResolveAbilityLibrary(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<AbilityLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual ItemLibrary ResolveItemLibrary(FFIHandle handle) => GetOrCreateInstance<ItemLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual LookupGrowthRate ResolveLookupGrowthRate(FFIHandle ptr) =>
|
||||||
|
GetOrCreateInstance<LookupGrowthRate>(ptr);
|
||||||
|
|
||||||
|
public virtual GrowthRateLibrary ResolveGrowthRateLibrary(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<GrowthRateLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual MoveLibrary ResolveMoveLibrary(FFIHandle handle) => GetOrCreateInstance<MoveLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual NatureLibrary ResolveNatureLibrary(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<NatureLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual SpeciesLibrary ResolveSpeciesLibrary(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<SpeciesLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual LibrarySettings ResolveLibrarySettings(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<LibrarySettings>(handle);
|
||||||
|
|
||||||
|
public virtual TypeLibrary ResolveTypeLibrary(FFIHandle handle) => GetOrCreateInstance<TypeLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual StaticData.Libraries.StaticData ResolveStaticData(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<StaticData.Libraries.StaticData>(handle);
|
||||||
|
|
||||||
|
public virtual LearnedMove ResolveLearnedMove(FFIHandle resolve) => GetOrCreateInstance<LearnedMove>(resolve);
|
||||||
|
|
||||||
|
public virtual Gen7BattleStatCalculator ResolveGen7BattleStatCalculator(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<Gen7BattleStatCalculator>(handle);
|
||||||
|
|
||||||
|
public virtual Gen7DamageLibrary ResolveGen7DamageLibrary(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<Gen7DamageLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual Gen7MiscLibrary ResolveGen7MiscLibrary(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<Gen7MiscLibrary>(handle);
|
||||||
|
|
||||||
|
public virtual EmptyScriptResolver ResolveEmptyScriptResolver(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<EmptyScriptResolver>(handle);
|
||||||
|
|
||||||
|
#if WASM
|
||||||
|
public virtual WasmScriptResolver ResolveWasmScriptResolver(FFIHandle handle) =>
|
||||||
|
GetOrCreateInstance<WasmScriptResolver>(handle);
|
||||||
|
#endif
|
||||||
|
public DynamicLibrary ResolveDynamicLibrary(FFIHandle resolve) => GetOrCreateInstance<DynamicLibrary>(resolve);
|
||||||
|
|
||||||
|
public Pokemon ResolvePokemon(FFIHandle resolve) => GetOrCreateInstance<Pokemon>(resolve);
|
||||||
|
}
|
||||||
|
}
|
BIN
PkmnLibRSharp/libpkmn_lib.so (Stored with Git LFS)
BIN
PkmnLibRSharp/libpkmn_lib.so (Stored with Git LFS)
Binary file not shown.
|
@ -10,27 +10,27 @@ namespace PkmnLibRSharpTests.DynamicData
|
||||||
[Test]
|
[Test]
|
||||||
public void LearnedMoveMoveData()
|
public void LearnedMoveMoveData()
|
||||||
{
|
{
|
||||||
using var moveData = new MoveData("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
var moveData = MoveData.Create("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
||||||
MoveTarget.All, 0, null, Array.Empty<string>());
|
MoveTarget.All, 0, null, Array.Empty<string>());
|
||||||
using var learnedMove = new LearnedMove(moveData, MoveLearnMethod.Level);
|
var learnedMove = LearnedMove.Create(moveData, MoveLearnMethod.Level);
|
||||||
Assert.AreEqual("foo", learnedMove.MoveData.Name);
|
Assert.AreEqual("foo", learnedMove.MoveData.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void LearnedMoveMaxPP()
|
public void LearnedMoveMaxPP()
|
||||||
{
|
{
|
||||||
using var moveData = new MoveData("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
var moveData = MoveData.Create("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
||||||
MoveTarget.All, 0, null, Array.Empty<string>());
|
MoveTarget.All, 0, null, Array.Empty<string>());
|
||||||
using var learnedMove = new LearnedMove(moveData, MoveLearnMethod.Level);
|
var learnedMove = LearnedMove.Create(moveData, MoveLearnMethod.Level);
|
||||||
Assert.AreEqual(30, learnedMove.MaxPP);
|
Assert.AreEqual(30, learnedMove.MaxPP);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void LearnedMoveRemainingPP()
|
public void LearnedMoveRemainingPP()
|
||||||
{
|
{
|
||||||
using var moveData = new MoveData("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
var moveData = MoveData.Create("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
||||||
MoveTarget.All, 0, null, Array.Empty<string>());
|
MoveTarget.All, 0, null, Array.Empty<string>());
|
||||||
using var learnedMove = new LearnedMove(moveData, MoveLearnMethod.Level);
|
var learnedMove = LearnedMove.Create(moveData, MoveLearnMethod.Level);
|
||||||
Assert.IsTrue(learnedMove.TryUse(1));
|
Assert.IsTrue(learnedMove.TryUse(1));
|
||||||
Assert.AreEqual(29, learnedMove.RemainingPP);
|
Assert.AreEqual(29, learnedMove.RemainingPP);
|
||||||
}
|
}
|
||||||
|
@ -38,18 +38,18 @@ namespace PkmnLibRSharpTests.DynamicData
|
||||||
[Test]
|
[Test]
|
||||||
public void LearnedMoveLearnMethod()
|
public void LearnedMoveLearnMethod()
|
||||||
{
|
{
|
||||||
using var moveData = new MoveData("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
var moveData = MoveData.Create("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
||||||
MoveTarget.All, 0, null, Array.Empty<string>());
|
MoveTarget.All, 0, null, Array.Empty<string>());
|
||||||
using var learnedMove = new LearnedMove(moveData, MoveLearnMethod.Level);
|
var learnedMove = LearnedMove.Create(moveData, MoveLearnMethod.Level);
|
||||||
Assert.AreEqual(MoveLearnMethod.Level, learnedMove.LearnMethod);
|
Assert.AreEqual(MoveLearnMethod.Level, learnedMove.LearnMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void LearnedMoveRestoreAllUses()
|
public void LearnedMoveRestoreAllUses()
|
||||||
{
|
{
|
||||||
using var moveData = new MoveData("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
var moveData = MoveData.Create("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
||||||
MoveTarget.All, 0, null, Array.Empty<string>());
|
MoveTarget.All, 0, null, Array.Empty<string>());
|
||||||
using var learnedMove = new LearnedMove(moveData, MoveLearnMethod.Level);
|
var learnedMove = LearnedMove.Create(moveData, MoveLearnMethod.Level);
|
||||||
Assert.IsTrue(learnedMove.TryUse(15));
|
Assert.IsTrue(learnedMove.TryUse(15));
|
||||||
Assert.AreEqual(15, learnedMove.RemainingPP);
|
Assert.AreEqual(15, learnedMove.RemainingPP);
|
||||||
learnedMove.RestoreAllUses();
|
learnedMove.RestoreAllUses();
|
||||||
|
@ -59,9 +59,9 @@ namespace PkmnLibRSharpTests.DynamicData
|
||||||
[Test]
|
[Test]
|
||||||
public void LearnedMoveRestoreUses()
|
public void LearnedMoveRestoreUses()
|
||||||
{
|
{
|
||||||
using var moveData = new MoveData("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
var moveData = MoveData.Create("foo", new TypeIdentifier(0), MoveCategory.Physical, 100, 20, 30,
|
||||||
MoveTarget.All, 0, null, Array.Empty<string>());
|
MoveTarget.All, 0, null, Array.Empty<string>());
|
||||||
using var learnedMove = new LearnedMove(moveData, MoveLearnMethod.Level);
|
var learnedMove = LearnedMove.Create(moveData, MoveLearnMethod.Level);
|
||||||
Assert.IsTrue(learnedMove.TryUse(15));
|
Assert.IsTrue(learnedMove.TryUse(15));
|
||||||
Assert.AreEqual(15, learnedMove.RemainingPP);
|
Assert.AreEqual(15, learnedMove.RemainingPP);
|
||||||
learnedMove.RestoreUses(5);
|
learnedMove.RestoreUses(5);
|
||||||
|
|
|
@ -12,24 +12,24 @@ namespace PkmnLibRSharpTests.DynamicData
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetLibrary()
|
public void Pokemon_GetLibrary()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
||||||
Assert.AreEqual(library, pokemon.Library);
|
Assert.AreEqual(library, pokemon.Library);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetSpecies()
|
public void Pokemon_GetSpecies()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
||||||
Assert.AreEqual(library.StaticData.SpeciesLibrary["testSpecies"], pokemon.Species);
|
Assert.AreEqual(library.StaticData.SpeciesLibrary["testSpecies"], pokemon.Species);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetForm()
|
public void Pokemon_GetForm()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
||||||
Assert.AreEqual(library.StaticData.SpeciesLibrary["testSpecies"].DefaultForm, pokemon.Form);
|
Assert.AreEqual(library.StaticData.SpeciesLibrary["testSpecies"].DefaultForm, pokemon.Form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,32 +37,32 @@ namespace PkmnLibRSharpTests.DynamicData
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetDisplaySpecies()
|
public void Pokemon_GetDisplaySpecies()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
||||||
Assert.AreEqual(library.StaticData.SpeciesLibrary["testSpecies"], pokemon.Species);
|
Assert.AreEqual(library.StaticData.SpeciesLibrary["testSpecies"], pokemon.Species);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetDisplayForm()
|
public void Pokemon_GetDisplayForm()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
||||||
Assert.AreEqual(library.StaticData.SpeciesLibrary["testSpecies"].DefaultForm, pokemon.Form);
|
Assert.AreEqual(library.StaticData.SpeciesLibrary["testSpecies"].DefaultForm, pokemon.Form);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetLevel()
|
public void Pokemon_GetLevel()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
||||||
Assert.AreEqual(100, pokemon.Level);
|
Assert.AreEqual(100, pokemon.Level);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetExperience()
|
public void Pokemon_GetExperience()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).Build();
|
||||||
Assert.AreEqual(library.StaticData.GrowthRateLibrary.CalculateExperience("testGrowthrate", 100),
|
Assert.AreEqual(library.StaticData.GrowthRateLibrary.CalculateExperience("testGrowthrate", 100),
|
||||||
pokemon.Experience);
|
pokemon.Experience);
|
||||||
}
|
}
|
||||||
|
@ -70,60 +70,59 @@ namespace PkmnLibRSharpTests.DynamicData
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetUniqueIdentifier()
|
public void Pokemon_GetUniqueIdentifier()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).WithIdentifier(1000).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).WithIdentifier(1000).Build();
|
||||||
Assert.AreEqual(1000, pokemon.UniqueIdentifier);
|
Assert.AreEqual(1000, pokemon.UniqueIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetGender()
|
public void Pokemon_GetGender()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).WithGender(Gender.Male).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).WithGender(Gender.Male).Build();
|
||||||
Assert.AreEqual(Gender.Male, pokemon.Gender);
|
Assert.AreEqual(Gender.Male, pokemon.Gender);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Pokemon_GetColoring()
|
public void Pokemon_GetColoring()
|
||||||
{
|
{
|
||||||
using var library = GetLibrary();
|
var library = GetLibrary();
|
||||||
using var pokemon = new PokemonBuilder(library, "testSpecies", 100).ForceShiny(true).Build();
|
var pokemon = new PokemonBuilder(library, "testSpecies", 100).ForceShiny(true).Build();
|
||||||
Assert.AreEqual(1, pokemon.Coloring);
|
Assert.AreEqual(1, pokemon.Coloring);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DynamicLibrary GetLibrary()
|
private static DynamicLibrary GetLibrary()
|
||||||
{
|
{
|
||||||
using var settings = new LibrarySettings(100, 4096);
|
var settings = LibrarySettings.Create(100, 4096);
|
||||||
using var speciesLibrary = new SpeciesLibrary(0);
|
var speciesLibrary = SpeciesLibrary.Create(0);
|
||||||
FillSpeciesLibrary(speciesLibrary);
|
FillSpeciesLibrary(speciesLibrary);
|
||||||
using var moves = new MoveLibrary(0);
|
var moves = MoveLibrary.Create(0);
|
||||||
using var items = new ItemLibrary(0);
|
var items = ItemLibrary.Create(0);
|
||||||
using var growthRates = new GrowthRateLibrary(0);
|
var growthRates = GrowthRateLibrary.Create(0);
|
||||||
using var gr = CommonGrowthRates.Erratic(100);
|
var gr = CommonGrowthRates.Erratic(100);
|
||||||
growthRates.AddGrowthRate("testGrowthrate", gr);
|
growthRates.AddGrowthRate("testGrowthrate", gr);
|
||||||
using var types = new TypeLibrary(0);
|
var types = TypeLibrary.Create(0);
|
||||||
using var natures = new NatureLibrary(0);
|
var natures = NatureLibrary.Create(0);
|
||||||
natures.LoadNature("testNature", Nature.NeutralNature());
|
natures.LoadNature("testNature", Nature.NeutralNature());
|
||||||
using var abilities = new AbilityLibrary(0);
|
var abilities = AbilityLibrary.Create(0);
|
||||||
using var library = new PkmnLibSharp.StaticData.Libraries.StaticData(settings, speciesLibrary, moves, items,
|
var library = PkmnLibSharp.StaticData.Libraries.StaticData.Create(settings, speciesLibrary, moves, items,
|
||||||
growthRates, types, natures, abilities);
|
growthRates, types, natures, abilities);
|
||||||
|
|
||||||
using var statCalc = new Gen7BattleStatCalculator();
|
var statCalc = Gen7BattleStatCalculator.Create();
|
||||||
using var damageLib = new Gen7DamageLibrary(false);
|
var damageLib = Gen7DamageLibrary.Create(false);
|
||||||
using var miscLib = new Gen7MiscLibrary();
|
var miscLib = Gen7MiscLibrary.Create();
|
||||||
using var scriptResolver = new WasmScriptResolver();
|
var scriptResolver = WasmScriptResolver.Create();
|
||||||
|
|
||||||
return new DynamicLibrary(library, statCalc, damageLib, miscLib, scriptResolver);
|
return DynamicLibrary.Create(library, statCalc, damageLib, miscLib, scriptResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FillSpeciesLibrary(SpeciesLibrary speciesLibrary)
|
private static void FillSpeciesLibrary(SpeciesLibrary speciesLibrary)
|
||||||
{
|
{
|
||||||
using var stats = new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0);
|
var stats = StaticStatisticSet<ushort>.Create(5, 10, 30, 20, 2, 0);
|
||||||
using var moves = new LearnableMoves();
|
var moves = LearnableMoves.Create();
|
||||||
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
var form = Form.Create("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
||||||
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
||||||
using var species =
|
var species = Species.Create(10, "testSpecies", 0.2f, "testGrowthrate", 120, form, Array.Empty<string>());
|
||||||
new Species(10, "testSpecies", 0.2f, "testGrowthrate", 120, form, Array.Empty<string>());
|
|
||||||
speciesLibrary.Add(species.Name, species);
|
speciesLibrary.Add(species.Name, species);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,22 +9,22 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void AbilityGetName([Values("foo", "bar", "", "zet", "xy")] string name)
|
public void AbilityGetName([Values("foo", "bar", "", "zet", "xy")] string name)
|
||||||
{
|
{
|
||||||
using var ability = new Ability(name, "", Array.Empty<EffectParameter>());
|
var ability = Ability.Create(name, "", Array.Empty<EffectParameter>());
|
||||||
Assert.AreEqual(name, ability.Name);
|
Assert.AreEqual(name, ability.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AbilityGetEffect([Values("foo", "bar", "", "zet", "xy")] string effect)
|
public void AbilityGetEffect([Values("foo", "bar", "", "zet", "xy")] string effect)
|
||||||
{
|
{
|
||||||
using var ability = new Ability("", effect, Array.Empty<EffectParameter>());
|
var ability = Ability.Create("", effect, Array.Empty<EffectParameter>());
|
||||||
Assert.AreEqual(effect, ability.Effect);
|
Assert.AreEqual(effect, ability.Effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AbilityGetParameters()
|
public void AbilityGetParameters()
|
||||||
{
|
{
|
||||||
using var ability = new Ability("", "",
|
var ability = Ability.Create("", "",
|
||||||
new EffectParameter[] { new(100), new(false), new("foobar"), new(true) });
|
new EffectParameter[] { 100, false, "foobar", true });
|
||||||
Assert.AreEqual(4, ability.Parameters.Count);
|
Assert.AreEqual(4, ability.Parameters.Count);
|
||||||
var p1 = ability.Parameters[0];
|
var p1 = ability.Parameters[0];
|
||||||
Assert.AreEqual(100, p1.Data);
|
Assert.AreEqual(100, p1.Data);
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void BoolParameter([Values(true, false)] bool value)
|
public void BoolParameter([Values(true, false)] bool value)
|
||||||
{
|
{
|
||||||
using var parameter = new EffectParameter(value);
|
var parameter = EffectParameter.FromBool(value);
|
||||||
Assert.AreEqual(EffectParameter.ParameterType.Bool, parameter.Type);
|
Assert.AreEqual(EffectParameter.ParameterType.Bool, parameter.Type);
|
||||||
Assert.AreEqual(value, parameter.Data);
|
Assert.AreEqual(value, parameter.Data);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void IntParameter([Random(long.MinValue, long.MaxValue, 10)] long value)
|
public void IntParameter([Random(long.MinValue, long.MaxValue, 10)] long value)
|
||||||
{
|
{
|
||||||
using var parameter = new EffectParameter(value);
|
var parameter = EffectParameter.FromLong(value);
|
||||||
Assert.AreEqual(EffectParameter.ParameterType.Int, parameter.Type);
|
Assert.AreEqual(EffectParameter.ParameterType.Int, parameter.Type);
|
||||||
Assert.AreEqual(value, parameter.Data);
|
Assert.AreEqual(value, parameter.Data);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void FloatParameter([Random(float.MinValue, float.MaxValue, 10)] float value)
|
public void FloatParameter([Random(float.MinValue, float.MaxValue, 10)] float value)
|
||||||
{
|
{
|
||||||
using var parameter = new EffectParameter(value);
|
var parameter = EffectParameter.FromFloat(value);
|
||||||
Assert.AreEqual(EffectParameter.ParameterType.Float, parameter.Type);
|
Assert.AreEqual(EffectParameter.ParameterType.Float, parameter.Type);
|
||||||
Assert.AreEqual(value, parameter.Data);
|
Assert.AreEqual(value, parameter.Data);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void StringParameter([Values("foo", "bar", "zet", "x", "")] string value)
|
public void StringParameter([Values("foo", "bar", "zet", "x", "")] string value)
|
||||||
{
|
{
|
||||||
using var parameter = new EffectParameter(value);
|
var parameter = EffectParameter.FromString(value);
|
||||||
Assert.AreEqual(EffectParameter.ParameterType.String, parameter.Type);
|
Assert.AreEqual(EffectParameter.ParameterType.String, parameter.Type);
|
||||||
Assert.AreEqual(value, parameter.Data);
|
Assert.AreEqual(value, parameter.Data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void BasicTests()
|
public void BasicTests()
|
||||||
{
|
{
|
||||||
using var stats = new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0);
|
var stats = StaticStatisticSet<ushort>.Create(5, 10, 30, 20, 2, 0);
|
||||||
using var moves = new LearnableMoves();
|
var moves = LearnableMoves.Create();
|
||||||
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
var form = Form.Create("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
||||||
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
||||||
Assert.AreEqual("foobar", form.Name);
|
Assert.AreEqual("foobar", form.Name);
|
||||||
Assert.AreEqual(0.2f, form.Height, 0.00001f);
|
Assert.AreEqual(0.2f, form.Height, 0.00001f);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using PkmnLibSharp.FFI;
|
||||||
using PkmnLibSharp.StaticData;
|
using PkmnLibSharp.StaticData;
|
||||||
|
|
||||||
namespace PkmnLibRSharpTests.StaticData
|
namespace PkmnLibRSharpTests.StaticData
|
||||||
|
@ -8,13 +9,13 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAndDropLookupGrowthRate()
|
public void CreateAndDropLookupGrowthRate()
|
||||||
{
|
{
|
||||||
using var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
var growthRate = LookupGrowthRate.Create(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void LookupGrowthRateCalculateLevel()
|
public void LookupGrowthRateCalculateLevel()
|
||||||
{
|
{
|
||||||
using var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
var growthRate = LookupGrowthRate.Create(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||||
Assert.AreEqual(1, growthRate.CalculateLevel(0));
|
Assert.AreEqual(1, growthRate.CalculateLevel(0));
|
||||||
Assert.AreEqual(2, growthRate.CalculateLevel(1));
|
Assert.AreEqual(2, growthRate.CalculateLevel(1));
|
||||||
Assert.AreEqual(2, growthRate.CalculateLevel(2));
|
Assert.AreEqual(2, growthRate.CalculateLevel(2));
|
||||||
|
@ -24,11 +25,15 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void LookupGrowthRateCalculateExperience()
|
public void LookupGrowthRateCalculateExperience()
|
||||||
{
|
{
|
||||||
using var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
var growthRate = LookupGrowthRate.Create(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||||
Assert.AreEqual(0, growthRate.CalculateExperience(1));
|
Assert.AreEqual(0, growthRate.CalculateExperience(1));
|
||||||
Assert.AreEqual(1, growthRate.CalculateExperience(2));
|
Assert.AreEqual(1, growthRate.CalculateExperience(2));
|
||||||
Assert.AreEqual(5, growthRate.CalculateExperience(3));
|
Assert.AreEqual(5, growthRate.CalculateExperience(3));
|
||||||
Assert.AreEqual(10, growthRate.CalculateExperience(4));
|
Assert.AreEqual(10, growthRate.CalculateExperience(4));
|
||||||
|
Assert.Throws<PkmnLibException>(() =>
|
||||||
|
{
|
||||||
|
growthRate.CalculateExperience(0);
|
||||||
|
}, "Level must be greater than 0, but was 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void BasicTests()
|
public void BasicTests()
|
||||||
{
|
{
|
||||||
using var item = new Item("foobar", ItemCategory.Mail, BattleItemCategory.StatusHealing, 500,
|
var item = Item.Create("foobar", ItemCategory.Mail, BattleItemCategory.StatusHealing, 500,
|
||||||
Array.Empty<string>());
|
Array.Empty<string>());
|
||||||
Assert.AreEqual("foobar", item.Name);
|
Assert.AreEqual("foobar", item.Name);
|
||||||
Assert.AreEqual(ItemCategory.Mail, item.Category);
|
Assert.AreEqual(ItemCategory.Mail, item.Category);
|
||||||
|
@ -20,7 +20,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void FlagTests()
|
public void FlagTests()
|
||||||
{
|
{
|
||||||
using var item = new Item("foobar", ItemCategory.Mail, BattleItemCategory.StatusHealing, 500,
|
var item = Item.Create("foobar", ItemCategory.Mail, BattleItemCategory.StatusHealing, 500,
|
||||||
new []{"foo", "zet"});
|
new []{"foo", "zet"});
|
||||||
Assert.That(item.HasFlag("foo"));
|
Assert.That(item.HasFlag("foo"));
|
||||||
Assert.That(item.HasFlag("zet"));
|
Assert.That(item.HasFlag("zet"));
|
||||||
|
|
|
@ -10,16 +10,16 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void Create()
|
public void Create()
|
||||||
{
|
{
|
||||||
using var lib = new AbilityLibrary(0);
|
var lib = AbilityLibrary.Create(0);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAndAdd()
|
public void CreateAndAdd()
|
||||||
{
|
{
|
||||||
using var lib = new AbilityLibrary(1);
|
var lib = AbilityLibrary.Create(0);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
using var ability = new Ability("testAbility", "effect", Array.Empty<EffectParameter>());
|
var ability = Ability.Create("testAbility", "effect", Array.Empty<EffectParameter>());
|
||||||
lib.Add("foobar", ability);
|
lib.Add("foobar", ability);
|
||||||
Assert.AreEqual(1, lib.Count);
|
Assert.AreEqual(1, lib.Count);
|
||||||
Assert.AreEqual("testAbility", lib["foobar"].Name);
|
Assert.AreEqual("testAbility", lib["foobar"].Name);
|
||||||
|
@ -28,11 +28,11 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAddIterate()
|
public void CreateAddIterate()
|
||||||
{
|
{
|
||||||
using var lib = new AbilityLibrary(10);
|
var lib = AbilityLibrary.Create(0);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
for (ushort i = 0; i < 10; i++)
|
for (ushort i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
using var item = new Ability(i.ToString(), "effect", Array.Empty<EffectParameter>());
|
var item = Ability.Create(i.ToString(), "effect", Array.Empty<EffectParameter>());
|
||||||
lib.Add(i + "_key", item);
|
lib.Add(i + "_key", item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[TestCase(100, 600_000)]
|
[TestCase(100, 600_000)]
|
||||||
public void ErraticExperience(byte level, int experience)
|
public void ErraticExperience(byte level, int experience)
|
||||||
{
|
{
|
||||||
using var growthRate = CommonGrowthRates.Erratic(100);
|
var growthRate = CommonGrowthRates.Erratic(100);
|
||||||
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[TestCase(100, 800_000)]
|
[TestCase(100, 800_000)]
|
||||||
public void FastExperience(byte level, int experience)
|
public void FastExperience(byte level, int experience)
|
||||||
{
|
{
|
||||||
using var growthRate = CommonGrowthRates.Fast(100);
|
var growthRate = CommonGrowthRates.Fast(100);
|
||||||
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[TestCase(100, 1_000_000)]
|
[TestCase(100, 1_000_000)]
|
||||||
public void MediumFastExperience(byte level, int experience)
|
public void MediumFastExperience(byte level, int experience)
|
||||||
{
|
{
|
||||||
using var growthRate = CommonGrowthRates.MediumFast(100);
|
var growthRate = CommonGrowthRates.MediumFast(100);
|
||||||
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[TestCase(100, 1_059_860)]
|
[TestCase(100, 1_059_860)]
|
||||||
public void MediumSlowExperience(byte level, int experience)
|
public void MediumSlowExperience(byte level, int experience)
|
||||||
{
|
{
|
||||||
using var growthRate = CommonGrowthRates.MediumSlow(100);
|
var growthRate = CommonGrowthRates.MediumSlow(100);
|
||||||
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[TestCase(100, 1_250_000)]
|
[TestCase(100, 1_250_000)]
|
||||||
public void SlowExperience(byte level, int experience)
|
public void SlowExperience(byte level, int experience)
|
||||||
{
|
{
|
||||||
using var growthRate = CommonGrowthRates.Slow(100);
|
var growthRate = CommonGrowthRates.Slow(100);
|
||||||
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[TestCase(100, 1_640_000)]
|
[TestCase(100, 1_640_000)]
|
||||||
public void FluctuatingExperience(byte level, int experience)
|
public void FluctuatingExperience(byte level, int experience)
|
||||||
{
|
{
|
||||||
using var growthRate = CommonGrowthRates.Fluctuating(100);
|
var growthRate = CommonGrowthRates.Fluctuating(100);
|
||||||
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
Assert.AreEqual(experience, growthRate.CalculateExperience(level));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,22 +9,22 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateGrowthRateLibrary()
|
public void CreateGrowthRateLibrary()
|
||||||
{
|
{
|
||||||
using var library = new GrowthRateLibrary(0);
|
var library = GrowthRateLibrary.Create(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AddGrowthRateToLibrary()
|
public void AddGrowthRateToLibrary()
|
||||||
{
|
{
|
||||||
using var library = new GrowthRateLibrary(0);
|
var library = GrowthRateLibrary.Create(0);
|
||||||
using var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
var growthRate = LookupGrowthRate.Create(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||||
library.AddGrowthRate("foobar", growthRate);
|
library.AddGrowthRate("foobar", growthRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CalculateLevel()
|
public void CalculateLevel()
|
||||||
{
|
{
|
||||||
using var library = new GrowthRateLibrary(0);
|
var library = GrowthRateLibrary.Create(0);
|
||||||
using var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
var growthRate = LookupGrowthRate.Create(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||||
library.AddGrowthRate("foobar", growthRate);
|
library.AddGrowthRate("foobar", growthRate);
|
||||||
var level = library.CalculateLevel("foobar", 20);
|
var level = library.CalculateLevel("foobar", 20);
|
||||||
Assert.AreEqual(5, level);
|
Assert.AreEqual(5, level);
|
||||||
|
@ -33,8 +33,8 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CalculateExperience()
|
public void CalculateExperience()
|
||||||
{
|
{
|
||||||
using var library = new GrowthRateLibrary(0);
|
var library = GrowthRateLibrary.Create(0);
|
||||||
using var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
var growthRate = LookupGrowthRate.Create(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
|
||||||
library.AddGrowthRate("foobar", growthRate);
|
library.AddGrowthRate("foobar", growthRate);
|
||||||
var experience = library.CalculateExperience("foobar", 5);
|
var experience = library.CalculateExperience("foobar", 5);
|
||||||
Assert.AreEqual(20, experience);
|
Assert.AreEqual(20, experience);
|
||||||
|
|
|
@ -10,16 +10,16 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void Create()
|
public void Create()
|
||||||
{
|
{
|
||||||
using var lib = new ItemLibrary(0);
|
var lib = ItemLibrary.Create(0);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAndAdd()
|
public void CreateAndAdd()
|
||||||
{
|
{
|
||||||
using var lib = new ItemLibrary(1);
|
var lib = ItemLibrary.Create(1);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
using var item = new Item("testItem", ItemCategory.Mail, BattleItemCategory.None, 100, Array.Empty<string>());
|
var item = Item.Create("testItem", ItemCategory.Mail, BattleItemCategory.None, 100, Array.Empty<string>());
|
||||||
lib.Add("foobar", item);
|
lib.Add("foobar", item);
|
||||||
Assert.AreEqual(1, lib.Count);
|
Assert.AreEqual(1, lib.Count);
|
||||||
Assert.AreEqual("testItem", lib["foobar"].Name);
|
Assert.AreEqual("testItem", lib["foobar"].Name);
|
||||||
|
@ -28,11 +28,11 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAddIterate()
|
public void CreateAddIterate()
|
||||||
{
|
{
|
||||||
using var lib = new ItemLibrary(10);
|
var lib = ItemLibrary.Create(10);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
for (ushort i = 0; i < 10; i++)
|
for (ushort i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
using var item = new Item(i.ToString(), ItemCategory.Mail, BattleItemCategory.None, 100,
|
var item = Item.Create(i.ToString(), ItemCategory.Mail, BattleItemCategory.None, 100,
|
||||||
Array.Empty<string>());
|
Array.Empty<string>());
|
||||||
lib.Add(i + "_key", item);
|
lib.Add(i + "_key", item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,21 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateLibrarySettings()
|
public void CreateLibrarySettings()
|
||||||
{
|
{
|
||||||
using var settings = new LibrarySettings(100, 4096);
|
var _ = LibrarySettings.Create(100, 4096);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetMaxLevel()
|
public void GetMaxLevel()
|
||||||
{
|
{
|
||||||
using var settings = new LibrarySettings(100, 4096);
|
var settings = LibrarySettings.Create(100, 4096);
|
||||||
Assert.AreEqual(100, settings.MaxLevel);
|
Assert.AreEqual(100, settings.MaxLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetShinyRate()
|
||||||
|
{
|
||||||
|
var settings = LibrarySettings.Create(100, 4096);
|
||||||
|
Assert.AreEqual(4096, settings.ShinyRate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,16 +10,16 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void Create()
|
public void Create()
|
||||||
{
|
{
|
||||||
using var lib = new MoveLibrary(0);
|
var lib = MoveLibrary.Create(0);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAndAdd()
|
public void CreateAndAdd()
|
||||||
{
|
{
|
||||||
using var lib = new MoveLibrary(1);
|
var lib = MoveLibrary.Create(1);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
using var move = new MoveData("testMove", new TypeIdentifier(0), MoveCategory.Physical, 100, 100, 1,
|
var move = MoveData.Create("testMove", new TypeIdentifier(0), MoveCategory.Physical, 100, 100, 1,
|
||||||
MoveTarget.All, 0, null, Array.Empty<string>());
|
MoveTarget.All, 0, null, Array.Empty<string>());
|
||||||
lib.Add("foobar", move);
|
lib.Add("foobar", move);
|
||||||
Assert.AreEqual(1, lib.Count);
|
Assert.AreEqual(1, lib.Count);
|
||||||
|
@ -29,11 +29,11 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAddIterate()
|
public void CreateAddIterate()
|
||||||
{
|
{
|
||||||
using var lib = new MoveLibrary(10);
|
var lib = MoveLibrary.Create(10);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
for (ushort i = 0; i < 10; i++)
|
for (ushort i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
using var move = new MoveData(i.ToString(), new TypeIdentifier(0), MoveCategory.Physical, 100, 100, 1,
|
var move = MoveData.Create(i.ToString(), new TypeIdentifier(0), MoveCategory.Physical, 100, 100, 1,
|
||||||
MoveTarget.All, 0, null, Array.Empty<string>());
|
MoveTarget.All, 0, null, Array.Empty<string>());
|
||||||
lib.Add(i + "_key", move);
|
lib.Add(i + "_key", move);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,15 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateNatureLibrary()
|
public void CreateNatureLibrary()
|
||||||
{
|
{
|
||||||
using var library = new NatureLibrary(0);
|
var _ = NatureLibrary.Create(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void LoadNatures()
|
public void LoadNatures()
|
||||||
{
|
{
|
||||||
using var library = new NatureLibrary(0);
|
var library = NatureLibrary.Create(0);
|
||||||
using var nature1 = Nature.NeutralNature();
|
var nature1 = Nature.NeutralNature();
|
||||||
using var nature2 = new Nature(Statistic.Attack, Statistic.Defense);
|
var nature2 = Nature.Create(Statistic.Attack, Statistic.Defense);
|
||||||
library.LoadNature("foo", nature1);
|
library.LoadNature("foo", nature1);
|
||||||
library.LoadNature("bar", nature2);
|
library.LoadNature("bar", nature2);
|
||||||
}
|
}
|
||||||
|
@ -25,56 +25,41 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void LoadAndGetNature()
|
public void LoadAndGetNature()
|
||||||
{
|
{
|
||||||
using var library = new NatureLibrary(0);
|
var library = NatureLibrary.Create(0);
|
||||||
using var nature1 = new Nature(Statistic.Attack, Statistic.Defense);
|
var nature1 = Nature.Create(Statistic.Attack, Statistic.Defense);
|
||||||
library.LoadNature("foo", nature1);
|
library.LoadNature("foo", nature1);
|
||||||
|
|
||||||
using (var n = library.TryGetNature("foo"))
|
Assert.That(library.TryGetNature("foo", out var n));
|
||||||
{
|
Assert.AreEqual(Statistic.Attack, n!.IncreasedStat);
|
||||||
Assert.AreEqual(Statistic.Attack, n.Value!.IncreasedStat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void LoadAndGetNatureTwice()
|
public void LoadAndGetNatureTwice()
|
||||||
{
|
{
|
||||||
using var library = new NatureLibrary(0);
|
var library = NatureLibrary.Create(0);
|
||||||
using var nature1 = new Nature(Statistic.Attack, Statistic.Defense);
|
var nature1 = Nature.Create(Statistic.Attack, Statistic.Defense);
|
||||||
library.LoadNature("foo", nature1);
|
library.LoadNature("foo", nature1);
|
||||||
|
Assert.That(library.TryGetNature("foo", out var n));
|
||||||
using (var n = library.TryGetNature("foo"))
|
Assert.AreEqual(Statistic.Attack, n!.IncreasedStat);
|
||||||
{
|
Assert.That(library.TryGetNature("foo", out var n2));
|
||||||
Assert.That(n.HasValue);
|
Assert.AreEqual(Statistic.Attack, n2!.IncreasedStat);
|
||||||
Assert.AreEqual(Statistic.Attack, n.Value!.IncreasedStat);
|
|
||||||
}
|
|
||||||
using (var n = library.TryGetNature("foo"))
|
|
||||||
{
|
|
||||||
Assert.That(n.HasValue);
|
|
||||||
Assert.AreEqual(Statistic.Attack, n.Value!.IncreasedStat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetUnknownNature()
|
public void GetUnknownNature()
|
||||||
{
|
{
|
||||||
using var library = new NatureLibrary(0);
|
var library = NatureLibrary.Create(0);
|
||||||
using var nature1 = new Nature(Statistic.Attack, Statistic.Defense);
|
Assert.IsFalse(library.TryGetNature("foo", out _));
|
||||||
|
|
||||||
using var n = library.TryGetNature("foo");
|
|
||||||
Assert.False(n.HasValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetNatureName()
|
public void GetNatureName()
|
||||||
{
|
{
|
||||||
using var library = new NatureLibrary(0);
|
var library = NatureLibrary.Create(0);
|
||||||
using var nature1 = new Nature(Statistic.Attack, Statistic.Defense);
|
var nature1 = Nature.Create(Statistic.Attack, Statistic.Defense);
|
||||||
library.LoadNature("foo", nature1);
|
library.LoadNature("foo", nature1);
|
||||||
|
Assert.That(library.TryGetNature("foo", out var n));
|
||||||
using (var n = library.TryGetNature("foo"))
|
Assert.AreEqual("foo", library.GetNatureName(n!));
|
||||||
{
|
|
||||||
Assert.AreEqual("foo", library.GetNatureName(n));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,20 +10,20 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void Create()
|
public void Create()
|
||||||
{
|
{
|
||||||
using var lib = new SpeciesLibrary(0);
|
var lib = SpeciesLibrary.Create(0);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAndAdd()
|
public void CreateAndAdd()
|
||||||
{
|
{
|
||||||
using var lib = new SpeciesLibrary(1);
|
var lib = SpeciesLibrary.Create(1);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
using var stats = new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0);
|
var stats = StaticStatisticSet<ushort>.Create(5, 10, 30, 20, 2, 0);
|
||||||
using var moves = new LearnableMoves();
|
var moves = LearnableMoves.Create();
|
||||||
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
var form = Form.Create("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
||||||
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
||||||
using var species = new Species(10, "testSpecies", 0.2f, "growth", 120, form, Array.Empty<string>());
|
var species = Species.Create(10, "testSpecies", 0.2f, "growth", 120, form, Array.Empty<string>());
|
||||||
lib.Add("foobar", species);
|
lib.Add("foobar", species);
|
||||||
Assert.AreEqual(1, lib.Count);
|
Assert.AreEqual(1, lib.Count);
|
||||||
Assert.AreEqual("testSpecies", lib["foobar"].Name);
|
Assert.AreEqual("testSpecies", lib["foobar"].Name);
|
||||||
|
@ -32,15 +32,15 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateAddIterate()
|
public void CreateAddIterate()
|
||||||
{
|
{
|
||||||
using var lib = new SpeciesLibrary(1);
|
var lib = SpeciesLibrary.Create(1);
|
||||||
Assert.AreEqual(0, lib.Count);
|
Assert.AreEqual(0, lib.Count);
|
||||||
for (ushort i = 0; i < 10; i++)
|
for (ushort i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
using var stats = new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0);
|
var stats = StaticStatisticSet<ushort>.Create(5, 10, 30, 20, 2, 0);
|
||||||
using var moves = new LearnableMoves();
|
var moves = LearnableMoves.Create();
|
||||||
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
var form = Form.Create("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
||||||
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
||||||
using var species = new Species(i, i.ToString(), 0.2f, "growth", 120, form, Array.Empty<string>());
|
var species = Species.Create(i, i.ToString(), 0.2f, "growth", 120, form, Array.Empty<string>());
|
||||||
lib.Add(i + "_key", species);
|
lib.Add(i + "_key", species);
|
||||||
}
|
}
|
||||||
Assert.AreEqual(10, lib.Count);
|
Assert.AreEqual(10, lib.Count);
|
||||||
|
|
|
@ -5,79 +5,79 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
{
|
{
|
||||||
public class StaticDataTests
|
public class StaticDataTests
|
||||||
{
|
{
|
||||||
private PkmnLibSharp.StaticData.Libraries.StaticData Build()
|
private static PkmnLibSharp.StaticData.Libraries.StaticData Build()
|
||||||
{
|
{
|
||||||
using var settings = new LibrarySettings(100, 4096);
|
var settings = LibrarySettings.Create(100, 4096);
|
||||||
using var species = new SpeciesLibrary(0);
|
var species = SpeciesLibrary.Create(0);
|
||||||
using var moves = new MoveLibrary(0);
|
var moves = MoveLibrary.Create(0);
|
||||||
using var items = new ItemLibrary(0);
|
var items = ItemLibrary.Create(0);
|
||||||
using var growthRates = new GrowthRateLibrary(0);
|
var growthRates = GrowthRateLibrary.Create(0);
|
||||||
using var types = new TypeLibrary(0);
|
var types = TypeLibrary.Create(0);
|
||||||
using var natures = new NatureLibrary(0);
|
var natures = NatureLibrary.Create(0);
|
||||||
using var abilities = new AbilityLibrary(0);
|
var abilities = AbilityLibrary.Create(0);
|
||||||
return new PkmnLibSharp.StaticData.Libraries.StaticData(settings, species, moves, items,
|
return PkmnLibSharp.StaticData.Libraries.StaticData.Create(settings, species, moves, items,
|
||||||
growthRates, types, natures, abilities);
|
growthRates, types, natures, abilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateNewStaticData()
|
public void CreateNewStaticData()
|
||||||
{
|
{
|
||||||
using var _ = Build();
|
var _ = Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetSettings()
|
public void GetSettings()
|
||||||
{
|
{
|
||||||
using var library = Build();
|
var library = Build();
|
||||||
var _ = library.LibrarySettings;
|
var _ = library.LibrarySettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetSpecies()
|
public void GetSpecies()
|
||||||
{
|
{
|
||||||
using var library = Build();
|
var library = Build();
|
||||||
var _ = library.SpeciesLibrary;
|
var _ = library.SpeciesLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetMoves()
|
public void GetMoves()
|
||||||
{
|
{
|
||||||
using var library = Build();
|
var library = Build();
|
||||||
var _ = library.MoveLibrary;
|
var _ = library.MoveLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetItems()
|
public void GetItems()
|
||||||
{
|
{
|
||||||
using var library = Build();
|
var library = Build();
|
||||||
var _ = library.ItemLibrary;
|
var _ = library.ItemLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetGrowthRates()
|
public void GetGrowthRates()
|
||||||
{
|
{
|
||||||
using var library = Build();
|
var library = Build();
|
||||||
var _ = library.GrowthRateLibrary;
|
var _ = library.GrowthRateLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetTypeLibrary()
|
public void GetTypeLibrary()
|
||||||
{
|
{
|
||||||
using var library = Build();
|
var library = Build();
|
||||||
var _ = library.TypeLibrary;
|
var _ = library.TypeLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetNatureLibrary()
|
public void GetNatureLibrary()
|
||||||
{
|
{
|
||||||
using var library = Build();
|
var library = Build();
|
||||||
var _ = library.NatureLibrary;
|
var _ = library.NatureLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetAbilityLibrary()
|
public void GetAbilityLibrary()
|
||||||
{
|
{
|
||||||
using var library = Build();
|
var library = Build();
|
||||||
var _ = library.AbilityLibrary;
|
var _ = library.AbilityLibrary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,20 +10,20 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateTypeLibrary()
|
public void CreateTypeLibrary()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void RegisterType()
|
public void RegisterType()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
typeLibrary.RegisterType("foobar");
|
typeLibrary.RegisterType("foobar");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void RegisterTypeRetrieve()
|
public void RegisterTypeRetrieve()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
||||||
Assert.AreEqual(typeIdentifier1, new TypeIdentifier(1));
|
Assert.AreEqual(typeIdentifier1, new TypeIdentifier(1));
|
||||||
var typeIdentifier2 = typeLibrary.RegisterType("bar");
|
var typeIdentifier2 = typeLibrary.RegisterType("bar");
|
||||||
|
@ -35,7 +35,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void GetUnknownTypeErrors()
|
public void GetUnknownTypeErrors()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
typeLibrary.RegisterType("foo");
|
typeLibrary.RegisterType("foo");
|
||||||
Assert.Throws<KeyNotFoundException>(() =>
|
Assert.Throws<KeyNotFoundException>(() =>
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void GetTypeName()
|
public void GetTypeName()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
||||||
Assert.AreEqual("foo", typeLibrary.GetTypeName(typeIdentifier1));
|
Assert.AreEqual("foo", typeLibrary.GetTypeName(typeIdentifier1));
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void GetUnknownTypeNameErrors()
|
public void GetUnknownTypeNameErrors()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
typeLibrary.RegisterType("foo");
|
typeLibrary.RegisterType("foo");
|
||||||
Assert.Throws<KeyNotFoundException>(() =>
|
Assert.Throws<KeyNotFoundException>(() =>
|
||||||
{
|
{
|
||||||
|
@ -65,7 +65,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void SetEffectiveness()
|
public void SetEffectiveness()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
||||||
var typeIdentifier2 = typeLibrary.RegisterType("bar");
|
var typeIdentifier2 = typeLibrary.RegisterType("bar");
|
||||||
typeLibrary.SetEffectiveness(typeIdentifier1, typeIdentifier2, 0.5f);
|
typeLibrary.SetEffectiveness(typeIdentifier1, typeIdentifier2, 0.5f);
|
||||||
|
@ -74,7 +74,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void GetEffectiveness()
|
public void GetEffectiveness()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
||||||
var typeIdentifier2 = typeLibrary.RegisterType("bar");
|
var typeIdentifier2 = typeLibrary.RegisterType("bar");
|
||||||
typeLibrary.SetEffectiveness(typeIdentifier1, typeIdentifier2, 0.5f);
|
typeLibrary.SetEffectiveness(typeIdentifier1, typeIdentifier2, 0.5f);
|
||||||
|
@ -84,7 +84,7 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
|
||||||
[Test]
|
[Test]
|
||||||
public void GetMultipleEffectiveness()
|
public void GetMultipleEffectiveness()
|
||||||
{
|
{
|
||||||
using var typeLibrary = new TypeLibrary(0);
|
var typeLibrary = TypeLibrary.Create(0);
|
||||||
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
var typeIdentifier1 = typeLibrary.RegisterType("foo");
|
||||||
var typeIdentifier2 = typeLibrary.RegisterType("bar");
|
var typeIdentifier2 = typeLibrary.RegisterType("bar");
|
||||||
typeLibrary.SetEffectiveness(typeIdentifier1, typeIdentifier2, 0.5f);
|
typeLibrary.SetEffectiveness(typeIdentifier1, typeIdentifier2, 0.5f);
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void BasicTests()
|
public void BasicTests()
|
||||||
{
|
{
|
||||||
using var move = new MoveData("foobar", new TypeIdentifier(), MoveCategory.Physical, 68, 23, 56,
|
var move = MoveData.Create("foobar", new TypeIdentifier(), MoveCategory.Physical, 68, 23, 56,
|
||||||
MoveTarget.Any, -3, null, Array.Empty<string>());
|
MoveTarget.Any, -3, null, Array.Empty<string>());
|
||||||
Assert.AreEqual("foobar", move.Name);
|
Assert.AreEqual("foobar", move.Name);
|
||||||
Assert.AreEqual(MoveCategory.Physical, move.Category);
|
Assert.AreEqual(MoveCategory.Physical, move.Category);
|
||||||
|
@ -24,8 +24,8 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void TestMoveWithSecondaryEffect()
|
public void TestMoveWithSecondaryEffect()
|
||||||
{
|
{
|
||||||
using var effect = new SecondaryEffect(0.25f, "foobar", Array.Empty<EffectParameter>());
|
var effect = SecondaryEffect.Create(0.25f, "foobar", Array.Empty<EffectParameter>());
|
||||||
using var move = new MoveData("foobar", new TypeIdentifier(), MoveCategory.Physical, 68, 23, 56,
|
var move = MoveData.Create("foobar", new TypeIdentifier(), MoveCategory.Physical, 68, 23, 56,
|
||||||
MoveTarget.Any, -3, effect, Array.Empty<string>());
|
MoveTarget.Any, -3, effect, Array.Empty<string>());
|
||||||
Assert.That(move.SecondaryEffect != null);
|
Assert.That(move.SecondaryEffect != null);
|
||||||
Assert.AreEqual("foobar", move.SecondaryEffect!.Name);
|
Assert.AreEqual("foobar", move.SecondaryEffect!.Name);
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Values] Statistic decreasedStat
|
[Values] Statistic decreasedStat
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
using var nature = new Nature(increasedStat, decreasedStat);
|
var nature = Nature.Create(increasedStat, decreasedStat);
|
||||||
Assert.AreEqual(increasedStat, nature.IncreasedStat);
|
Assert.AreEqual(increasedStat, nature.IncreasedStat);
|
||||||
Assert.AreEqual(decreasedStat, nature.DecreasedStat);
|
Assert.AreEqual(decreasedStat, nature.DecreasedStat);
|
||||||
if (increasedStat == decreasedStat)
|
if (increasedStat == decreasedStat)
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Values("foo", "bar", "", "ssdsdsdsdsd")] string effectName
|
[Values("foo", "bar", "", "ssdsdsdsdsd")] string effectName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
using var effect = new SecondaryEffect(chance, effectName, Array.Empty<EffectParameter>());
|
var effect = SecondaryEffect.Create(chance, effectName, Array.Empty<EffectParameter>());
|
||||||
Assert.AreEqual(effectName, effect.Name);
|
Assert.AreEqual(effectName, effect.Name);
|
||||||
Assert.AreEqual(chance, effect.Chance);
|
Assert.AreEqual(chance, effect.Chance);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,11 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
[Test]
|
[Test]
|
||||||
public void BasicTests()
|
public void BasicTests()
|
||||||
{
|
{
|
||||||
using var stats = new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0);
|
var stats = StaticStatisticSet<ushort>.Create(5, 10, 30, 20, 2, 0);
|
||||||
using var moves = new LearnableMoves();
|
var moves = LearnableMoves.Create();
|
||||||
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
var form = Form.Create("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
|
||||||
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
|
||||||
using var species = new Species(10, "testSpecies", 0.2f, "growth", 120, form, Array.Empty<string>());
|
var species = Species.Create(10, "testSpecies", 0.2f, "growth", 120, form, Array.Empty<string>());
|
||||||
Assert.AreEqual(10, species.Id);
|
Assert.AreEqual(10, species.Id);
|
||||||
Assert.AreEqual("testSpecies", species.Name);
|
Assert.AreEqual("testSpecies", species.Name);
|
||||||
Assert.AreEqual(0.2f, species.GenderRate, 0.00001f);
|
Assert.AreEqual(0.2f, species.GenderRate, 0.00001f);
|
||||||
|
|
|
@ -5,76 +5,11 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
{
|
{
|
||||||
public class StaticStaticStatisticSetTests
|
public class StaticStaticStatisticSetTests
|
||||||
{
|
{
|
||||||
[Test]
|
|
||||||
public void ByteStaticStatisticSet([Random(1)] byte hp, [Random(1)] byte attack, [Random(1)] byte defense,
|
|
||||||
[Random(1)] byte specialAttack, [Random(1)] byte specialDefense, [Random(1)] byte speed)
|
|
||||||
{
|
|
||||||
using var set = new StaticStatisticSet<byte>(hp, attack, defense, specialAttack, specialDefense, speed);
|
|
||||||
Assert.AreEqual(set.HP, hp);
|
|
||||||
Assert.AreEqual(set.Attack, attack);
|
|
||||||
Assert.AreEqual(set.Defense, defense);
|
|
||||||
Assert.AreEqual(set.SpecialAttack, specialAttack);
|
|
||||||
Assert.AreEqual(set.SpecialDefense, specialDefense);
|
|
||||||
Assert.AreEqual(set.Speed, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void UShortStaticStatisticSet([Random(1)] ushort hp, [Random(1)] ushort attack, [Random(1)] ushort defense,
|
public void UShortStaticStatisticSet([Random(1)] ushort hp, [Random(1)] ushort attack, [Random(1)] ushort defense,
|
||||||
[Random(1)] ushort specialAttack, [Random(1)] ushort specialDefense, [Random(1)] ushort speed)
|
[Random(1)] ushort specialAttack, [Random(1)] ushort specialDefense, [Random(1)] ushort speed)
|
||||||
{
|
{
|
||||||
using var set = new StaticStatisticSet<ushort>(hp, attack, defense, specialAttack, specialDefense, speed);
|
var set = StaticStatisticSet<ushort>.Create(hp, attack, defense, specialAttack, specialDefense, speed);
|
||||||
Assert.AreEqual(set.HP, hp);
|
|
||||||
Assert.AreEqual(set.Attack, attack);
|
|
||||||
Assert.AreEqual(set.Defense, defense);
|
|
||||||
Assert.AreEqual(set.SpecialAttack, specialAttack);
|
|
||||||
Assert.AreEqual(set.SpecialDefense, specialDefense);
|
|
||||||
Assert.AreEqual(set.Speed, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UintStaticStatisticSet([Random(1)] uint hp, [Random(1)] uint attack, [Random(1)] uint defense,
|
|
||||||
[Random(1)] uint specialAttack, [Random(1)] uint specialDefense, [Random(1)] uint speed)
|
|
||||||
{
|
|
||||||
using var set = new StaticStatisticSet<uint>(hp, attack, defense, specialAttack, specialDefense, speed);
|
|
||||||
Assert.AreEqual(set.HP, hp);
|
|
||||||
Assert.AreEqual(set.Attack, attack);
|
|
||||||
Assert.AreEqual(set.Defense, defense);
|
|
||||||
Assert.AreEqual(set.SpecialAttack, specialAttack);
|
|
||||||
Assert.AreEqual(set.SpecialDefense, specialDefense);
|
|
||||||
Assert.AreEqual(set.Speed, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SbyteStaticStatisticSet([Random(1)] sbyte hp, [Random(1)] sbyte attack, [Random(1)] sbyte defense,
|
|
||||||
[Random(1)] sbyte specialAttack, [Random(1)] sbyte specialDefense, [Random(1)] sbyte speed)
|
|
||||||
{
|
|
||||||
using var set = new StaticStatisticSet<sbyte>(hp, attack, defense, specialAttack, specialDefense, speed);
|
|
||||||
Assert.AreEqual(set.HP, hp);
|
|
||||||
Assert.AreEqual(set.Attack, attack);
|
|
||||||
Assert.AreEqual(set.Defense, defense);
|
|
||||||
Assert.AreEqual(set.SpecialAttack, specialAttack);
|
|
||||||
Assert.AreEqual(set.SpecialDefense, specialDefense);
|
|
||||||
Assert.AreEqual(set.Speed, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ShortStaticStatisticSet([Random(1)] short hp, [Random(1)] short attack, [Random(1)] short defense,
|
|
||||||
[Random(1)] short specialAttack, [Random(1)] short specialDefense, [Random(1)] short speed)
|
|
||||||
{
|
|
||||||
using var set = new StaticStatisticSet<short>(hp, attack, defense, specialAttack, specialDefense, speed);
|
|
||||||
Assert.AreEqual(set.HP, hp);
|
|
||||||
Assert.AreEqual(set.Attack, attack);
|
|
||||||
Assert.AreEqual(set.Defense, defense);
|
|
||||||
Assert.AreEqual(set.SpecialAttack, specialAttack);
|
|
||||||
Assert.AreEqual(set.SpecialDefense, specialDefense);
|
|
||||||
Assert.AreEqual(set.Speed, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void IntStaticStatisticSet([Random(1)] int hp, [Random(1)] int attack, [Random(1)] int defense,
|
|
||||||
[Random(1)] int specialAttack, [Random(1)] int specialDefense, [Random(1)] int speed)
|
|
||||||
{
|
|
||||||
using var set = new StaticStatisticSet<int>(hp, attack, defense, specialAttack, specialDefense, speed);
|
|
||||||
Assert.AreEqual(set.HP, hp);
|
Assert.AreEqual(set.HP, hp);
|
||||||
Assert.AreEqual(set.Attack, attack);
|
Assert.AreEqual(set.Attack, attack);
|
||||||
Assert.AreEqual(set.Defense, defense);
|
Assert.AreEqual(set.Defense, defense);
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
public void ByteStatisticSet([Random(1)] byte hp, [Random(1)] byte attack, [Random(1)] byte defense,
|
public void ByteStatisticSet([Random(1)] byte hp, [Random(1)] byte attack, [Random(1)] byte defense,
|
||||||
[Random(1)] byte specialAttack, [Random(1)] byte specialDefense, [Random(1)] byte speed)
|
[Random(1)] byte specialAttack, [Random(1)] byte specialDefense, [Random(1)] byte speed)
|
||||||
{
|
{
|
||||||
using var set = new StatisticSet<byte>(hp, attack, defense, specialAttack, specialDefense, speed);
|
var set = StatisticSet<byte>.Create(hp, attack, defense, specialAttack, specialDefense, speed);
|
||||||
Assert.AreEqual(set.HP, hp);
|
Assert.AreEqual(set.HP, hp);
|
||||||
Assert.AreEqual(set.Attack, attack);
|
Assert.AreEqual(set.Attack, attack);
|
||||||
Assert.AreEqual(set.Defense, defense);
|
Assert.AreEqual(set.Defense, defense);
|
||||||
|
@ -22,7 +22,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
public void ByteStatisticSetModifying([Random(1)] byte hp, [Random(1)] byte attack, [Random(1)] byte defense,
|
public void ByteStatisticSetModifying([Random(1)] byte hp, [Random(1)] byte attack, [Random(1)] byte defense,
|
||||||
[Random(1)] byte specialAttack, [Random(1)] byte specialDefense, [Random(1)] byte speed)
|
[Random(1)] byte specialAttack, [Random(1)] byte specialDefense, [Random(1)] byte speed)
|
||||||
{
|
{
|
||||||
using var set = new StatisticSet<byte>(0,0,0,0,0,0);
|
var set = StatisticSet<byte>.Create(0,0,0,0,0,0);
|
||||||
set.HP = hp;
|
set.HP = hp;
|
||||||
Assert.AreEqual(set.HP, hp);
|
Assert.AreEqual(set.HP, hp);
|
||||||
set.Attack = attack;
|
set.Attack = attack;
|
||||||
|
@ -36,25 +36,12 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
set.Speed = speed;
|
set.Speed = speed;
|
||||||
Assert.AreEqual(set.Speed, speed);
|
Assert.AreEqual(set.Speed, speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UShortStatisticSet([Random(1)] ushort hp, [Random(1)] ushort attack, [Random(1)] ushort defense,
|
|
||||||
[Random(1)] ushort specialAttack, [Random(1)] ushort specialDefense, [Random(1)] ushort speed)
|
|
||||||
{
|
|
||||||
using var set = new StatisticSet<ushort>(hp, attack, defense, specialAttack, specialDefense, speed);
|
|
||||||
Assert.AreEqual(set.HP, hp);
|
|
||||||
Assert.AreEqual(set.Attack, attack);
|
|
||||||
Assert.AreEqual(set.Defense, defense);
|
|
||||||
Assert.AreEqual(set.SpecialAttack, specialAttack);
|
|
||||||
Assert.AreEqual(set.SpecialDefense, specialDefense);
|
|
||||||
Assert.AreEqual(set.Speed, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void UintStatisticSet([Random(1)] uint hp, [Random(1)] uint attack, [Random(1)] uint defense,
|
public void UintStatisticSet([Random(1)] uint hp, [Random(1)] uint attack, [Random(1)] uint defense,
|
||||||
[Random(1)] uint specialAttack, [Random(1)] uint specialDefense, [Random(1)] uint speed)
|
[Random(1)] uint specialAttack, [Random(1)] uint specialDefense, [Random(1)] uint speed)
|
||||||
{
|
{
|
||||||
using var set = new StatisticSet<uint>(hp, attack, defense, specialAttack, specialDefense, speed);
|
var set = StatisticSet<uint>.Create(hp, attack, defense, specialAttack, specialDefense, speed);
|
||||||
Assert.AreEqual(set.HP, hp);
|
Assert.AreEqual(set.HP, hp);
|
||||||
Assert.AreEqual(set.Attack, attack);
|
Assert.AreEqual(set.Attack, attack);
|
||||||
Assert.AreEqual(set.Defense, defense);
|
Assert.AreEqual(set.Defense, defense);
|
||||||
|
@ -67,33 +54,7 @@ namespace PkmnLibRSharpTests.StaticData
|
||||||
public void SbyteStatisticSet([Random(1)] sbyte hp, [Random(1)] sbyte attack, [Random(1)] sbyte defense,
|
public void SbyteStatisticSet([Random(1)] sbyte hp, [Random(1)] sbyte attack, [Random(1)] sbyte defense,
|
||||||
[Random(1)] sbyte specialAttack, [Random(1)] sbyte specialDefense, [Random(1)] sbyte speed)
|
[Random(1)] sbyte specialAttack, [Random(1)] sbyte specialDefense, [Random(1)] sbyte speed)
|
||||||
{
|
{
|
||||||
using var set = new StatisticSet<sbyte>(hp, attack, defense, specialAttack, specialDefense, speed);
|
var set = StatisticSet<sbyte>.Create(hp, attack, defense, specialAttack, specialDefense, speed);
|
||||||
Assert.AreEqual(set.HP, hp);
|
|
||||||
Assert.AreEqual(set.Attack, attack);
|
|
||||||
Assert.AreEqual(set.Defense, defense);
|
|
||||||
Assert.AreEqual(set.SpecialAttack, specialAttack);
|
|
||||||
Assert.AreEqual(set.SpecialDefense, specialDefense);
|
|
||||||
Assert.AreEqual(set.Speed, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ShortStatisticSet([Random(1)] short hp, [Random(1)] short attack, [Random(1)] short defense,
|
|
||||||
[Random(1)] short specialAttack, [Random(1)] short specialDefense, [Random(1)] short speed)
|
|
||||||
{
|
|
||||||
using var set = new StatisticSet<short>(hp, attack, defense, specialAttack, specialDefense, speed);
|
|
||||||
Assert.AreEqual(set.HP, hp);
|
|
||||||
Assert.AreEqual(set.Attack, attack);
|
|
||||||
Assert.AreEqual(set.Defense, defense);
|
|
||||||
Assert.AreEqual(set.SpecialAttack, specialAttack);
|
|
||||||
Assert.AreEqual(set.SpecialDefense, specialDefense);
|
|
||||||
Assert.AreEqual(set.Speed, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void IntStatisticSet([Random(1)] int hp, [Random(1)] int attack, [Random(1)] int defense,
|
|
||||||
[Random(1)] int specialAttack, [Random(1)] int specialDefense, [Random(1)] int speed)
|
|
||||||
{
|
|
||||||
using var set = new StatisticSet<int>(hp, attack, defense, specialAttack, specialDefense, speed);
|
|
||||||
Assert.AreEqual(set.HP, hp);
|
Assert.AreEqual(set.HP, hp);
|
||||||
Assert.AreEqual(set.Attack, attack);
|
Assert.AreEqual(set.Attack, attack);
|
||||||
Assert.AreEqual(set.Defense, defense);
|
Assert.AreEqual(set.Defense, defense);
|
||||||
|
|
Loading…
Reference in New Issue