Updates pkmnlib, adds wrappers for PkmnLib_ai

This commit is contained in:
Deukhoofd 2021-04-23 10:53:50 +02:00
parent ced4524737
commit 12850e3771
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
28 changed files with 211 additions and 18 deletions

View File

@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AI/@EntryIndexedValue">AI</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pkmn/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -0,0 +1,9 @@
namespace PkmnLibSharp.AI
{
public class DepthSearchAI : PokemonAI
{
public DepthSearchAI() : base(PkmnLibAI.Generated.DepthSearchAI.Create())
{
}
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace PkmnLibSharp.AI
{
public class NaiveAI : PokemonAI
{
public NaiveAI() : base(PkmnLibAI.Generated.NaiveAI.Create())
{
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using PkmnLibSharp.Battling;
using PkmnLibSharp.Utilities;
using BaseTurnChoice = PkmnLibSharp.Battling.ChoiceTurn.BaseTurnChoice;
namespace PkmnLibSharp.AI
{
public abstract class PokemonAI : PointerWrapper
{
protected PokemonAI(IntPtr ptr) : base(ptr)
{
}
public BaseTurnChoice GetChoice(Battle battle, Pokemon user)
{
var ptr = IntPtr.Zero;
PkmnLibAI.Generated.PokemonAI.GetChoice(ref ptr, Ptr, battle.Ptr, user.Ptr).Assert();
return BaseTurnChoice.GetFromPointer(ptr);
}
protected override void DeletePtr()
{
PkmnLibAI.Generated.PokemonAI.Delete(Ptr);
}
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace PkmnLibSharp.AI
{
public class RandomAI : PokemonAI
{
public RandomAI() : base(PkmnLibAI.Generated.RandomAI.Create())
{
}
}
}

View File

@ -6,8 +6,25 @@ namespace PkmnLibSharp.Battling.ChoiceTurn
public abstract class BaseTurnChoice : PointerWrapper
{
protected BaseTurnChoice(IntPtr ptr) : base(ptr){}
public static BaseTurnChoice GetFromPointer(IntPtr ptr)
{
var kind = (TurnChoiceKind) Creaturelib.Generated.BaseTurnChoice.GetKind(ptr);
switch (kind)
{
case TurnChoiceKind.Attack:
return new MoveTurnChoice(ptr);
case TurnChoiceKind.Switch:
return new SwitchTurnChoice(ptr);
case TurnChoiceKind.Flee:
return new FleeTurnChoice(ptr);
default:
throw new ArgumentOutOfRangeException();
}
}
public TurnChoiceKind Kind => (TurnChoiceKind) Creaturelib.Generated.BaseTurnChoice.GetKind(Ptr);
public Pokemon User
{

View File

@ -1,3 +1,5 @@
using System;
namespace PkmnLibSharp.Battling.ChoiceTurn
{
public class FleeTurnChoice : BaseTurnChoice
@ -5,6 +7,7 @@ namespace PkmnLibSharp.Battling.ChoiceTurn
public FleeTurnChoice(Pokemon user) : base(Creaturelib.Generated.FleeTurnChoice.Construct(user.Ptr))
{
}
internal FleeTurnChoice(IntPtr ptr) : base(ptr){}
protected override void DeletePtr()
{

View File

@ -1,3 +1,5 @@
using System;
namespace PkmnLibSharp.Battling.ChoiceTurn
{
public class SwitchTurnChoice : BaseTurnChoice
@ -6,6 +8,9 @@ namespace PkmnLibSharp.Battling.ChoiceTurn
Creaturelib.Generated.SwitchTurnChoice.Construct(user.Ptr, newPokemon.Ptr))
{
}
internal SwitchTurnChoice(IntPtr ptr) : base(ptr){}
protected override void DeletePtr()
{

View File

@ -87,5 +87,13 @@ namespace Creaturelib.Generated
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_BattleSide_MarkAsFled")]
internal static extern void MarkAsFled(IntPtr p);
/// <param name="out">unsigned char &</param>
/// <param name="p">BattleSide *</param>
/// <param name="a">unsigned char</param>
/// <param name="b">unsigned char</param>
/// <returns>unsigned char</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_BattleSide_SwapPositions")]
internal static extern byte SwapPositions(ref byte @out, IntPtr p, byte a, byte b);
}
}

View File

@ -19,5 +19,7 @@ namespace Creaturelib
ChangeVariant = 10,
AttackUse = 11,
ChangeStatBoost = 12,
Fail = 13,
Swap = 14,
}
}

View File

@ -0,0 +1,18 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace PkmnLibAI.Generated
{
internal static class C
{
/// <returns>const char *</returns>
[DllImport("libpkmnlib_ai", CallingConvention = CallingConvention.Cdecl, EntryPoint= "pkmnlibai_C_GetLastException")]
internal static extern IntPtr GetLastException();
/// <returns>const char *</returns>
[DllImport("libpkmnlib_ai", CallingConvention = CallingConvention.Cdecl, EntryPoint= "pkmnlibai_C_GetLastExceptionStacktrace")]
internal static extern IntPtr GetLastExceptionStacktrace();
}
}

View File

@ -0,0 +1,14 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace PkmnLibAI.Generated
{
internal static class DepthSearchAI
{
/// <returns>DepthSearchAI *</returns>
[DllImport("libpkmnlib_ai", CallingConvention = CallingConvention.Cdecl, EntryPoint= "pkmnlibai_DepthSearchAI_Create")]
internal static extern IntPtr Create();
}
}

View File

@ -0,0 +1,14 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace PkmnLibAI.Generated
{
internal static class NaiveAI
{
/// <returns>NaiveAI *</returns>
[DllImport("libpkmnlib_ai", CallingConvention = CallingConvention.Cdecl, EntryPoint= "pkmnlibai_NaiveAI_Create")]
internal static extern IntPtr Create();
}
}

View File

@ -0,0 +1,23 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace PkmnLibAI.Generated
{
internal static class PokemonAI
{
/// <param name="p">PokemonAI *</param>
/// <returns>void</returns>
[DllImport("libpkmnlib_ai", CallingConvention = CallingConvention.Cdecl, EntryPoint= "pkmnlibai_PokemonAI_Delete")]
internal static extern void Delete(IntPtr p);
/// <param name="out">BaseTurnChoice * &</param>
/// <param name="p">PokemonAI *</param>
/// <param name="battle">Battle *</param>
/// <param name="user">Pokemon *</param>
/// <returns>unsigned char</returns>
[DllImport("libpkmnlib_ai", CallingConvention = CallingConvention.Cdecl, EntryPoint= "pkmnlibai_PokemonAI_GetChoice")]
internal static extern byte GetChoice(ref IntPtr @out, IntPtr p, IntPtr battle, IntPtr user);
}
}

View File

@ -0,0 +1,14 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace PkmnLibAI.Generated
{
internal static class RandomAI
{
/// <returns>RandomAI *</returns>
[DllImport("libpkmnlib_ai", CallingConvention = CallingConvention.Cdecl, EntryPoint= "pkmnlibai_RandomAI_Create")]
internal static extern IntPtr Create();
}
}

View File

@ -19,5 +19,7 @@ namespace Pkmnlib
ChangeVariant = 10,
AttackUse = 11,
ChangeStatBoost = 12,
Fail = 13,
Swap = 14,
}
}

BIN
PkmnLibSharp/Native/Linux/libArbutils.so (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
PkmnLibSharp/Native/Linux/libpkmnLib.so (Stored with Git LFS)

Binary file not shown.

BIN
PkmnLibSharp/Native/Linux/libpkmnlib_ai.so (Stored with Git LFS) Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
PkmnLibSharp/Native/Windows/libpkmnLib.dll (Stored with Git LFS)

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8,15 +8,22 @@ def resolve_enum_size(size):
return "int"
raise Exception("Unknown size {}".format(size))
def clean_namespace(namespace):
if (namespace == "Pkmnlib_ai"):
return "PkmnLibAI"
return namespace
def write_enum(enum, enumNames):
namespace = str.capitalize(enum["filename"][3:])
if (namespace == "Pkmnlib_ai"):
return
if (enum["name"].startswith("bfd_")):
return
if (enum["name"].startswith("float_")):
return
if (enum["name"].startswith("as")):
return
filename = "Generated/{}/{}.cs".format(namespace, enum["name"])
filename = "Generated/{}/{}.cs".format(clean_namespace(namespace), enum["name"])
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, "w") as f:
f.write("// AUTOMATICALLY GENERATED, DO NOT EDIT\n")
@ -94,18 +101,20 @@ def parse_type(type, enumSet):
def clean_name(name):
if (name == "out"):
return "@out"
if (name == "event"):
return "@event"
if (name == ""):
return "_"
return name
def write_class(c, enumSet):
filename = "Generated/{}/{}.cs".format(c.file[3:].capitalize(), c.name)
filename = "Generated/{}/{}.cs".format(clean_namespace(c.file[3:].capitalize()), c.name)
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, "w") as f:
f.write("// AUTOMATICALLY GENERATED, DO NOT EDIT\n")
f.write("using System;\n")
f.write("using System.Runtime.InteropServices;\n\n")
f.write("namespace {}.Generated\n{{\n".format(c.namespace))
f.write("namespace {}.Generated\n{{\n".format(clean_namespace(c.namespace)))
f.write(" internal static class {}\n {{\n".format(c.name))
for function in c.functions:
for parameter in function.parameters:
@ -146,5 +155,6 @@ def main():
handle_file("arbutils.json")
handle_file("creaturelib.json")
handle_file("pkmnlib.json")
handle_file("pkmnlibai.json")
main()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long