Support for new version of CreatureLib.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-02-28 19:51:50 +01:00
parent dba8ae2b83
commit 29a82a5e75
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
19 changed files with 113 additions and 100 deletions

View File

@ -1,7 +1,7 @@
#include "PokemonForme.hpp" #include "PokemonForme.hpp"
PkmnLib::Library::PokemonForme::PokemonForme(std::string name, float height, float weight, uint32_t baseExperience, PkmnLib::Library::PokemonForme::PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience,
std::vector<uint8_t> types, std::vector<uint8_t> types,
CreatureLib::Core::StatisticSet<uint16_t> baseStats, CreatureLib::Core::StatisticSet<uint16_t> baseStats,
std::vector<std::string> talents, std::vector<std::string> secretTalents, std::vector<ConstString> talents, std::vector<ConstString> secretTalents,
const CreatureLib::Library::LearnableAttacks* attacks) const CreatureLib::Library::LearnableAttacks* attacks)
: SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks) {} : SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks) {}

View File

@ -6,13 +6,13 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
class PokemonForme : public CreatureLib::Library::SpeciesVariant { class PokemonForme : public CreatureLib::Library::SpeciesVariant {
public: public:
PokemonForme(std::string name, float height, float weight, uint32_t baseExperience, std::vector<uint8_t> types, PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience, std::vector<uint8_t> types,
CreatureLib::Core::StatisticSet<uint16_t> baseStats, std::vector<std::string> talents, CreatureLib::Core::StatisticSet<uint16_t> baseStats, std::vector<ConstString> talents,
std::vector<std::string> secretTalents, const CreatureLib::Library::LearnableAttacks* attacks); std::vector<ConstString> secretTalents, const CreatureLib::Library::LearnableAttacks* attacks);
private: private:
public: public:
inline const std::string& GetAbility(int index) const { return GetTalent(index); } inline const ConstString& GetAbility(int index) const { return GetTalent(index); }
}; };
} }

View File

@ -85,18 +85,18 @@ void AngelScripResolver::RegisterTypes() {
BasicScriptClass::Register(_engine); BasicScriptClass::Register(_engine);
} }
AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const std::string& name, const std::string& decl) { AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const ConstString& name, const std::string& decl) {
auto find = _types.find(decl); auto find = _types.find(name);
if (find != _types.end()) { if (find != _types.end()) {
return find->second; return find->second;
} }
auto type = _mainModule->GetTypeInfoByDecl(decl.c_str()); auto type = _mainModule->GetTypeInfoByDecl(decl.c_str());
if (type == nullptr) { if (type == nullptr) {
_types.insert({decl, nullptr}); _types.insert({name, nullptr});
return nullptr; return nullptr;
} }
auto typeinfo = new AngelScriptTypeInfo(name, type); auto typeinfo = new AngelScriptTypeInfo(name, type);
_types.insert({decl, typeinfo}); _types.insert({name, typeinfo});
return typeinfo; return typeinfo;
} }
void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param) { void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param) {
@ -120,9 +120,9 @@ static constexpr const char* GetCategoryNamespace(ScriptCategory category) {
} }
} }
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const std::string& scriptName) { CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const ConstString& scriptName) {
std::stringstream decl; std::stringstream decl;
decl << GetCategoryNamespace(category) << "::" << scriptName; decl << GetCategoryNamespace(category) << "::" << scriptName.c_str();
auto typeInfo = GetTypeInfo(scriptName, decl.str()); auto typeInfo = GetTypeInfo(scriptName, decl.str());
if (typeInfo == nullptr) if (typeInfo == nullptr)
return nullptr; return nullptr;

View File

@ -17,11 +17,11 @@ private:
asIScriptModule* _mainModule = nullptr; asIScriptModule* _mainModule = nullptr;
ContextPool* _contextPool = nullptr; ContextPool* _contextPool = nullptr;
CScriptBuilder _builder; CScriptBuilder _builder;
std::unordered_map<std::string, AngelScriptTypeInfo*> _types; std::unordered_map<ConstString, AngelScriptTypeInfo*> _types;
static void MessageCallback(const asSMessageInfo* msg, void* param); static void MessageCallback(const asSMessageInfo* msg, void* param);
static void Print(const std::string& str) { std::cout << str << std::endl; } static void Print(const std::string& str) { std::cout << str << std::endl; }
AngelScriptTypeInfo* GetTypeInfo(const std::string& name, const std::string& decl); AngelScriptTypeInfo* GetTypeInfo(const ConstString& name, const std::string& decl);
void RegisterTypes(); void RegisterTypes();
@ -40,6 +40,6 @@ public:
void FinalizeModule(); void FinalizeModule();
CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const std::string& scriptName) override; CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const ConstString& scriptName) override;
}; };
#endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP #endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP

View File

@ -21,7 +21,7 @@ public:
~AngelScriptScript() override { _obj->Release(); } ~AngelScriptScript() override { _obj->Release(); }
[[nodiscard]] const std::string& GetName() const override { return _type->GetName(); } [[nodiscard]] const ConstString& GetName() const override { return _type->GetName(); }
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) { asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) {
auto func = _type->GetFunction(name); auto func = _type->GetFunction(name);
@ -51,7 +51,7 @@ public:
if (scriptResult != asEXECUTION_FINISHED) { \ if (scriptResult != asEXECUTION_FINISHED) { \
if (scriptResult == asEXECUTION_EXCEPTION) { \ if (scriptResult == asEXECUTION_EXCEPTION) { \
std::stringstream err; \ std::stringstream err; \
err << "Script exception in script '" << GetName() << "', line " << ctx->GetExceptionLineNumber() \ err << "Script exception in script '" << GetName().c_str() << "', line " << ctx->GetExceptionLineNumber() \
<< ". Message: '" << ctx->GetExceptionString() << "'."; \ << ". Message: '" << ctx->GetExceptionString() << "'."; \
throw CreatureException(err.str()); \ throw CreatureException(err.str()); \
} \ } \

View File

@ -2,17 +2,20 @@
#define PKMNLIB_ANGELSCRIPTTYPEINFO_HPP #define PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT #define ANGELSCRIPT_DLL_LIBRARY_IMPORT
#include <Arbutils/ConstString.hpp>
#include <CreatureLib/Core/Exceptions/CreatureException.hpp> #include <CreatureLib/Core/Exceptions/CreatureException.hpp>
#include <angelscript.h> #include <angelscript.h>
#include <cstring> #include <cstring>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
using ConstString = Arbutils::CaseInsensitiveConstString;
class AngelScriptTypeInfo { class AngelScriptTypeInfo {
private: private:
asITypeInfo* _type = nullptr; asITypeInfo* _type = nullptr;
std::unordered_map<std::string, asIScriptFunction*> _functions; std::unordered_map<std::string, asIScriptFunction*> _functions;
std::string _name; ConstString _name;
struct FunctionInfo { struct FunctionInfo {
bool Exists = false; bool Exists = false;
@ -31,7 +34,7 @@ private:
} }
public: public:
explicit AngelScriptTypeInfo(std::string name, asITypeInfo* type) : _type(type), _name(std::move(name)) {} explicit AngelScriptTypeInfo(const ConstString& name, asITypeInfo* type) : _type(type), _name(name) {}
~AngelScriptTypeInfo() { ~AngelScriptTypeInfo() {
for (const auto& f : _functions) { for (const auto& f : _functions) {
f.second->Release(); f.second->Release();
@ -39,7 +42,7 @@ public:
_functions.clear(); _functions.clear();
} }
const std::string& GetName() const{ const ConstString& GetName() const{
return _name; return _name;
} }

View File

@ -62,10 +62,10 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(
"Battle", "void AddVolatile(const string &in name) const", "Battle", "void AddVolatile(const string &in name) const",
asMETHODPR(CreatureLib::Battling::Battle, AddVolatileScript, (const std::string&), void), asCALL_THISCALL); asMETHODPR(CreatureLib::Battling::Battle, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(
"Battle", "void RemoveVolatile(const string &in name) const", "Battle", "void RemoveVolatile(const string &in name) const",
asMETHODPR(CreatureLib::Battling::Battle, RemoveVolatileScript, (const std::string&), void), asCALL_THISCALL); asMETHODPR(CreatureLib::Battling::Battle, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
} }

View File

@ -179,10 +179,10 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(
"Pokemon", "void AddVolatile(const string &in name) const", "Pokemon", "void AddVolatile(const string &in name) const",
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const std::string&), void), asCALL_THISCALL); asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(
"Pokemon", "void RemoveVolatile(const string &in name) const", "Pokemon", "void RemoveVolatile(const string &in name) const",
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const std::string&), void), asCALL_THISCALL); asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
} }

View File

@ -14,9 +14,9 @@ TEST_CASE("Able to build, destroy and insert library", "library") {
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme(
"default", 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100));
delete lib; delete lib;
} }
@ -27,9 +27,9 @@ TEST_CASE("Able to insert and retrieve from library", "library") {
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme(
"default", 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100));
auto val = lib->Get("foo"_cnc); auto val = lib->Get("foo"_cnc);
REQUIRE(val->GetName() == "foo"); REQUIRE(val->GetName() == "foo");

View File

@ -5,9 +5,10 @@
TEST_CASE("Able to create and destroy species", "library") { TEST_CASE("Able to create and destroy species", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
delete species; delete species;
} }
@ -15,9 +16,10 @@ TEST_CASE("Able to create and destroy species", "library") {
TEST_CASE("Able to get default forme", "library") { TEST_CASE("Able to get default forme", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
auto forme = species->GetDefaultForme(); auto forme = species->GetDefaultForme();
@ -29,9 +31,10 @@ TEST_CASE("Able to get default forme", "library") {
TEST_CASE("Able to get default forme name", "library") { TEST_CASE("Able to get default forme name", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
auto forme = species->GetDefaultForme(); auto forme = species->GetDefaultForme();
@ -44,9 +47,10 @@ TEST_CASE("Able to get default forme name", "library") {
TEST_CASE("Able to get species name", "library") { TEST_CASE("Able to get species name", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
REQUIRE(species->GetName() == "foo"); REQUIRE(species->GetName() == "foo");
@ -57,9 +61,10 @@ TEST_CASE("Able to get species name", "library") {
TEST_CASE("Able to get species id", "library") { TEST_CASE("Able to get species id", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
REQUIRE(species->GetId() == 1); REQUIRE(species->GetId() == 1);
@ -70,9 +75,10 @@ TEST_CASE("Able to get species id", "library") {
TEST_CASE("Able to get species gender ratio", "library") { TEST_CASE("Able to get species gender ratio", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
REQUIRE(species->GetGenderRate() == 0.5f); REQUIRE(species->GetGenderRate() == 0.5f);
@ -83,9 +89,10 @@ TEST_CASE("Able to get species gender ratio", "library") {
TEST_CASE("Able to get species growth rate", "library") { TEST_CASE("Able to get species growth rate", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
REQUIRE(species->GetGrowthRate() == "testGrowthRate"); REQUIRE(species->GetGrowthRate() == "testGrowthRate");
@ -96,9 +103,10 @@ TEST_CASE("Able to get species growth rate", "library") {
TEST_CASE("Able to get species capture rate", "library") { TEST_CASE("Able to get species capture rate", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
REQUIRE(species->GetCaptureRate() == 100); REQUIRE(species->GetCaptureRate() == 100);
@ -109,9 +117,10 @@ TEST_CASE("Able to get species capture rate", "library") {
TEST_CASE("Able to get species base happiness", "library") { TEST_CASE("Able to get species base happiness", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
REQUIRE(species->GetBaseHappiness() == 100); REQUIRE(species->GetBaseHappiness() == 100);
@ -122,15 +131,17 @@ TEST_CASE("Able to get species base happiness", "library") {
TEST_CASE("Able to set and get evolution", "library") { TEST_CASE("Able to set and get evolution", "library") {
auto species = new PkmnLib::Library::PokemonSpecies( auto species = new PkmnLib::Library::PokemonSpecies(
1, "foo"_cnc, 1, "foo"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
auto species2 = new PkmnLib::Library::PokemonSpecies( auto species2 = new PkmnLib::Library::PokemonSpecies(
2, "bar"_cnc, 2, "bar"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
"default", 1.0f, 1.0f, 100, {0}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"}, {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100);
species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2)); species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2));
@ -145,5 +156,4 @@ TEST_CASE("Able to set and get evolution", "library") {
delete species2; delete species2;
} }
#endif #endif

View File

@ -75,7 +75,7 @@ static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* m
return _resolverCache; return _resolverCache;
} }
static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* scriptName) { static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ConstString& scriptName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, scriptName); auto s = lib->LoadScript(ScriptCategory::Creature, scriptName);
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
@ -84,14 +84,14 @@ static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, c
TEST_CASE("Invoke non-implemented script function") { TEST_CASE("Invoke non-implemented script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "blankScript"); auto script = GetScript(mainLib, "blankScript"_cnc);
script->Stack(); script->Stack();
delete script; delete script;
} }
TEST_CASE("Invoke Stack script function") { TEST_CASE("Invoke Stack script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "stackScript"); auto script = GetScript(mainLib, "stackScript"_cnc);
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
script->Stack(); script->Stack();
@ -108,7 +108,7 @@ TEST_CASE("Invoke Stack script function") {
TEST_CASE("Invoke OnRemove script function") { TEST_CASE("Invoke OnRemove script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "onRemoveScript"); auto script = GetScript(mainLib, "onRemoveScript"_cnc);
script->OnRemove(); script->OnRemove();
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();
@ -124,7 +124,7 @@ TEST_CASE("Invoke OnRemove script function") {
TEST_CASE("Invoke Stack script function with implementation in base class") { TEST_CASE("Invoke Stack script function with implementation in base class") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "doubleInheritanceScript"); auto script = GetScript(mainLib, "doubleInheritanceScript"_cnc);
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
script->Stack(); script->Stack();
@ -141,7 +141,7 @@ TEST_CASE("Invoke Stack script function with implementation in base class") {
TEST_CASE("Invoke preventAttackScript script function") { TEST_CASE("Invoke preventAttackScript script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "preventAttackScript"); auto script = GetScript(mainLib, "preventAttackScript"_cnc);
bool b = false; bool b = false;
script->PreventAttack(nullptr, &b); script->PreventAttack(nullptr, &b);
REQUIRE(b); REQUIRE(b);
@ -151,7 +151,7 @@ TEST_CASE("Invoke preventAttackScript script function") {
TEST_CASE("Invoke StopBeforeAttack script function") { TEST_CASE("Invoke StopBeforeAttack script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "stopBeforeAttackScript"); auto script = GetScript(mainLib, "stopBeforeAttackScript"_cnc);
bool b = false; bool b = false;
script->StopBeforeAttack(nullptr, &b); script->StopBeforeAttack(nullptr, &b);
REQUIRE(b); REQUIRE(b);
@ -161,7 +161,7 @@ TEST_CASE("Invoke StopBeforeAttack script function") {
TEST_CASE("Invoke OnBeforeAttack script function") { TEST_CASE("Invoke OnBeforeAttack script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "OnBeforeAttackScript"); auto script = GetScript(mainLib, "OnBeforeAttackScript"_cnc);
script->OnBeforeAttack(nullptr); script->OnBeforeAttack(nullptr);
@ -177,7 +177,7 @@ TEST_CASE("Invoke OnBeforeAttack script function") {
TEST_CASE("Invoke FailIncomingAttack script function") { TEST_CASE("Invoke FailIncomingAttack script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "FailIncomingAttackScript"); auto script = GetScript(mainLib, "FailIncomingAttackScript"_cnc);
bool b = false; bool b = false;
script->FailIncomingAttack(nullptr, nullptr, &b); script->FailIncomingAttack(nullptr, nullptr, &b);
REQUIRE(b); REQUIRE(b);
@ -187,7 +187,7 @@ TEST_CASE("Invoke FailIncomingAttack script function") {
TEST_CASE("Invoke OnAttackMiss script function") { TEST_CASE("Invoke OnAttackMiss script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "OnAttackMissScript"); auto script = GetScript(mainLib, "OnAttackMissScript"_cnc);
script->OnAttackMiss(nullptr, nullptr); script->OnAttackMiss(nullptr, nullptr);
@ -203,7 +203,7 @@ TEST_CASE("Invoke OnAttackMiss script function") {
TEST_CASE("Invoke ChangeAttackType script function") { TEST_CASE("Invoke ChangeAttackType script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "ChangeAttackTypeScript"); auto script = GetScript(mainLib, "ChangeAttackTypeScript"_cnc);
uint8_t b = 0; uint8_t b = 0;
script->ChangeAttackType(nullptr, nullptr, 0, &b); script->ChangeAttackType(nullptr, nullptr, 0, &b);
REQUIRE(b == 1); REQUIRE(b == 1);
@ -213,7 +213,7 @@ TEST_CASE("Invoke ChangeAttackType script function") {
TEST_CASE("Invoke OnStatusMove script function") { TEST_CASE("Invoke OnStatusMove script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "OnStatusMoveScript"); auto script = GetScript(mainLib, "OnStatusMoveScript"_cnc);
script->OnStatusMove(nullptr, nullptr, 0); script->OnStatusMove(nullptr, nullptr, 0);
@ -229,7 +229,7 @@ TEST_CASE("Invoke OnStatusMove script function") {
TEST_CASE("Invoke PreventSecondaryEffects script function") { TEST_CASE("Invoke PreventSecondaryEffects script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "PreventSecondaryEffectsScript"); auto script = GetScript(mainLib, "PreventSecondaryEffectsScript"_cnc);
bool b = false; bool b = false;
script->PreventSecondaryEffects(nullptr, nullptr, 0, &b); script->PreventSecondaryEffects(nullptr, nullptr, 0, &b);
REQUIRE(b); REQUIRE(b);
@ -239,7 +239,7 @@ TEST_CASE("Invoke PreventSecondaryEffects script function") {
TEST_CASE("Invoke OnSecondaryEffect script function") { TEST_CASE("Invoke OnSecondaryEffect script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "OnSecondaryEffectScript"); auto script = GetScript(mainLib, "OnSecondaryEffectScript"_cnc);
script->OnSecondaryEffect(nullptr, nullptr, 0); script->OnSecondaryEffect(nullptr, nullptr, 0);
@ -255,7 +255,7 @@ TEST_CASE("Invoke OnSecondaryEffect script function") {
TEST_CASE("Invoke OnAfterHits script function") { TEST_CASE("Invoke OnAfterHits script function") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "OnAfterHitsScript"); auto script = GetScript(mainLib, "OnAfterHitsScript"_cnc);
script->OnAfterHits(nullptr, nullptr); script->OnAfterHits(nullptr, nullptr);
@ -271,7 +271,7 @@ TEST_CASE("Invoke OnAfterHits script function") {
TEST_CASE("Handle script exceptions.") { TEST_CASE("Handle script exceptions.") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "throwScript"); auto script = GetScript(mainLib, "throwScript"_cnc);
bool b = false; bool b = false;
bool hasThrown = false; bool hasThrown = false;
try{ try{

View File

@ -40,7 +40,7 @@ TEST_CASE("Build script resolver, then create object") {
lib->CreateScript("testScript1" , _scripts["testScript1"]); lib->CreateScript("testScript1" , _scripts["testScript1"]);
lib->FinalizeModule(); lib->FinalizeModule();
auto obj = lib->LoadScript(ScriptCategory::Creature, "testScript1"); auto obj = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
delete obj; delete obj;
delete lib; delete lib;
@ -53,7 +53,7 @@ TEST_CASE("Build script resolver, create object, invoke addition method") {
lib->FinalizeModule(); lib->FinalizeModule();
auto obj = auto obj =
dynamic_cast<AngelScriptScript*>(lib->LoadScript(ScriptCategory::Creature, "testScript1")); dynamic_cast<AngelScriptScript*>(lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc));
auto ctxPool = obj->GetContextPool(); auto ctxPool = obj->GetContextPool();
auto ctx = ctxPool->RequestContext(); auto ctx = ctxPool->RequestContext();

View File

@ -53,7 +53,7 @@ static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* m
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"); auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext(); auto ctx = ctxPool->RequestContext();

View File

@ -43,7 +43,7 @@ static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* m
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"); auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext(); auto ctx = ctxPool->RequestContext();

View File

@ -39,7 +39,7 @@ static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* m
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"); auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext(); auto ctx = ctxPool->RequestContext();

View File

@ -43,7 +43,7 @@ static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* m
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"); auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext(); auto ctx = ctxPool->RequestContext();

View File

@ -41,7 +41,7 @@ static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* m
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"); auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext(); auto ctx = ctxPool->RequestContext();

View File

@ -42,7 +42,7 @@ static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* m
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"); auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext(); auto ctx = ctxPool->RequestContext();

View File

@ -8,33 +8,33 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
1, "testSpecies"_cnc, 1, "testSpecies"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme(
"default", 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100));
lib->Insert("testSpecies2"_cnc, lib->Insert("testSpecies2"_cnc,
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
2, "testSpecies2"_cnc, 2, "testSpecies2"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme(
"default", 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100));
lib->Insert("statTestSpecies1"_cnc, lib->Insert("statTestSpecies1"_cnc,
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
3, "statTestSpecies1"_cnc, 3, "statTestSpecies1"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme(
"default", 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100));
lib->Insert("testSpecies3"_cnc, lib->Insert("testSpecies3"_cnc,
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
2, "testSpecies3"_cnc, 2, "testSpecies3"_cnc,
new PkmnLib::Library::PokemonForme( new PkmnLib::Library::PokemonForme(
"default", 1.0f, 1.0f, 100, {0, 4}, "default"_cnc, 1.0f, 1.0f, 100, {0, 4},
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"}, CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100));
return lib; return lib;