2021-03-07 16:09:30 +00:00
|
|
|
#ifdef TESTS_BUILD
|
2022-02-11 11:17:27 +00:00
|
|
|
#include <doctest.h>
|
2021-03-07 16:09:30 +00:00
|
|
|
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
|
|
|
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
|
|
|
#include "../TestLibrary/TestLibrary.hpp"
|
|
|
|
|
|
|
|
#define AS_CLASS(name, contents) \
|
|
|
|
{ #name, "namespace Pokemon{ [ItemUse effect=" #name "] class " #name " : ItemUseScript { " contents "}}" }
|
|
|
|
|
|
|
|
static std::unordered_map<const char*, const char*> _scripts = std::unordered_map<const char*, const char*>{
|
|
|
|
AS_CLASS(blankClass, R"(
|
|
|
|
)"),
|
|
|
|
|
|
|
|
AS_CLASS(isItemUsable, R"(
|
|
|
|
bool IsItemUsable() override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)"),
|
|
|
|
|
|
|
|
AS_CLASS(isPokemonUseItem, R"(
|
|
|
|
bool IsPokemonUseItem() override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)"),
|
|
|
|
};
|
|
|
|
|
|
|
|
static AngelScriptResolver* _resolverCache = nullptr;
|
|
|
|
static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib) {
|
2021-03-07 17:20:42 +00:00
|
|
|
if (_resolverCache != nullptr) {
|
|
|
|
delete _resolverCache;
|
|
|
|
}
|
2021-03-07 16:09:30 +00:00
|
|
|
_resolverCache = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
|
|
|
_resolverCache->Initialize(mainLib);
|
|
|
|
for (auto kv : _scripts) {
|
|
|
|
_resolverCache->CreateScript(kv.first, kv.second);
|
|
|
|
}
|
|
|
|
_resolverCache->FinalizeModule();
|
|
|
|
return _resolverCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AngelScriptItemUseScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& name) {
|
|
|
|
auto lib = GetScriptResolver(mainLib);
|
|
|
|
auto item = CreatureLib::Library::Item(name, CreatureLib::Library::ItemCategory::MiscItem,
|
|
|
|
CreatureLib::Library::BattleItemCategory::None, 0,
|
2022-02-19 13:04:43 +00:00
|
|
|
new CreatureLib::Library::SecondaryEffect(100, name, {}), nullptr, {});
|
2021-03-07 16:09:30 +00:00
|
|
|
|
|
|
|
auto s = lib->LoadItemScript(&item);
|
|
|
|
auto script = dynamic_cast<AngelScriptItemUseScript*>(s);
|
|
|
|
REQUIRE(script != nullptr);
|
|
|
|
return script;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Invoke isItemUsable item use script function on empty class") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
|
|
|
|
auto script = GetScript(mainLib, "blankClass"_cnc);
|
|
|
|
REQUIRE(script != nullptr);
|
|
|
|
REQUIRE_FALSE(script->IsItemUsable());
|
|
|
|
}
|
|
|
|
TEST_CASE("Invoke isItemUsable item use script function") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
|
|
|
|
auto script = GetScript(mainLib, "isItemUsable"_cnc);
|
|
|
|
REQUIRE(script != nullptr);
|
|
|
|
REQUIRE(script->IsItemUsable());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Invoke isPokemonUseItem item use script function on empty class") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
|
|
|
|
auto script = GetScript(mainLib, "blankClass"_cnc);
|
|
|
|
REQUIRE(script != nullptr);
|
|
|
|
REQUIRE_FALSE(script->IsCreatureUseItem());
|
|
|
|
}
|
|
|
|
TEST_CASE("Invoke isPokemonUseItem item use script function") {
|
|
|
|
auto mainLib = TestLibrary::GetLibrary();
|
|
|
|
|
|
|
|
auto script = GetScript(mainLib, "isPokemonUseItem"_cnc);
|
|
|
|
REQUIRE(script != nullptr);
|
|
|
|
REQUIRE(script->IsCreatureUseItem());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|