PkmnLib/src/ScriptResolving/AngelScript/AngelScriptEvolutionScript.hpp

48 lines
1.8 KiB
C++

#ifndef PKMNLIB_ANGELSCRIPTEVOLUTIONSCRIPT_HPP
#define PKMNLIB_ANGELSCRIPTEVOLUTIONSCRIPT_HPP
#include <angelscript.h>
#include "../../Battling/Pokemon/Pokemon.hpp"
#include "../../Library/Evolutions/EvolutionData.hpp"
class AngelScriptResolver;
class AngelScriptEvolutionScript final : public PkmnLib::Battling::EvolutionScript {
asIScriptObject* non_null _scriptObject;
AngelScriptResolver* non_null _resolver;
struct FunctionInfo {
bool Exists = false;
asIScriptFunction* nullable Function = nullptr;
};
#define EVO_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
FunctionInfo Initialize(const std::string& decl) {
auto val = _scriptObject->GetObjectType()->GetMethodByDecl(decl.c_str(), false);
if (val == nullptr) {
return FunctionInfo{.Exists = false, .Function = nullptr};
}
return FunctionInfo{.Exists = true, .Function = val};
}
EVO_SCRIPT_HOOK_FUNCTION(DoesEvolveFromLevelUp,
"void DoesEvolveFromLevelUp(bool& out, const EvolutionData@ evoData,"
"const Pokemon@ pokemon)");
public:
AngelScriptEvolutionScript(asIScriptObject* non_null scriptObject, AngelScriptResolver* non_null resolver)
: _scriptObject(scriptObject), _resolver(resolver) {}
~AngelScriptEvolutionScript() {
if (_scriptObject != nullptr) {
_scriptObject->Release();
}
}
void DoesEvolveFromLevelUp(const ArbUt::BorrowedPtr<const PkmnLib::Library::EvolutionData>& evolution,
const ArbUt::BorrowedPtr<const PkmnLib::Battling::Pokemon>& pokemon,
bool* non_null out) const override;
};
#endif // PKMNLIB_ANGELSCRIPTEVOLUTIONSCRIPT_HPP