Register Static Library types.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
47db8464a2
commit
af9fa61245
|
@ -5,6 +5,7 @@
|
|||
#include "TypeRegistry/Library/RegisterItemTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterMoveTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterSpeciesTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterStaticLibraryTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterTypeLibrary.hpp"
|
||||
|
||||
CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver() {
|
||||
|
@ -36,6 +37,7 @@ void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* librar
|
|||
RegisterMoveTypes::Register(_engine);
|
||||
RegisterGrowthRateTypes::Register(_engine);
|
||||
RegisterTypeLibrary::Register(_engine);
|
||||
RegisterStaticLibraryTypes::Register(_engine);
|
||||
|
||||
_mainModule = _engine->GetModule("pkmn", asGM_ALWAYS_CREATE);
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#include "RegisterStaticLibraryTypes.hpp"
|
||||
#include <cassert>
|
||||
#include "../../../Library/PokemonLibrary.hpp"
|
||||
|
||||
void RegisterStaticLibraryTypes::Register(asIScriptEngine* engine) {
|
||||
RegisterLibrarySettingsType(engine);
|
||||
RegisterLibraryType(engine);
|
||||
}
|
||||
|
||||
void RegisterStaticLibraryTypes::RegisterLibrarySettingsType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("LibrarySettings", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
r = engine->RegisterObjectMethod("LibrarySettings", "uint8 get_MaximalLevel() const property",
|
||||
asMETHOD(CreatureLib::Library::LibrarySettings, GetMaximalLevel), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("LibrarySettings", "uint8 get_MaximalMoves() const property",
|
||||
asMETHOD(CreatureLib::Library::LibrarySettings, GetMaximalMoves), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings& get_Settings() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSettings), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSpeciesLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const MoveLibrary@ get_MoveLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetMoveLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const ItemLibrary@ get_ItemLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetItemLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const GrowthRateLibrary@ get_GrowthRateLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetGrowthRates), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetTypeLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
|
||||
#define PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
|
||||
|
||||
#include <angelscript.h>
|
||||
class RegisterStaticLibraryTypes {
|
||||
static void RegisterLibrarySettingsType(asIScriptEngine* engine);
|
||||
static void RegisterLibraryType(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef TESTS_BUILD
|
||||
#include "../../../extern/catch.hpp"
|
||||
#include "../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../TestLibrary/TestLibrary.hpp"
|
||||
#include "../../../../extern/catch.hpp"
|
||||
#include "../../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef TESTS_BUILD
|
||||
#include "../../../extern/catch.hpp"
|
||||
#include "../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../TestLibrary/TestLibrary.hpp"
|
||||
#include "../../../../extern/catch.hpp"
|
||||
#include "../../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef TESTS_BUILD
|
||||
#include "../../../extern/catch.hpp"
|
||||
#include "../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../TestLibrary/TestLibrary.hpp"
|
||||
#include "../../../../extern/catch.hpp"
|
||||
#include "../../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
|
@ -1,7 +1,7 @@
|
|||
#ifdef TESTS_BUILD
|
||||
#include "../../../extern/catch.hpp"
|
||||
#include "../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../TestLibrary/TestLibrary.hpp"
|
||||
#include "../../../../extern/catch.hpp"
|
||||
#include "../../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
|
@ -0,0 +1,147 @@
|
|||
#ifdef TESTS_BUILD
|
||||
#include "../../../../extern/catch.hpp"
|
||||
#include "../../../../src/AngelScript/AngelScripResolver.hpp"
|
||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||
class testScript1 {
|
||||
bool testMaximumLevel(const StaticLibrary@ s, uint8 level){ return s.Settings.MaximalLevel == level; }
|
||||
bool testMaximumMoves(const StaticLibrary@ s, uint8 moveCount){ return s.Settings.MaximalMoves == moveCount; }
|
||||
bool testSpeciesLibrary(const StaticLibrary@ s, const SpeciesLibrary@ speciesLib){ return s.SpeciesLibrary is speciesLib; }
|
||||
bool testMoveLibrary(const StaticLibrary@ s, const MoveLibrary@ moveLib){ return s.MoveLibrary is moveLib; }
|
||||
bool testItemLibrary(const StaticLibrary@ s, const ItemLibrary@ itemLib){ return s.ItemLibrary is itemLib; }
|
||||
bool testGrowthRateLibrary(const StaticLibrary@ s, const GrowthRateLibrary@ gl){ return s.GrowthRateLibrary is gl; }
|
||||
bool testTypeLibrary(const StaticLibrary@ s, const TypeLibrary@ tl){ return s.TypeLibrary is tl; }
|
||||
}
|
||||
)"}};
|
||||
|
||||
static const char* _testLoadFunc(const char* name) { return _scripts[name]; }
|
||||
|
||||
struct ScriptData {
|
||||
AngelScriptScript* Script;
|
||||
AngelScripResolver* Resolver;
|
||||
asIScriptFunction* Func;
|
||||
asIScriptContext* Context;
|
||||
|
||||
~ScriptData() {
|
||||
Script->GetContextPool()->ReturnContextToPool(Context);
|
||||
delete Script;
|
||||
delete Resolver;
|
||||
}
|
||||
};
|
||||
|
||||
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
||||
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||
lib->Initialize(mainLib);
|
||||
lib->SetCreateFunction(&_testLoadFunc);
|
||||
lib->CreateScript("testScript1");
|
||||
lib->FinalizeModule();
|
||||
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
auto ctxPool = script->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
auto func = script->PrepareMethod(funcName, ctx);
|
||||
REQUIRE(func != nullptr);
|
||||
|
||||
return {.Script = script, .Resolver = lib, .Func = func, .Context = ctx};
|
||||
}
|
||||
|
||||
TEST_CASE("Validate StaticLibrary Maximum Level in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testMaximumLevel");
|
||||
|
||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||
data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings().GetMaximalLevel());
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
TEST_CASE("Validate StaticLibrary Maximum Moves in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testMaximumMoves");
|
||||
|
||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||
data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings().GetMaximalMoves());
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
TEST_CASE("Validate StaticLibrary Species Library in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testSpeciesLibrary");
|
||||
|
||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||
data.Context->SetArgObject(
|
||||
1, const_cast<PkmnLib::Library::SpeciesLibrary*>(mainLib->GetStaticLib()->GetSpeciesLibrary()));
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
TEST_CASE("Validate StaticLibrary Move Library in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testMoveLibrary");
|
||||
|
||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||
data.Context->SetArgObject(1,
|
||||
const_cast<PkmnLib::Library::MoveLibrary*>(mainLib->GetStaticLib()->GetMoveLibrary()));
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
TEST_CASE("Validate StaticLibrary Item Library in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testItemLibrary");
|
||||
|
||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||
data.Context->SetArgObject(1,
|
||||
const_cast<PkmnLib::Library::ItemLibrary*>(mainLib->GetStaticLib()->GetItemLibrary()));
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
TEST_CASE("Validate StaticLibrary Growth Rate Library in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testGrowthRateLibrary");
|
||||
|
||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||
data.Context->SetArgObject(
|
||||
1, const_cast<CreatureLib::Library::GrowthRateLibrary*>(mainLib->GetStaticLib()->GetGrowthRates()));
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
TEST_CASE("Validate StaticLibrary Type Library in Script") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto data = GetScript(mainLib, "testTypeLibrary");
|
||||
|
||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||
data.Context->SetArgObject(
|
||||
1, const_cast<CreatureLib::Library::TypeLibrary*>(mainLib->GetStaticLib()->GetTypeLibrary()));
|
||||
|
||||
auto result = data.Context->Execute();
|
||||
REQUIRE(result == asEXECUTION_FINISHED);
|
||||
auto v = (bool)data.Context->GetReturnWord();
|
||||
REQUIRE(v);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue