Files
PkmnLib/src/ScriptResolving/AngelScript/AngelScripResolver.hpp
Deukhoofd 6032610de6
All checks were successful
continuous-integration/drone/push Build is passing
Add script category to script creation function in AngelScript.
2020-02-13 13:59:07 +01:00

50 lines
1.6 KiB
C++

#ifndef PKMNLIB_ANGELSCRIPRESOLVER_HPP
#define PKMNLIB_ANGELSCRIPRESOLVER_HPP
#include <CreatureLib/Battling/ScriptHandling/ScriptResolver.hpp>
#include "../../Battling/Library/BattleLibrary.hpp"
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
#include <angelscript.h>
#include <iostream>
#include "AngelScriptScript.hpp"
#include "AngelScriptTypeInfo.hpp"
class AngelScripResolver : public CreatureLib::Battling::ScriptResolver {
private:
asIScriptEngine* _engine = nullptr;
asIScriptModule* _mainModule = nullptr;
ContextPool* _contextPool = nullptr;
const char* (*_loadFunc)(ScriptCategory category, const char*) = nullptr;
std::unordered_map<std::string, AngelScriptTypeInfo*> _types;
static void MessageCallback(const asSMessageInfo* msg, void* param);
static void Print(const std::string& str) { std::cout << str << std::endl; }
AngelScriptTypeInfo* GetTypeInfo(const std::string& name);
void RegisterTypes();
public:
~AngelScripResolver() override {
delete _contextPool;
for (const auto& type : _types) {
delete type.second;
}
_types.clear();
_engine->ShutDownAndRelease();
}
void Initialize(CreatureLib::Battling::BattleLibrary* library) override;
void SetCreateFunction(const char* (*loadFunc)(ScriptCategory category, const char* scriptName)) {
_loadFunc = loadFunc;
}
void CreateScript(ScriptCategory category, const char* scriptName);
void FinalizeModule();
CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const std::string& scriptName) override;
};
#endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP