Rework cache handling.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-10-08 13:42:30 +02:00
parent a140dcf781
commit cc2468c1d0
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
51 changed files with 412 additions and 150 deletions

View File

@ -0,0 +1,12 @@
using System;
using System.Runtime.InteropServices;
namespace PkmnLibSharp.FFI
{
[StructLayout(LayoutKind.Sequential)]
public struct IdentifiablePointer
{
public readonly IntPtr Ptr;
public readonly nuint Identifier;
}
}

View File

@ -6,7 +6,7 @@ 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 IntPtr ability_new(IntPtr name, IntPtr effect, IntPtr parameters, ulong size); internal static extern IdentifiablePointer 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 void ability_drop(IntPtr value);
@ -21,6 +21,6 @@ namespace PkmnLibSharp.FFI.StaticData
internal static extern ulong ability_parameter_length(IntPtr value); internal static extern ulong ability_parameter_length(IntPtr value);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr ability_parameter_get(IntPtr value, ulong index); internal static extern IdentifiablePointer ability_parameter_get(IntPtr value, ulong index);
} }
} }

View File

@ -6,16 +6,16 @@ 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 IntPtr effect_parameter_new_bool(byte value); internal static extern IdentifiablePointer effect_parameter_new_bool(byte value);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr effect_parameter_new_int(long value); internal static extern IdentifiablePointer effect_parameter_new_int(long value);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr effect_parameter_new_float(float value); internal static extern IdentifiablePointer 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 IntPtr effect_parameter_new_string(IntPtr value); internal static extern IdentifiablePointer effect_parameter_new_string(IntPtr 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 void effect_parameter_drop(IntPtr value);

View File

@ -7,10 +7,10 @@ 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 IntPtr form_new(IntPtr name, float height, float weight, uint baseExperience, internal static extern IdentifiablePointer form_new(IntPtr name, float height, float weight,
IntPtr types, ulong typesLength, IntPtr baseStats, IntPtr abilities, ulong abilitiesLength, uint baseExperience, IntPtr types, ulong typesLength, IntPtr baseStats, IntPtr abilities,
IntPtr hiddenAbilities, ulong hiddenAbilitiesLength, IntPtr learnableMoves, IntPtr flags, ulong abilitiesLength, IntPtr hiddenAbilities, ulong hiddenAbilitiesLength, IntPtr learnableMoves,
ulong flagsLength); IntPtr flags, ulong flagsLength);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern void form_drop(IntPtr ptr); internal static extern void form_drop(IntPtr ptr);
@ -34,7 +34,7 @@ namespace PkmnLibSharp.FFI.StaticData
internal static extern TypeIdentifier form_types_get(IntPtr ptr, ulong index); internal static extern TypeIdentifier form_types_get(IntPtr ptr, ulong index);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr form_base_stats(IntPtr ptr); internal static extern IdentifiablePointer form_base_stats(IntPtr ptr);
[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_abilities_length(IntPtr ptr);

View File

@ -7,7 +7,7 @@ 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 IntPtr item_new(IntPtr name, ItemCategory category, BattleItemCategory battleCategory, internal static extern IdentifiablePointer 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)]

View File

@ -6,13 +6,13 @@ 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 IntPtr ability_library_new(ulong capacity); internal static extern IdentifiablePointer 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_drop(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr ability_library_get(IntPtr ptr, IntPtr key); internal static extern IdentifiablePointer ability_library_get(IntPtr ptr, IntPtr key);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr ability_library_get_key_by_index(IntPtr ptr, ulong index); internal static extern IntPtr ability_library_get_key_by_index(IntPtr ptr, ulong index);

View File

@ -7,7 +7,7 @@ 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 IntPtr growth_rate_library_new(ulong capacity); internal static extern IdentifiablePointer 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 void growth_rate_library_drop(IntPtr ptr);

View File

@ -6,13 +6,13 @@ 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 IntPtr item_library_new(ulong capacity); internal static extern IdentifiablePointer 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 void item_library_drop(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr item_library_get(IntPtr ptr, IntPtr key); internal static extern IdentifiablePointer item_library_get(IntPtr ptr, IntPtr key);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr item_library_get_key_by_index(IntPtr ptr, ulong index); internal static extern IntPtr item_library_get_key_by_index(IntPtr ptr, ulong index);

View File

@ -7,7 +7,7 @@ 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 IntPtr library_settings_new(LevelInt maxLevel); internal static extern IdentifiablePointer library_settings_new(LevelInt maxLevel);
[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);

View File

@ -6,13 +6,13 @@ 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 IntPtr move_library_new(ulong capacity); internal static extern IdentifiablePointer 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 void move_library_drop(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr move_library_get(IntPtr ptr, IntPtr key); internal static extern IdentifiablePointer move_library_get(IntPtr ptr, IntPtr key);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr move_library_get_key_by_index(IntPtr ptr, ulong index); internal static extern IntPtr move_library_get_key_by_index(IntPtr ptr, ulong index);

View File

@ -6,7 +6,7 @@ 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 IntPtr nature_library_new(ulong capacity); internal static extern IdentifiablePointer 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_drop(IntPtr ptr);
@ -15,7 +15,7 @@ namespace PkmnLibSharp.FFI.StaticData.Libraries
internal static extern void nature_library_load_nature(IntPtr ptr, IntPtr name, IntPtr nature); 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 IntPtr nature_library_get_nature(IntPtr ptr, IntPtr name); internal static extern IdentifiablePointer nature_library_get_nature(IntPtr ptr, IntPtr name);
[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(IntPtr ptr, IntPtr nature);

View File

@ -6,13 +6,13 @@ 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 IntPtr species_library_new(ulong capacity); internal static extern IdentifiablePointer 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 void species_library_drop(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr species_library_get(IntPtr ptr, IntPtr key); internal static extern IdentifiablePointer species_library_get(IntPtr ptr, IntPtr key);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr species_library_get_key_by_index(IntPtr ptr, ulong index); internal static extern IntPtr species_library_get_key_by_index(IntPtr ptr, ulong index);

View File

@ -6,33 +6,33 @@ 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 IntPtr static_data_new(IntPtr settings); internal static extern IdentifiablePointer static_data_new(IntPtr settings);
[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 IntPtr static_data_settings(IntPtr ptr); internal static extern IdentifiablePointer static_data_settings(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_data_species(IntPtr ptr); internal static extern IdentifiablePointer static_data_species(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_data_moves(IntPtr ptr); internal static extern IdentifiablePointer static_data_moves(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_data_items(IntPtr ptr); internal static extern IdentifiablePointer static_data_items(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_data_growth_rates(IntPtr ptr); internal static extern IdentifiablePointer static_data_growth_rates(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_data_types(IntPtr ptr); internal static extern IdentifiablePointer static_data_types(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_data_natures(IntPtr ptr); internal static extern IdentifiablePointer static_data_natures(IntPtr ptr);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_data_abilities(IntPtr ptr); internal static extern IdentifiablePointer static_data_abilities(IntPtr ptr);
} }
} }

View File

@ -7,7 +7,7 @@ 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 IntPtr type_library_new(ulong capacity); internal static extern IdentifiablePointer type_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 type_library_drop(IntPtr ptr); internal static extern void type_library_drop(IntPtr ptr);

View File

@ -7,7 +7,7 @@ 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 IntPtr move_data_new(IntPtr name, TypeIdentifier moveType, MoveCategory category, internal static extern IdentifiablePointer 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, IntPtr secondaryEffect,
IntPtr flags, ulong flagsLength); IntPtr flags, ulong flagsLength);
@ -39,14 +39,14 @@ namespace PkmnLibSharp.FFI.StaticData
internal static extern sbyte move_data_priority(IntPtr p); internal static extern sbyte move_data_priority(IntPtr p);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr move_data_secondary_effect(IntPtr p); internal static extern IdentifiablePointer move_data_secondary_effect(IntPtr p);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern byte move_data_has_flag(IntPtr p, IntPtr flag); 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 IntPtr secondary_effect_new(float chance, IntPtr effectName, IntPtr parameters, internal static extern IdentifiablePointer 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)]
@ -62,6 +62,6 @@ namespace PkmnLibSharp.FFI.StaticData
internal static extern ulong secondary_effect_parameter_length(IntPtr p); internal static extern ulong secondary_effect_parameter_length(IntPtr p);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr secondary_effect_parameter_get(IntPtr p, ulong index); internal static extern IdentifiablePointer secondary_effect_parameter_get(IntPtr p, ulong index);
} }
} }

View File

@ -7,7 +7,7 @@ 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 IntPtr nature_new(Statistic increaseStat, Statistic decreaseStat, float increaseModifier, internal static extern IdentifiablePointer nature_new(Statistic increaseStat, Statistic decreaseStat, float increaseModifier,
float decreaseModifier); float decreaseModifier);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]

View File

@ -6,7 +6,7 @@ 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 IntPtr species_new(ushort id, IntPtr name, float genderRate, IntPtr growthRate, internal static extern IdentifiablePointer species_new(ushort id, IntPtr name, float genderRate, IntPtr growthRate,
byte captureRate, IntPtr defaultForm, IntPtr flags, ulong flagsLength); byte captureRate, IntPtr defaultForm, IntPtr flags, ulong flagsLength);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
@ -31,7 +31,7 @@ namespace PkmnLibSharp.FFI.StaticData
internal static extern IntPtr species_add_form(IntPtr ptr, IntPtr name, IntPtr form); internal static extern IntPtr species_add_form(IntPtr ptr, IntPtr name, IntPtr form);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr species_get_form(IntPtr ptr, IntPtr name); internal static extern IdentifiablePointer species_get_form(IntPtr ptr, IntPtr name);
} }
} }

View File

@ -7,27 +7,27 @@ 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 IntPtr static_statistic_set_u8_new(byte hp, byte attack, byte defense, internal static extern IdentifiablePointer static_statistic_set_u8_new(byte hp, byte attack, byte defense,
byte specialAttack, byte specialDefense, byte speed); byte specialAttack, 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 IntPtr static_statistic_set_u16_new(ushort hp, ushort attack, ushort defense, 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 IntPtr static_statistic_set_u32_new(uint hp, uint attack, uint defense, internal static extern IdentifiablePointer static_statistic_set_u32_new(uint hp, uint attack, uint defense,
uint specialAttack, uint specialDefense, uint speed); uint specialAttack, 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 IntPtr static_statistic_set_i8_new(sbyte hp, sbyte attack, sbyte defense, internal static extern IdentifiablePointer static_statistic_set_i8_new(sbyte hp, sbyte attack, sbyte defense,
sbyte specialAttack, sbyte specialDefense, sbyte speed); sbyte specialAttack, sbyte specialDefense, sbyte speed);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_statistic_set_i16_new(short hp, short attack, short defense, internal static extern IdentifiablePointer static_statistic_set_i16_new(short hp, short attack, short defense,
short specialAttack, short specialDefense, short speed); short specialAttack, short specialDefense, short speed);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr static_statistic_set_i32_new(int hp, int attack, int defense, int specialAttack, internal static extern IdentifiablePointer static_statistic_set_i32_new(int hp, int attack, int defense, int specialAttack,
int specialDefense, int speed); int specialDefense, int speed);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]

View File

@ -7,27 +7,27 @@ 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 IntPtr statistic_set_u8_new(byte hp, byte attack, byte defense, byte specialAttack, internal static extern IdentifiablePointer 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 IntPtr statistic_set_u16_new(ushort hp, ushort attack, ushort defense, internal static extern IdentifiablePointer 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 IntPtr statistic_set_u32_new(uint hp, uint attack, uint defense, uint specialAttack, 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 IntPtr statistic_set_i8_new(sbyte hp, sbyte attack, sbyte defense, sbyte specialAttack, internal static extern IdentifiablePointer 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)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr statistic_set_i16_new(short hp, short attack, short defense, short specialAttack, internal static extern IdentifiablePointer statistic_set_i16_new(short hp, short attack, short defense, short specialAttack,
short specialDefense, short speed); short specialDefense, short speed);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern IntPtr statistic_set_i32_new(int hp, int attack, int defense, int specialAttack, internal static extern IdentifiablePointer statistic_set_i32_new(int hp, int attack, int defense, int specialAttack,
int specialDefense, int speed); int specialDefense, int speed);
[DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [DllImport(Data.DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]

View File

@ -25,6 +25,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="IDisposableAnalyzers" Version="4.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" /> <PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
</ItemGroup> </ItemGroup>

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils; using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Ability; using Interface = PkmnLibSharp.FFI.StaticData.Ability;
@ -28,7 +29,7 @@ namespace PkmnLibSharp.StaticData
true); true);
} }
internal Ability(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal Ability(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -69,5 +70,10 @@ namespace PkmnLibSharp.StaticData
cacheParameter?.Invalidate(); cacheParameter?.Invalidate();
} }
} }
~Ability()
{
Dispose();
}
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using JetBrains.Annotations; using JetBrains.Annotations;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils; using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.EffectParameter; using Interface = PkmnLibSharp.FFI.StaticData.EffectParameter;
@ -14,7 +15,7 @@ namespace PkmnLibSharp.StaticData
public object? Data { get; internal set; } public object? Data { get; internal set; }
} }
internal EffectParameter(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal EffectParameter(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -89,5 +90,10 @@ 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();
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; 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;
@ -22,7 +23,7 @@ namespace PkmnLibSharp.StaticData
public LearnableMoves? LearnableMoves { get; internal set; } public LearnableMoves? LearnableMoves { get; internal set; }
} }
internal Form(IntPtr formPtr, bool isOwner) : base(formPtr, isOwner) internal Form(IdentifiablePointer formPtr, bool isOwner) : base(formPtr, isOwner)
{ {
} }
@ -77,5 +78,10 @@ namespace PkmnLibSharp.StaticData
{ {
Cache.LearnableMoves?.Invalidate(); Cache.LearnableMoves?.Invalidate();
} }
~Form()
{
Dispose();
}
} }
} }

View File

@ -44,5 +44,10 @@ namespace PkmnLibSharp.StaticData
{ {
return new object(); return new object();
} }
~LookupGrowthRate()
{
Dispose();
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; 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;
@ -103,7 +104,7 @@ namespace PkmnLibSharp.StaticData
InitializePointer(ptr, true); InitializePointer(ptr, true);
} }
internal Item(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal Item(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -116,5 +117,10 @@ namespace PkmnLibSharp.StaticData
protected override CacheData CreateCache() => new CacheData(); protected override CacheData CreateCache() => new CacheData();
protected override void Destructor() => Interface.item_drop(Ptr); protected override void Destructor() => Interface.item_drop(Ptr);
~Item()
{
Dispose();
}
} }
} }

View File

@ -27,5 +27,10 @@ namespace PkmnLibSharp.StaticData
protected override object CreateCache() => new object(); protected override object CreateCache() => new object();
protected override void Destructor() => Interface.learnable_moves_drop(Ptr); protected override void Destructor() => Interface.learnable_moves_drop(Ptr);
~LearnableMoves()
{
Dispose();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils; using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.ItemLibrary; using Interface = PkmnLibSharp.FFI.StaticData.Libraries.ItemLibrary;
@ -10,7 +11,7 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
} }
internal AbilityLibrary(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal AbilityLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -24,7 +25,7 @@ namespace PkmnLibSharp.StaticData.Libraries
protected override Ability? GetValueByKey(string key) protected override Ability? GetValueByKey(string key)
{ {
var ptr = Interface.item_library_get(Ptr, key.ToPtr()); var ptr = Interface.item_library_get(Ptr, key.ToPtr());
return ptr == IntPtr.Zero ? null : new Ability(ptr, false); return ptr.Ptr == IntPtr.Zero ? null : new Ability(ptr, false);
} }
public override string? GetKeyByIndex(ulong index) => public override string? GetKeyByIndex(ulong index) =>
@ -37,5 +38,10 @@ namespace PkmnLibSharp.StaticData.Libraries
value.Invalidate(); value.Invalidate();
} }
} }
~AbilityLibrary()
{
Dispose();
}
} }
} }

View File

@ -2,13 +2,14 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; 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> : ExternPointer<DataLibrary<T>.CacheData>, IReadOnlyDictionary<string, T>
{ {
protected DataLibrary(IntPtr ptr, bool isOwner) : base(ptr, isOwner) protected DataLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -90,5 +91,10 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
return GetEnumerator(); return GetEnumerator();
} }
~DataLibrary()
{
Dispose();
}
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
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;
@ -11,7 +12,7 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
} }
internal GrowthRateLibrary(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal GrowthRateLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -29,5 +30,10 @@ namespace PkmnLibSharp.StaticData.Libraries
protected override object CreateCache() => new(); protected override object CreateCache() => new();
protected override void Destructor() => Interface.growth_rate_library_drop(Ptr); protected override void Destructor() => Interface.growth_rate_library_drop(Ptr);
~GrowthRateLibrary()
{
Dispose();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils; using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.ItemLibrary; using Interface = PkmnLibSharp.FFI.StaticData.Libraries.ItemLibrary;
@ -10,7 +11,7 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
} }
internal ItemLibrary(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal ItemLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -24,7 +25,7 @@ namespace PkmnLibSharp.StaticData.Libraries
protected override Item? GetValueByKey(string key) protected override Item? GetValueByKey(string key)
{ {
var ptr = Interface.item_library_get(Ptr, key.ToPtr()); var ptr = Interface.item_library_get(Ptr, key.ToPtr());
return ptr == IntPtr.Zero ? null : new Item(ptr, false); return ptr.Ptr == IntPtr.Zero ? null : new Item(ptr, false);
} }
public override string? GetKeyByIndex(ulong index) => public override string? GetKeyByIndex(ulong index) =>
@ -37,5 +38,10 @@ namespace PkmnLibSharp.StaticData.Libraries
value.Invalidate(); value.Invalidate();
} }
} }
~ItemLibrary()
{
Dispose();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils; using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.LibrarySettings; using Interface = PkmnLibSharp.FFI.StaticData.Libraries.LibrarySettings;
@ -15,7 +16,7 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
} }
internal LibrarySettings(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal LibrarySettings(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -24,5 +25,10 @@ namespace PkmnLibSharp.StaticData.Libraries
protected override CacheData CreateCache() => new(); protected override CacheData CreateCache() => new();
protected override void Destructor() => Interface.library_settings_drop(Ptr); protected override void Destructor() => Interface.library_settings_drop(Ptr);
~LibrarySettings()
{
Dispose();
}
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils; using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.MoveLibrary; using Interface = PkmnLibSharp.FFI.StaticData.Libraries.MoveLibrary;
@ -11,7 +12,7 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
} }
internal MoveLibrary(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal MoveLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -28,7 +29,7 @@ namespace PkmnLibSharp.StaticData.Libraries
protected override MoveData? GetValueByKey(string key) protected override MoveData? GetValueByKey(string key)
{ {
var ptr = Interface.move_library_get(Ptr, key.ToPtr()); var ptr = Interface.move_library_get(Ptr, key.ToPtr());
return ptr == IntPtr.Zero ? null : new MoveData(ptr, false); return ptr.Ptr == IntPtr.Zero ? null : new MoveData(ptr, false);
} }
public override string? GetKeyByIndex(ulong index) => public override string? GetKeyByIndex(ulong index) =>
@ -41,5 +42,10 @@ namespace PkmnLibSharp.StaticData.Libraries
value.Invalidate(); value.Invalidate();
} }
} }
~MoveLibrary()
{
Dispose();
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; 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.Libraries.NatureLibrary; using Interface = PkmnLibSharp.FFI.StaticData.Libraries.NatureLibrary;
@ -17,20 +18,20 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
} }
internal NatureLibrary(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal NatureLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
public bool TryGetNature(string name, out Nature nature) public Optional<Nature> TryGetNature(string name)
{ {
if (Cache.Natures.TryGetValue(name, out nature)) if (Cache.Natures.TryGetValue(name, out var nature))
return true; return nature;
var naturePtr = Interface.nature_library_get_nature(Ptr, name.ToPtr()); var naturePtr = Interface.nature_library_get_nature(Ptr, name.ToPtr());
if (naturePtr == IntPtr.Zero) if (naturePtr.Ptr == IntPtr.Zero)
return false; return Optional<Nature>.None();
nature = new Nature(naturePtr, false); nature = new Nature(naturePtr);
Cache.Natures.Add(name, nature); Cache.Natures.Add(name, nature);
return true; return nature;
} }
public string GetNatureName(Nature nature) public string GetNatureName(Nature nature)
@ -55,5 +56,10 @@ namespace PkmnLibSharp.StaticData.Libraries
nature.Invalidate(); nature.Invalidate();
} }
} }
~NatureLibrary()
{
Dispose();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; 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;
@ -10,7 +11,7 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
} }
internal SpeciesLibrary(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal SpeciesLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -24,7 +25,7 @@ namespace PkmnLibSharp.StaticData.Libraries
protected override Species? GetValueByKey(string key) protected override Species? GetValueByKey(string key)
{ {
var ptr = Interface.species_library_get(Ptr, key.ToPtr()); var ptr = Interface.species_library_get(Ptr, key.ToPtr());
return ptr == IntPtr.Zero ? null : new Species(ptr, false); return ptr.Ptr == IntPtr.Zero ? null : new Species(ptr, false);
} }
public override string? GetKeyByIndex(ulong index) => public override string? GetKeyByIndex(ulong index) =>
@ -37,5 +38,10 @@ namespace PkmnLibSharp.StaticData.Libraries
value.Invalidate(); value.Invalidate();
} }
} }
~SpeciesLibrary()
{
Dispose();
}
} }
} }

View File

@ -64,5 +64,10 @@ namespace PkmnLibSharp.StaticData.Libraries
Cache.NatureLibrary?.Invalidate(); Cache.NatureLibrary?.Invalidate();
Cache.AbilityLibrary?.Invalidate(); Cache.AbilityLibrary?.Invalidate();
} }
~StaticData()
{
Dispose();
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; 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.Libraries.TypeLibrary; using Interface = PkmnLibSharp.FFI.StaticData.Libraries.TypeLibrary;
@ -18,7 +19,7 @@ namespace PkmnLibSharp.StaticData.Libraries
{ {
} }
internal TypeLibrary(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal TypeLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -61,5 +62,10 @@ namespace PkmnLibSharp.StaticData.Libraries
protected override CacheData CreateCache() => new(); protected override CacheData CreateCache() => new();
protected override void Destructor() => Interface.type_library_drop(Ptr); protected override void Destructor() => Interface.type_library_drop(Ptr);
~TypeLibrary()
{
Dispose();
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; 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;
@ -76,7 +77,7 @@ namespace PkmnLibSharp.StaticData
public SecondaryEffect? SecondaryEffect { get; internal set; } public SecondaryEffect? SecondaryEffect { get; internal set; }
} }
internal MoveData(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal MoveData(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -108,7 +109,7 @@ namespace PkmnLibSharp.StaticData
if (Cache.SecondaryEffect != null) if (Cache.SecondaryEffect != null)
return Cache.SecondaryEffect; return Cache.SecondaryEffect;
var effect = Interface.move_data_secondary_effect(Ptr); var effect = Interface.move_data_secondary_effect(Ptr);
if (effect == IntPtr.Zero) if (effect.Ptr == IntPtr.Zero)
return null; return null;
Cache.SecondaryEffect = new SecondaryEffect(effect, false); Cache.SecondaryEffect = new SecondaryEffect(effect, false);
return Cache.SecondaryEffect; return Cache.SecondaryEffect;
@ -135,5 +136,10 @@ namespace PkmnLibSharp.StaticData
base.InvalidateChildren(); base.InvalidateChildren();
Cache.SecondaryEffect?.Invalidate(); Cache.SecondaryEffect?.Invalidate();
} }
~MoveData()
{
Dispose();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils; using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Nature; using Interface = PkmnLibSharp.FFI.StaticData.Nature;
@ -18,7 +19,7 @@ namespace PkmnLibSharp.StaticData
{ {
} }
internal Nature(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal Nature(IdentifiablePointer ptr) : base(ptr, true)
{ {
} }
@ -52,5 +53,10 @@ namespace PkmnLibSharp.StaticData
{ {
Interface.nature_drop(Ptr); Interface.nature_drop(Ptr);
} }
~Nature()
{
Dispose();
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; 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;
@ -15,7 +16,7 @@ namespace PkmnLibSharp.StaticData
public CachedExternArray<EffectParameter>? Parameters { get; internal set; } public CachedExternArray<EffectParameter>? Parameters { get; internal set; }
} }
internal SecondaryEffect(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal SecondaryEffect(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -31,10 +32,11 @@ namespace PkmnLibSharp.StaticData
public float Chance => Cache.Chance ??= Interface.secondary_effect_chance(Ptr); public float Chance => Cache.Chance ??= Interface.secondary_effect_chance(Ptr);
public string Name => Cache.Name ?? (Cache.Name = Interface.secondary_effect_effect_name(Ptr).PtrString()!); public string Name => Cache.Name ?? (Cache.Name = Interface.secondary_effect_effect_name(Ptr).PtrString()!);
public IReadOnlyList<EffectParameter> Parameters => public IReadOnlyList<EffectParameter> GetParameters()
Cache.Parameters ??= new CachedExternArray<EffectParameter>( {
Interface.secondary_effect_parameter_length(Ptr), return Cache.Parameters ??= new CachedExternArray<EffectParameter>(Interface.secondary_effect_parameter_length(Ptr),
arg => new EffectParameter(Interface.secondary_effect_parameter_get(Ptr, arg), false)); arg => new EffectParameter(Interface.secondary_effect_parameter_get(Ptr, arg), false));
}
protected override CacheData CreateCache() protected override CacheData CreateCache()
{ {
@ -57,5 +59,10 @@ namespace PkmnLibSharp.StaticData
} }
} }
} }
~SecondaryEffect()
{
Dispose();
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; 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.Species; using Interface = PkmnLibSharp.FFI.StaticData.Species;
@ -18,7 +19,7 @@ namespace PkmnLibSharp.StaticData
public Dictionary<string, Form> Forms { get; } = new(); public Dictionary<string, Form> Forms { get; } = new();
} }
internal Species(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal Species(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -27,7 +28,7 @@ namespace PkmnLibSharp.StaticData
{ {
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 ptr = Interface.species_new(id, name.ToPtr(), genderRate, growthRate.ToPtr(), captureRate,
defaultForm.TakeOwnershipAndInvalidate(), flagsPtrArray.ArrayPtr(), (ulong)flags.Count); defaultForm.Ptr, flagsPtrArray.ArrayPtr(), (ulong)flags.Count);
InitializePointer(ptr, true); InitializePointer(ptr, true);
} }
@ -42,7 +43,7 @@ namespace PkmnLibSharp.StaticData
if (Cache.Forms.TryGetValue(formName, out form)) if (Cache.Forms.TryGetValue(formName, out form))
return true; return true;
var formPtr = Interface.species_get_form(Ptr, formName.ToPtr()); var formPtr = Interface.species_get_form(Ptr, formName.ToPtr());
if (formPtr == IntPtr.Zero) if (formPtr.Ptr == IntPtr.Zero)
{ {
form = null; form = null;
return false; return false;
@ -66,5 +67,10 @@ namespace PkmnLibSharp.StaticData
form.Value.Invalidate(); form.Value.Invalidate();
} }
} }
~Species()
{
Dispose();
}
} }
} }

View File

@ -1,5 +1,6 @@
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;
@ -17,7 +18,7 @@ namespace PkmnLibSharp.StaticData
public T? Speed { get; internal set; } public T? Speed { get; internal set; }
} }
internal StaticStatisticSet(IntPtr ptr, bool isOwner) : base(ptr, isOwner) internal StaticStatisticSet(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{ {
} }
@ -129,5 +130,10 @@ namespace PkmnLibSharp.StaticData
else if (typeof(T) == typeof(short)) Interface.static_statistic_set_i16_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); else if (typeof(T) == typeof(int)) Interface.static_statistic_set_i32_drop(Ptr);
} }
~StaticStatisticSet()
{
Dispose();
}
} }
} }

View File

@ -5,13 +5,8 @@ using Interface = PkmnLibSharp.FFI.StaticData.StatisticSet;
namespace PkmnLibSharp.StaticData namespace PkmnLibSharp.StaticData
{ {
public class StatisticSet<T> : ExternPointer<StatisticSet<T>.CacheData> where T : struct, IConvertible public class StatisticSet<T> : ExternPointer<object> where T : struct, IConvertible
{ {
public class CacheData
{
// While we require cache types for all pointer data, we can't make caching assumptions for this type.
// As such, this is empty (and never instantiated).
}
public StatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed) public StatisticSet(T hp, T attack, T defense, T specialAttack, T specialDefense, T speed)
{ {
@ -109,10 +104,7 @@ namespace PkmnLibSharp.StaticData
} }
protected override CacheData CreateCache() protected override object CreateCache() => new();
{
return new CacheData();
}
protected override void Destructor() protected override void Destructor()
{ {
@ -123,5 +115,10 @@ namespace PkmnLibSharp.StaticData
else if (typeof(T) == typeof(short)) Interface.statistic_set_i16_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); else if (typeof(T) == typeof(int)) Interface.statistic_set_i32_drop(Ptr);
} }
~StatisticSet()
{
Dispose();
}
} }
} }

View File

@ -0,0 +1,70 @@
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()
{
}
}
}

View File

@ -5,14 +5,14 @@ namespace PkmnLibSharp.Utils
{ {
internal static class CacheHandler internal static class CacheHandler
{ {
private static readonly ConcurrentDictionary<IntPtr, object> Caches = new(); private static readonly ConcurrentDictionary<ulong, object> Caches = new();
internal static T GetCache<T>(IntPtr ptr, Func<object> ctor) internal static T GetCache<T>(ulong id, Func<object> ctor)
{ {
if (!Caches.TryGetValue(ptr, out var cache)) if (!Caches.TryGetValue(id, out var cache))
{ {
cache = ctor(); cache = ctor();
Caches.TryAdd(ptr, cache); Caches.TryAdd(id, cache);
} }
if (cache.GetType() != typeof(T)) if (cache.GetType() != typeof(T))
@ -23,9 +23,9 @@ namespace PkmnLibSharp.Utils
return (T)cache; return (T)cache;
} }
internal static void RemoveCache(IntPtr ptr) internal static void RemoveCache(ulong id)
{ {
Caches.TryRemove(ptr, out _); Caches.TryRemove(id, out _);
} }
} }
} }

View File

@ -1,26 +1,16 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using PkmnLibSharp.FFI;
[assembly: InternalsVisibleTo("PkmnLibRSharp")] [assembly: InternalsVisibleTo("PkmnLibRSharp")]
namespace PkmnLibSharp.Utils namespace PkmnLibSharp.Utils
{ {
public abstract class ExternPointer<TCache> : IDisposable public abstract class ExternPointer<TCache> : BasePointer<TCache>
where TCache : class where TCache : class
{ {
private IntPtr _ptr;
private bool _isOwner; private bool _isOwner;
private bool _isInvalidated; private bool _isInvalidated;
private bool _isDisposed; private bool _isDisposed;
private TCache? _cache;
protected abstract TCache CreateCache();
internal TCache Cache
{
get { return _cache ??= CacheHandler.GetCache<TCache>(_ptr, CreateCache); }
}
protected bool HasCache => _cache != null;
protected ExternPointer() protected ExternPointer()
{ {
@ -32,15 +22,25 @@ namespace PkmnLibSharp.Utils
InitializePointer(ptr, isOwner); InitializePointer(ptr, isOwner);
} }
protected void InitializePointer(IntPtr ptr, bool isOwner) protected ExternPointer(IdentifiablePointer ptr, bool isOwner) : base(ptr)
{ {
_ptr = ptr;
_isOwner = isOwner; _isOwner = isOwner;
} }
protected abstract void Destructor();
internal IntPtr Ptr 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 get
{ {
@ -48,7 +48,7 @@ namespace PkmnLibSharp.Utils
{ {
throw new Exception("Pointer was used after invalidate"); throw new Exception("Pointer was used after invalidate");
} }
return _ptr; return base.Ptr;
} }
} }
@ -72,13 +72,13 @@ namespace PkmnLibSharp.Utils
internal void Invalidate() internal void Invalidate()
{ {
_isInvalidated = true; _isInvalidated = true;
CacheHandler.RemoveCache(_ptr); CacheHandler.RemoveCache(Identifier);
InvalidateChildren(); InvalidateChildren();
} }
public virtual void InvalidateChildren(){} public virtual void InvalidateChildren(){}
public void Dispose() public override void Dispose()
{ {
if (_isDisposed) if (_isDisposed)
return; return;
@ -88,10 +88,11 @@ namespace PkmnLibSharp.Utils
if (!_isInvalidated) if (!_isInvalidated)
Destructor(); Destructor();
_isOwner = false; _isOwner = false;
CacheHandler.RemoveCache(_ptr); CacheHandler.RemoveCache(Identifier);
} }
_isDisposed = true; _isDisposed = true;
_isInvalidated = true; _isInvalidated = true;
GC.SuppressFinalize(this);
} }
} }
} }

View File

@ -0,0 +1,39 @@
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
}
}
}

BIN
PkmnLibRSharp/libpkmn_lib.so (Stored with Git LFS)

Binary file not shown.

View File

@ -14,6 +14,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="IDisposableAnalyzers" Version="4.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />

View File

@ -26,10 +26,14 @@ namespace PkmnLibRSharpTests.StaticData
using var ability = new Ability("", "", using var ability = new Ability("", "",
new EffectParameter[] { new(100), new(false), new("foobar"), new(true) }); new EffectParameter[] { new(100), new(false), new("foobar"), new(true) });
Assert.AreEqual(4, ability.ParameterLength); Assert.AreEqual(4, ability.ParameterLength);
Assert.AreEqual(100, ability.GetParameter(0).Data); using var p1 = ability.GetParameter(0);
Assert.AreEqual(false, ability.GetParameter(1).Data); Assert.AreEqual(100, p1.Data);
Assert.AreEqual("foobar", ability.GetParameter(2).Data); using var p2 = ability.GetParameter(1);
Assert.AreEqual(true, ability.GetParameter(3).Data); Assert.AreEqual(false, p2.Data);
using var p3 = ability.GetParameter(2);
Assert.AreEqual("foobar", p3.Data);
using var p4 = ability.GetParameter(3);
Assert.AreEqual(true, p4.Data);
} }
} }
} }

View File

@ -8,30 +8,27 @@ namespace PkmnLibRSharpTests.StaticData
[Test] [Test]
public void CreateAndDropLookupGrowthRate() public void CreateAndDropLookupGrowthRate()
{ {
var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 }); using var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 });
growthRate.Dispose();
} }
[Test] [Test]
public void LookupGrowthRateCalculateLevel() public void LookupGrowthRateCalculateLevel()
{ {
var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 }); using var growthRate = new LookupGrowthRate(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));
Assert.AreEqual(3, growthRate.CalculateLevel(5)); Assert.AreEqual(3, growthRate.CalculateLevel(5));
growthRate.Dispose();
} }
[Test] [Test]
public void LookupGrowthRateCalculateExperience() public void LookupGrowthRateCalculateExperience()
{ {
var growthRate = new LookupGrowthRate(new uint[] { 0, 1, 5, 10, 20, 100, 200, 500 }); using var growthRate = new LookupGrowthRate(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));
growthRate.Dispose();
} }
} }

View File

@ -29,8 +29,10 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
using var nature1 = new Nature(Statistic.Attack, Statistic.Defense); using var nature1 = new Nature(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.AreEqual(Statistic.Attack, n.Value!.IncreasedStat);
}
} }
[Test] [Test]
@ -40,11 +42,16 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
using var nature1 = new Nature(Statistic.Attack, Statistic.Defense); using var nature1 = new Nature(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(n.HasValue);
Assert.That(library.TryGetNature("foo", out n)); Assert.AreEqual(Statistic.Attack, n.Value!.IncreasedStat);
Assert.AreEqual(Statistic.Attack, n.IncreasedStat); }
using (var n = library.TryGetNature("foo"))
{
Assert.That(n.HasValue);
Assert.AreEqual(Statistic.Attack, n.Value!.IncreasedStat);
}
} }
[Test] [Test]
@ -53,7 +60,8 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
using var library = new NatureLibrary(0); using var library = new NatureLibrary(0);
using var nature1 = new Nature(Statistic.Attack, Statistic.Defense); using var nature1 = new Nature(Statistic.Attack, Statistic.Defense);
Assert.False(library.TryGetNature("foo", out _)); using var n = library.TryGetNature("foo");
Assert.False(n.HasValue);
} }
[Test] [Test]
@ -63,9 +71,11 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
using var nature1 = new Nature(Statistic.Attack, Statistic.Defense); using var nature1 = new Nature(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));
} }
}
} }
} }