Rework AngelScript effect names to be not based on script names, but on attributes instead.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
72ef9599ed
commit
149b0f08f6
|
@ -7,7 +7,7 @@ namespace PkmnLib::Battling {
|
||||||
class CreatePokemon {
|
class CreatePokemon {
|
||||||
private:
|
private:
|
||||||
const BattleLibrary* _library;
|
const BattleLibrary* _library;
|
||||||
Arbutils::CaseInsensitiveConstString _species;
|
Arbutils::CaseInsensitiveConstString _species = ""_cnc;
|
||||||
Arbutils::CaseInsensitiveConstString _forme = "default"_cnc;
|
Arbutils::CaseInsensitiveConstString _forme = "default"_cnc;
|
||||||
uint8_t _level;
|
uint8_t _level;
|
||||||
std::string _nickname = "";
|
std::string _nickname = "";
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace PkmnLib::Library {
|
||||||
inline uint8_t GetBaseHappiness() const { return _baseHappiness; }
|
inline uint8_t GetBaseHappiness() const { return _baseHappiness; }
|
||||||
|
|
||||||
inline const PokemonForme* GetDefaultForme() const {
|
inline const PokemonForme* GetDefaultForme() const {
|
||||||
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant("default"_cnc));
|
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant("default"_cnc.GetHash()));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool HasForme(const Arbutils::CaseInsensitiveConstString& key) const { return HasVariant(key); }
|
inline bool HasForme(const Arbutils::CaseInsensitiveConstString& key) const { return HasVariant(key); }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "AngelScripResolver.hpp"
|
#include "AngelScripResolver.hpp"
|
||||||
#include <CreatureLib/Battling/Models/Creature.hpp>
|
#include <CreatureLib/Battling/Models/Creature.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <regex>
|
||||||
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||||
#include "../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
#include "../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
||||||
#include "../../../extern/angelscript_addons/scripthelper/scripthelper.h"
|
#include "../../../extern/angelscript_addons/scripthelper/scripthelper.h"
|
||||||
|
@ -24,6 +25,10 @@ CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateS
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg) {
|
void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg) {
|
||||||
|
for (auto scriptCategory : ScriptCategoryHelper::GetValues()) {
|
||||||
|
_typeDatabase.Insert(scriptCategory, {});
|
||||||
|
}
|
||||||
|
|
||||||
auto library = (PkmnLib::Battling::BattleLibrary*)arg;
|
auto library = (PkmnLib::Battling::BattleLibrary*)arg;
|
||||||
_engine = asCreateScriptEngine();
|
_engine = asCreateScriptEngine();
|
||||||
|
|
||||||
|
@ -87,20 +92,6 @@ void AngelScripResolver::RegisterTypes() {
|
||||||
BasicScriptClass::Register(_engine);
|
BasicScriptClass::Register(_engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const ConstString& name, const std::string& decl) {
|
|
||||||
auto find = _types.find(name);
|
|
||||||
if (find != _types.end()) {
|
|
||||||
return find->second;
|
|
||||||
}
|
|
||||||
auto type = _mainModule->GetTypeInfoByDecl(decl.c_str());
|
|
||||||
if (type == nullptr) {
|
|
||||||
_types.insert({name, nullptr});
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
auto typeinfo = new AngelScriptTypeInfo(name, type);
|
|
||||||
_types.insert({name, typeinfo});
|
|
||||||
return typeinfo;
|
|
||||||
}
|
|
||||||
void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param) {
|
void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param) {
|
||||||
const char* type = "ERR ";
|
const char* type = "ERR ";
|
||||||
if (msg->type == asMSGTYPE_WARNING)
|
if (msg->type == asMSGTYPE_WARNING)
|
||||||
|
@ -110,33 +101,78 @@ void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param)
|
||||||
printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
|
printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr const char* GetCategoryNamespace(ScriptCategory category) {
|
|
||||||
switch (category) {
|
|
||||||
case ScriptCategory::Attack: return "Moves";
|
|
||||||
case ScriptCategory::Talent: return "Abilities";
|
|
||||||
case ScriptCategory::Status: return "Status";
|
|
||||||
case ScriptCategory::Creature: return "Pokemon";
|
|
||||||
case ScriptCategory::Battle: return "Battle";
|
|
||||||
case ScriptCategory::Side: return "Side";
|
|
||||||
default: throw CreatureException("Unknown script category");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const ConstString& scriptName) {
|
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const ConstString& scriptName) {
|
||||||
std::stringstream decl;
|
Dictionary<uint32_t, AngelScriptTypeInfo*> innerDb;
|
||||||
decl << GetCategoryNamespace(category) << "::" << scriptName.c_str();
|
if (!_typeDatabase.TryGet(category, innerDb)) {
|
||||||
auto typeInfo = GetTypeInfo(scriptName, decl.str());
|
_typeDatabase.Insert(category, innerDb);
|
||||||
if (typeInfo == nullptr)
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
AngelScriptTypeInfo* t;
|
||||||
|
if (!innerDb.TryGet(scriptName, t)) {
|
||||||
|
innerDb.Insert(scriptName, nullptr);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (t == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
auto ctx = _contextPool->RequestContext();
|
auto ctx = _contextPool->RequestContext();
|
||||||
auto obj = typeInfo->Instantiate(ctx);
|
auto obj = t->Instantiate(ctx);
|
||||||
_contextPool->ReturnContextToPool(ctx);
|
_contextPool->ReturnContextToPool(ctx);
|
||||||
return new AngelScriptScript(typeInfo, obj, _contextPool);
|
return new AngelScriptScript(t, obj, _contextPool);
|
||||||
}
|
}
|
||||||
void AngelScripResolver::FinalizeModule() {
|
void AngelScripResolver::FinalizeModule() {
|
||||||
int r = _builder.BuildModule();
|
int r = _builder.BuildModule();
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
throw CreatureException("Building Script Module failed.");
|
throw CreatureException("Building Script Module failed.");
|
||||||
|
int count = _mainModule->GetObjectTypeCount();
|
||||||
|
std::regex metadataMatcher("^\\s*(\\w+)([\\w\\s=]*)$", std::regex_constants::icase);
|
||||||
|
std::regex variableMatcher("\\s*(\\w+)=(\\w+)", std::regex_constants::icase);
|
||||||
|
std::smatch base_match;
|
||||||
|
|
||||||
|
for (int n = 0; n < count; n++) {
|
||||||
|
auto typeInfo = _mainModule->GetObjectTypeByIndex(n);
|
||||||
|
auto metadata = _builder.GetMetadataForType(typeInfo->GetTypeId());
|
||||||
|
for (int m = 0; m < metadata.size(); m++) {
|
||||||
|
auto data = metadata[m];
|
||||||
|
if (std::regex_match(data, base_match, metadataMatcher)) {
|
||||||
|
auto metadataKind = base_match[1].str();
|
||||||
|
auto metadataVariables = base_match[2].str();
|
||||||
|
if (!std::regex_match(metadataVariables, base_match, variableMatcher)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ConstString effectName;
|
||||||
|
for (size_t variableIndex = 1; variableIndex < base_match.size(); variableIndex += 2) {
|
||||||
|
if (base_match[variableIndex] == "effect") {
|
||||||
|
auto val = base_match[variableIndex + 1].str();
|
||||||
|
effectName = ConstString(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (effectName.Empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadataKind == "Move") {
|
||||||
|
_typeDatabase[ScriptCategory::Attack].Insert(effectName,
|
||||||
|
new AngelScriptTypeInfo(effectName, typeInfo));
|
||||||
|
} else if (metadataKind == "Pokemon") {
|
||||||
|
_typeDatabase[ScriptCategory::Creature].Insert(effectName,
|
||||||
|
new AngelScriptTypeInfo(effectName, typeInfo));
|
||||||
|
} else if (metadataKind == "Ability") {
|
||||||
|
_typeDatabase[ScriptCategory::Talent].Insert(effectName,
|
||||||
|
new AngelScriptTypeInfo(effectName, typeInfo));
|
||||||
|
} else if (metadataKind == "Status") {
|
||||||
|
_typeDatabase[ScriptCategory::Status].Insert(effectName,
|
||||||
|
new AngelScriptTypeInfo(effectName, typeInfo));
|
||||||
|
} else if (metadataKind == "Battle") {
|
||||||
|
_typeDatabase[ScriptCategory::Battle].Insert(effectName,
|
||||||
|
new AngelScriptTypeInfo(effectName, typeInfo));
|
||||||
|
} else if (metadataKind == "Side") {
|
||||||
|
_typeDatabase[ScriptCategory::Side].Insert(effectName,
|
||||||
|
new AngelScriptTypeInfo(effectName, typeInfo));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void AngelScripResolver::CreateScript(const char* name, const char* script) {
|
void AngelScripResolver::CreateScript(const char* name, const char* script) {
|
||||||
_builder.AddSectionFromMemory(name, script);
|
_builder.AddSectionFromMemory(name, script);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "AngelScriptScript.hpp"
|
#include "AngelScriptScript.hpp"
|
||||||
#include "AngelScriptTypeInfo.hpp"
|
#include "AngelScriptTypeInfo.hpp"
|
||||||
|
using namespace Arbutils::Collections;
|
||||||
|
|
||||||
class AngelScripResolver : public CreatureLib::Battling::ScriptResolver {
|
class AngelScripResolver : public CreatureLib::Battling::ScriptResolver {
|
||||||
private:
|
private:
|
||||||
|
@ -17,21 +18,21 @@ private:
|
||||||
asIScriptModule* _mainModule = nullptr;
|
asIScriptModule* _mainModule = nullptr;
|
||||||
ContextPool* _contextPool = nullptr;
|
ContextPool* _contextPool = nullptr;
|
||||||
CScriptBuilder _builder;
|
CScriptBuilder _builder;
|
||||||
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 ConstString& name, const std::string& decl);
|
Dictionary<ScriptCategory, Dictionary<uint32_t, AngelScriptTypeInfo*>> _typeDatabase;
|
||||||
|
|
||||||
void RegisterTypes();
|
void RegisterTypes();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~AngelScripResolver() override {
|
~AngelScripResolver() override {
|
||||||
delete _contextPool;
|
delete _contextPool;
|
||||||
for (const auto& type : _types) {
|
for (const auto& category : _typeDatabase) {
|
||||||
|
for (const auto& type : category.second){
|
||||||
delete type.second;
|
delete type.second;
|
||||||
}
|
}
|
||||||
_types.clear();
|
}
|
||||||
_engine->ShutDownAndRelease();
|
_engine->ShutDownAndRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||||
class AngelScriptTypeInfo {
|
class AngelScriptTypeInfo {
|
||||||
private:
|
private:
|
||||||
asITypeInfo* _type = nullptr;
|
asITypeInfo* _type = nullptr;
|
||||||
Arbutils::Collections::Dictionary<ConstString, asIScriptFunction*> _functions;
|
Arbutils::Collections::Dictionary<uint32_t, asIScriptFunction*> _functions;
|
||||||
ConstString _name;
|
ConstString _name;
|
||||||
|
|
||||||
struct FunctionInfo {
|
struct FunctionInfo {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "../TestLibrary/TestLibrary.hpp"
|
#include "../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
||||||
#define AS_CLASS(name, contents) \
|
#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*>{
|
static std::unordered_map<const char*, const char*> _scripts = std::unordered_map<const char*, const char*>{
|
||||||
AS_CLASS(blankScript, ),
|
AS_CLASS(blankScript, ),
|
||||||
|
@ -20,6 +20,7 @@ class doubleInheritanceScriptBase : PkmnScript {
|
||||||
|
|
||||||
int GetValue(){ return value; }
|
int GetValue(){ return value; }
|
||||||
}
|
}
|
||||||
|
[Pokemon effect=doubleInheritanceScript]
|
||||||
class doubleInheritanceScript : doubleInheritanceScriptBase {}
|
class doubleInheritanceScript : doubleInheritanceScriptBase {}
|
||||||
)"},
|
)"},
|
||||||
AS_CLASS(preventAttackScript,
|
AS_CLASS(preventAttackScript,
|
||||||
|
@ -78,12 +79,16 @@ static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, c
|
||||||
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);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
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"_cnc);
|
auto script = GetScript(mainLib, "blankScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
script->Stack();
|
script->Stack();
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +96,8 @@ TEST_CASE("Invoke non-implemented script function") {
|
||||||
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"_cnc);
|
auto script = GetScript(mainLib, "stackScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
for (int i = 1; i <= 10; i++) {
|
for (int i = 1; i <= 10; i++) {
|
||||||
script->Stack();
|
script->Stack();
|
||||||
|
|
||||||
|
@ -108,6 +115,8 @@ 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"_cnc);
|
auto script = GetScript(mainLib, "onRemoveScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
script->OnRemove();
|
script->OnRemove();
|
||||||
|
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
|
@ -160,6 +169,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"_cnc);
|
auto script = GetScript(mainLib, "OnBeforeAttackScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
script->OnBeforeAttack(nullptr);
|
script->OnBeforeAttack(nullptr);
|
||||||
|
|
||||||
|
@ -176,6 +186,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"_cnc);
|
auto script = GetScript(mainLib, "FailIncomingAttackScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
bool b = false;
|
bool b = false;
|
||||||
script->FailIncomingAttack(nullptr, nullptr, &b);
|
script->FailIncomingAttack(nullptr, nullptr, &b);
|
||||||
REQUIRE(b);
|
REQUIRE(b);
|
||||||
|
@ -186,6 +197,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"_cnc);
|
auto script = GetScript(mainLib, "OnAttackMissScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
script->OnAttackMiss(nullptr, nullptr);
|
script->OnAttackMiss(nullptr, nullptr);
|
||||||
|
|
||||||
|
@ -202,6 +214,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"_cnc);
|
auto script = GetScript(mainLib, "ChangeAttackTypeScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
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);
|
||||||
|
@ -254,6 +267,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"_cnc);
|
auto script = GetScript(mainLib, "OnAfterHitsScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
script->OnAfterHits(nullptr, nullptr);
|
script->OnAfterHits(nullptr, nullptr);
|
||||||
|
|
||||||
|
@ -272,9 +286,21 @@ void TryException(AngelScriptScript* script) {
|
||||||
script->PreventAttack(nullptr, &b);
|
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.") {
|
TEST_CASE("Handle script exceptions.") {
|
||||||
auto mainLib = TestLibrary::GetLibrary();
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
auto script = GetScript(mainLib, "throwScript"_cnc);
|
auto script = GetScript(mainLib, "throwScript"_cnc);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
CHECK_THROWS_WITH(
|
CHECK_THROWS_WITH(
|
||||||
TryException(script),
|
TryException(script),
|
||||||
Catch::Matchers::Equals("Script exception in script 'throwScript', line 1. Message: 'test exception'."));
|
Catch::Matchers::Equals("Script exception in script 'throwScript', line 1. Message: 'test exception'."));
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
static std::unordered_map<const char*, const char*> _scripts =
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
namespace Pokemon{
|
namespace Pokemon{
|
||||||
|
[Pokemon effect=testScript1]
|
||||||
class testScript1 {
|
class testScript1 {
|
||||||
int add(int a, int b) {
|
int add(int a, int b) {
|
||||||
return a + b;
|
return a + b;
|
||||||
|
@ -54,6 +55,7 @@ TEST_CASE("Build script resolver, create object, invoke addition method") {
|
||||||
|
|
||||||
auto obj =
|
auto obj =
|
||||||
dynamic_cast<AngelScriptScript*>(lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc));
|
dynamic_cast<AngelScriptScript*>(lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc));
|
||||||
|
REQUIRE(obj != nullptr);
|
||||||
auto ctxPool = obj->GetContextPool();
|
auto ctxPool = obj->GetContextPool();
|
||||||
auto ctx = ctxPool->RequestContext();
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
static std::unordered_map<const char*, const char*> _scripts =
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
namespace Pokemon{
|
namespace Pokemon{
|
||||||
|
[Pokemon effect=testScript1]
|
||||||
class testScript1 {
|
class testScript1 {
|
||||||
bool testSpecies(Pokemon@ p, const Species@ species){ return p.Species is species; }
|
bool testSpecies(Pokemon@ p, const Species@ species){ return p.Species is species; }
|
||||||
bool testForme(Pokemon@ p, const Forme@ forme){ return p.Forme is forme; }
|
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 lib = GetScriptResolver(mainLib);
|
||||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
auto ctx = ctxPool->RequestContext();
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
static std::unordered_map<const char*, const char*> _scripts =
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
namespace Pokemon{
|
namespace Pokemon{
|
||||||
|
[Pokemon effect=testScript1]
|
||||||
class testScript1 {
|
class testScript1 {
|
||||||
bool testName(const Forme@ s, const constString &in name){ return s.Name == name; }
|
bool testName(const Forme@ s, const constString &in name){ return s.Name == name; }
|
||||||
bool testWeight(const Forme@ s, float weight){ return s.Weight == weight; }
|
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 lib = GetScriptResolver(mainLib);
|
||||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
auto ctx = ctxPool->RequestContext();
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
static std::unordered_map<const char*, const char*> _scripts =
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
namespace Pokemon{
|
namespace Pokemon{
|
||||||
|
[Pokemon effect=testScript1]
|
||||||
class testScript1 {
|
class testScript1 {
|
||||||
bool testName(const Item@ i, const constString &in name){ return i.Name == name; }
|
bool testName(const Item@ i, const constString &in name){ return i.Name == name; }
|
||||||
bool testCategory(const Item@ i, ItemCategory category){ return i.Category == category; }
|
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 lib = GetScriptResolver(mainLib);
|
||||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
auto ctx = ctxPool->RequestContext();
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
static std::unordered_map<const char*, const char*> _scripts =
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
namespace Pokemon{
|
namespace Pokemon{
|
||||||
|
[Pokemon effect=testScript1]
|
||||||
class testScript1 {
|
class testScript1 {
|
||||||
bool testName(const MoveData@ s, const constString &in name){ return s.Name == name; }
|
bool testName(const MoveData@ s, const constString &in name){ return s.Name == name; }
|
||||||
bool testType(const MoveData@ s, uint8 type){ return s.Type == type; }
|
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 lib = GetScriptResolver(mainLib);
|
||||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
auto ctx = ctxPool->RequestContext();
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
static std::unordered_map<const char*, const char*> _scripts =
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
namespace Pokemon{
|
namespace Pokemon{
|
||||||
|
[Pokemon effect=testScript1]
|
||||||
class testScript1 {
|
class testScript1 {
|
||||||
bool testName(const Species@ s, const constString &in name){ return s.Name == name; }
|
bool testName(const Species@ s, const constString &in name){ return s.Name == name; }
|
||||||
bool testId(const Species@ s, uint16 id){ return s.Id == id; }
|
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 lib = GetScriptResolver(mainLib);
|
||||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
auto ctx = ctxPool->RequestContext();
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
static std::unordered_map<const char*, const char*> _scripts =
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
namespace Pokemon{
|
namespace Pokemon{
|
||||||
|
[Pokemon effect=testScript1]
|
||||||
class testScript1 {
|
class testScript1 {
|
||||||
bool testMaximumLevel(const StaticLibrary@ s, uint8 level){ return s.Settings.MaximalLevel == level; }
|
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 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 lib = GetScriptResolver(mainLib);
|
||||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
|
REQUIRE(script != nullptr);
|
||||||
|
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
auto ctx = ctxPool->RequestContext();
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,11 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
|
||||||
}
|
}
|
||||||
PkmnLib::Library::MoveLibrary* TestLibrary::BuildMoveLibrary() {
|
PkmnLib::Library::MoveLibrary* TestLibrary::BuildMoveLibrary() {
|
||||||
auto lib = new PkmnLib::Library::MoveLibrary();
|
auto lib = new PkmnLib::Library::MoveLibrary();
|
||||||
lib->Insert("testMove"_cnc,
|
lib->Insert("testMove"_cnc.GetHash(),
|
||||||
new PkmnLib::Library::MoveData("testMove"_cnc, 0, PkmnLib::Library::MoveCategory::Physical, 50, 100, 20,
|
new PkmnLib::Library::MoveData("testMove"_cnc, 0, PkmnLib::Library::MoveCategory::Physical, 50, 100, 20,
|
||||||
CreatureLib::Library::AttackTarget::Adjacent, 0,
|
CreatureLib::Library::AttackTarget::Adjacent, 0,
|
||||||
CreatureLib::Library::SecondaryEffect(), {}));
|
CreatureLib::Library::SecondaryEffect(), {}));
|
||||||
lib->Insert("testMove2"_cnc,
|
lib->Insert("testMove2"_cnc.GetHash(),
|
||||||
new PkmnLib::Library::MoveData("testMove2"_cnc, 0, PkmnLib::Library::MoveCategory::Special, 30, 100, 10,
|
new PkmnLib::Library::MoveData("testMove2"_cnc, 0, PkmnLib::Library::MoveCategory::Special, 30, 100, 10,
|
||||||
CreatureLib::Library::AttackTarget::Adjacent, 0,
|
CreatureLib::Library::AttackTarget::Adjacent, 0,
|
||||||
CreatureLib::Library::SecondaryEffect(), {}));
|
CreatureLib::Library::SecondaryEffect(), {}));
|
||||||
|
|
|
@ -24,8 +24,7 @@ public:
|
||||||
auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
|
auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
|
||||||
auto lib = new PkmnLib::Battling::BattleLibrary(
|
auto lib = new PkmnLib::Battling::BattleLibrary(
|
||||||
BuildStaticLibrary(), statCalc, new PkmnLib::Battling::DamageLibrary(),
|
BuildStaticLibrary(), statCalc, new PkmnLib::Battling::DamageLibrary(),
|
||||||
new CreatureLib::Battling::ExperienceLibrary(), scriptResolver,
|
new CreatureLib::Battling::ExperienceLibrary(), scriptResolver, new CreatureLib::Battling::MiscLibrary());
|
||||||
new CreatureLib::Battling::MiscLibrary());
|
|
||||||
scriptResolver->Initialize(lib);
|
scriptResolver->Initialize(lib);
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +44,7 @@ public:
|
||||||
static CreatureLib::Library::GrowthRateLibrary* BuildGrowthRateLibrary() {
|
static CreatureLib::Library::GrowthRateLibrary* BuildGrowthRateLibrary() {
|
||||||
auto lib = new CreatureLib::Library::GrowthRateLibrary();
|
auto lib = new CreatureLib::Library::GrowthRateLibrary();
|
||||||
lib->AddGrowthRate(
|
lib->AddGrowthRate(
|
||||||
"testGrowthRate"_cnc,
|
"testGrowthRate"_cnc.GetHash(),
|
||||||
new CreatureLib::Library::LookupGrowthRate(
|
new CreatureLib::Library::LookupGrowthRate(
|
||||||
{0, 15, 52, 122, 237, 406, 637, 942, 1326, 1800, 2369, 3041, 3822,
|
{0, 15, 52, 122, 237, 406, 637, 942, 1326, 1800, 2369, 3041, 3822,
|
||||||
4719, 5737, 6881, 8155, 9564, 11111, 12800, 14632, 16610, 18737, 21012, 23437, 26012,
|
4719, 5737, 6881, 8155, 9564, 11111, 12800, 14632, 16610, 18737, 21012, 23437, 26012,
|
||||||
|
@ -67,7 +66,8 @@ public:
|
||||||
auto lib = new PkmnLib::Library::NatureLibrary();
|
auto lib = new PkmnLib::Library::NatureLibrary();
|
||||||
lib->LoadNature("neutralNature", PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
lib->LoadNature("neutralNature", PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
||||||
PkmnLib::Library::Statistic::PhysicalDefense, 1, 1));
|
PkmnLib::Library::Statistic::PhysicalDefense, 1, 1));
|
||||||
lib->LoadNature("buffsAttackNerfsSpeed", PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
lib->LoadNature("buffsAttackNerfsSpeed",
|
||||||
|
PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
||||||
PkmnLib::Library::Statistic::Speed, 1.1, 0.9));
|
PkmnLib::Library::Statistic::Speed, 1.1, 0.9));
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue