Rework AngelScript effect names to be not based on script names, but on attributes instead.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-04-10 14:57:20 +02:00
parent 72ef9599ed
commit 149b0f08f6
15 changed files with 131 additions and 48 deletions

View File

@@ -5,7 +5,7 @@
#include "../TestLibrary/TestLibrary.hpp"
#define AS_CLASS(name, contents) \
{ #name, "namespace Pokemon{ class " #name " : PkmnScript { " contents "}}" }
{ #name, "namespace Pokemon{ [Pokemon effect=" #name "] class " #name " : PkmnScript { " contents "}}" }
static std::unordered_map<const char*, const char*> _scripts = std::unordered_map<const char*, const char*>{
AS_CLASS(blankScript, ),
@@ -20,6 +20,7 @@ class doubleInheritanceScriptBase : PkmnScript {
int GetValue(){ return value; }
}
[Pokemon effect=doubleInheritanceScript]
class doubleInheritanceScript : doubleInheritanceScriptBase {}
)"},
AS_CLASS(preventAttackScript,
@@ -78,12 +79,16 @@ static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, c
auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, scriptName);
auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr);
return script;
}
TEST_CASE("Invoke non-implemented script function") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "blankScript"_cnc);
REQUIRE(script != nullptr);
script->Stack();
delete script;
}
@@ -91,6 +96,8 @@ TEST_CASE("Invoke non-implemented script function") {
TEST_CASE("Invoke Stack script function") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "stackScript"_cnc);
REQUIRE(script != nullptr);
for (int i = 1; i <= 10; i++) {
script->Stack();
@@ -108,6 +115,8 @@ TEST_CASE("Invoke Stack script function") {
TEST_CASE("Invoke OnRemove script function") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "onRemoveScript"_cnc);
REQUIRE(script != nullptr);
script->OnRemove();
auto ctxPool = script->GetContextPool();
@@ -160,6 +169,7 @@ TEST_CASE("Invoke StopBeforeAttack script function") {
TEST_CASE("Invoke OnBeforeAttack script function") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "OnBeforeAttackScript"_cnc);
REQUIRE(script != nullptr);
script->OnBeforeAttack(nullptr);
@@ -176,6 +186,7 @@ TEST_CASE("Invoke OnBeforeAttack script function") {
TEST_CASE("Invoke FailIncomingAttack script function") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "FailIncomingAttackScript"_cnc);
REQUIRE(script != nullptr);
bool b = false;
script->FailIncomingAttack(nullptr, nullptr, &b);
REQUIRE(b);
@@ -186,6 +197,7 @@ TEST_CASE("Invoke FailIncomingAttack script function") {
TEST_CASE("Invoke OnAttackMiss script function") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "OnAttackMissScript"_cnc);
REQUIRE(script != nullptr);
script->OnAttackMiss(nullptr, nullptr);
@@ -202,6 +214,7 @@ TEST_CASE("Invoke OnAttackMiss script function") {
TEST_CASE("Invoke ChangeAttackType script function") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "ChangeAttackTypeScript"_cnc);
REQUIRE(script != nullptr);
uint8_t b = 0;
script->ChangeAttackType(nullptr, nullptr, 0, &b);
REQUIRE(b == 1);
@@ -254,6 +267,7 @@ TEST_CASE("Invoke OnSecondaryEffect script function") {
TEST_CASE("Invoke OnAfterHits script function") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "OnAfterHitsScript"_cnc);
REQUIRE(script != nullptr);
script->OnAfterHits(nullptr, nullptr);
@@ -272,9 +286,21 @@ void TryException(AngelScriptScript* script) {
script->PreventAttack(nullptr, &b);
}
TEST_CASE("Get script name.") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "throwScript"_cnc);
REQUIRE(script != nullptr);
INFO(script->GetName().c_str());
INFO(script->GetName().std_str());
CHECK(strcmp(script->GetName().c_str(), "throwScript") == 0);
delete script;
}
TEST_CASE("Handle script exceptions.") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "throwScript"_cnc);
REQUIRE(script != nullptr);
CHECK_THROWS_WITH(
TryException(script),
Catch::Matchers::Equals("Script exception in script 'throwScript', line 1. Message: 'test exception'."));

View File

@@ -6,6 +6,7 @@
static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
[Pokemon effect=testScript1]
class testScript1 {
int add(int a, int b) {
return a + b;
@@ -54,6 +55,7 @@ TEST_CASE("Build script resolver, create object, invoke addition method") {
auto obj =
dynamic_cast<AngelScriptScript*>(lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc));
REQUIRE(obj != nullptr);
auto ctxPool = obj->GetContextPool();
auto ctx = ctxPool->RequestContext();

View File

@@ -7,6 +7,7 @@
static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
[Pokemon effect=testScript1]
class testScript1 {
bool testSpecies(Pokemon@ p, const Species@ species){ return p.Species is species; }
bool testForme(Pokemon@ p, const Forme@ forme){ return p.Forme is forme; }
@@ -55,6 +56,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr);
auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext();

View File

@@ -6,6 +6,7 @@
static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
[Pokemon effect=testScript1]
class testScript1 {
bool testName(const Forme@ s, const constString &in name){ return s.Name == name; }
bool testWeight(const Forme@ s, float weight){ return s.Weight == weight; }
@@ -45,6 +46,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr);
auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext();

View File

@@ -6,6 +6,7 @@
static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
[Pokemon effect=testScript1]
class testScript1 {
bool testName(const Item@ i, const constString &in name){ return i.Name == name; }
bool testCategory(const Item@ i, ItemCategory category){ return i.Category == category; }
@@ -41,6 +42,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr);
auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext();

View File

@@ -6,6 +6,7 @@
static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
[Pokemon effect=testScript1]
class testScript1 {
bool testName(const MoveData@ s, const constString &in name){ return s.Name == name; }
bool testType(const MoveData@ s, uint8 type){ return s.Type == type; }
@@ -45,6 +46,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr);
auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext();

View File

@@ -6,6 +6,7 @@
static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
[Pokemon effect=testScript1]
class testScript1 {
bool testName(const Species@ s, const constString &in name){ return s.Name == name; }
bool testId(const Species@ s, uint16 id){ return s.Id == id; }
@@ -43,6 +44,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr);
auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext();

View File

@@ -6,6 +6,7 @@
static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
[Pokemon effect=testScript1]
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; }
@@ -44,6 +45,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr);
auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext();