Reorganized files
This commit is contained in:
103
src/ScriptResolving/AngelScript/AngelScripResolver.cpp
Normal file
103
src/ScriptResolving/AngelScript/AngelScripResolver.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "AngelScripResolver.hpp"
|
||||
#define AS_USE_ACCESSORS
|
||||
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||
#undef AS_USE_ACCESSORS
|
||||
#include "../../../extern/angelscript_addons/scripthelper/scripthelper.h"
|
||||
#include "../../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h"
|
||||
#include "TypeRegistry/Battling/RegisterExecutingAttack.hpp"
|
||||
#include "TypeRegistry/Battling/RegisterPokemonClass.hpp"
|
||||
#include "TypeRegistry/Library/RegisterGrowthRateTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterItemTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterMoveTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterSpeciesTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterStaticLibraryTypes.hpp"
|
||||
#include "TypeRegistry/Library/RegisterTypeLibrary.hpp"
|
||||
|
||||
CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver() {
|
||||
return new AngelScripResolver();
|
||||
}
|
||||
|
||||
void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* library) {
|
||||
_engine = asCreateScriptEngine();
|
||||
|
||||
int32_t r = _engine->SetMessageCallback(asFUNCTION(MessageCallback), nullptr, asCALL_CDECL);
|
||||
if (r < 0)
|
||||
throw CreatureException("Registering message callback failed.");
|
||||
|
||||
_engine->SetEngineProperty(asEP_DISALLOW_EMPTY_LIST_ELEMENTS, true);
|
||||
_engine->SetEngineProperty(asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE, true);
|
||||
_engine->SetEngineProperty(asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT, true);
|
||||
_engine->SetEngineProperty(asEP_AUTO_GARBAGE_COLLECT, false);
|
||||
_engine->SetEngineProperty(asEP_REQUIRE_ENUM_SCOPE, true);
|
||||
|
||||
RegisterStdString(_engine);
|
||||
|
||||
// Register Script Array type
|
||||
RegisterScriptArray(_engine, true);
|
||||
|
||||
r = _engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(Print), asCALL_CDECL);
|
||||
if (r < 0)
|
||||
throw CreatureException("Registering print function failed.");
|
||||
|
||||
RegisterTypes();
|
||||
RegisterExceptionRoutines(_engine);
|
||||
|
||||
_mainModule = _engine->GetModule("pkmn", asGM_ALWAYS_CREATE);
|
||||
|
||||
_contextPool = new ContextPool(_engine);
|
||||
}
|
||||
|
||||
void AngelScripResolver::RegisterTypes() {
|
||||
// Register static library types
|
||||
RegisterSpeciesTypes::Register(_engine);
|
||||
RegisterItemTypes::Register(_engine);
|
||||
RegisterMoveTypes::Register(_engine);
|
||||
RegisterGrowthRateTypes::Register(_engine);
|
||||
RegisterTypeLibrary::Register(_engine);
|
||||
RegisterStaticLibraryTypes::Register(_engine);
|
||||
|
||||
// Register battle types
|
||||
RegisterPokemonClass::Register(_engine);
|
||||
RegisterExecutingAttack::Register(_engine);
|
||||
}
|
||||
|
||||
AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const std::string& name) {
|
||||
auto find = _types.find(name);
|
||||
if (find != _types.end()) {
|
||||
return find->second;
|
||||
}
|
||||
auto type = _mainModule->GetTypeInfoByDecl(name.c_str());
|
||||
if (type == nullptr) {
|
||||
_types.insert({name, nullptr});
|
||||
return nullptr;
|
||||
}
|
||||
auto typeinfo = new AngelScriptTypeInfo(type);
|
||||
_types.insert({name, typeinfo});
|
||||
return typeinfo;
|
||||
}
|
||||
void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param) {
|
||||
const char* type = "ERR ";
|
||||
if (msg->type == asMSGTYPE_WARNING)
|
||||
type = "WARN";
|
||||
else if (msg->type == asMSGTYPE_INFORMATION)
|
||||
type = "INFO";
|
||||
printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
|
||||
}
|
||||
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const std::string& scriptName) {
|
||||
auto typeInfo = GetTypeInfo(scriptName);
|
||||
if (typeInfo == nullptr)
|
||||
return nullptr;
|
||||
auto ctx = _contextPool->RequestContext();
|
||||
auto obj = typeInfo->Instantiate(ctx);
|
||||
_contextPool->ReturnContextToPool(ctx);
|
||||
return new AngelScriptScript(scriptName, typeInfo, obj, _contextPool);
|
||||
}
|
||||
void AngelScripResolver::FinalizeModule() {
|
||||
int r = _mainModule->Build();
|
||||
if (r < 0)
|
||||
throw CreatureException("Building Script Module failed.");
|
||||
}
|
||||
void AngelScripResolver::CreateScript(const char* scriptName) {
|
||||
auto scriptString = _loadFunc(scriptName);
|
||||
_mainModule->AddScriptSection(scriptName, scriptString);
|
||||
}
|
||||
47
src/ScriptResolving/AngelScript/AngelScripResolver.hpp
Normal file
47
src/ScriptResolving/AngelScript/AngelScripResolver.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
||||
#define PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
||||
|
||||
#include <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)(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)(const char* scriptName)) { _loadFunc = loadFunc; }
|
||||
|
||||
void CreateScript(const char* scriptName);
|
||||
|
||||
void FinalizeModule();
|
||||
|
||||
CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const std::string& scriptName) override;
|
||||
};
|
||||
#endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
||||
1
src/ScriptResolving/AngelScript/AngelScriptScript.cpp
Normal file
1
src/ScriptResolving/AngelScript/AngelScriptScript.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "AngelScriptScript.hpp"
|
||||
51
src/ScriptResolving/AngelScript/AngelScriptScript.hpp
Normal file
51
src/ScriptResolving/AngelScript/AngelScriptScript.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
||||
#define PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
||||
#include <Battling/ScriptHandling/Script.hpp>
|
||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||
#include <angelscript.h>
|
||||
#include "AngelScriptTypeInfo.hpp"
|
||||
#include "ContextPool.hpp"
|
||||
|
||||
class AngelScriptScript : public CreatureLib::Battling::Script {
|
||||
private:
|
||||
AngelScriptTypeInfo* _type = nullptr;
|
||||
ContextPool* _ctxPool = nullptr;
|
||||
|
||||
asIScriptObject* _obj = nullptr;
|
||||
|
||||
public:
|
||||
AngelScriptScript(const std::string& name, AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool)
|
||||
: CreatureLib::Battling::Script(name), _type(type), _ctxPool(ctxPool), _obj(obj) {}
|
||||
|
||||
~AngelScriptScript() override { _obj->Release(); }
|
||||
|
||||
void InvokeMethod(const char* name) {
|
||||
auto func = _type->GetFunction(name);
|
||||
if (func == nullptr)
|
||||
return;
|
||||
auto ctx = _ctxPool->RequestContext();
|
||||
ctx->Prepare(func);
|
||||
ctx->SetObject(_obj);
|
||||
auto result = ctx->Execute();
|
||||
if (result != asEXECUTION_FINISHED) {
|
||||
if (result == asEXECUTION_EXCEPTION) {
|
||||
throw CreatureException(ctx->GetExceptionString());
|
||||
}
|
||||
throw CreatureException("Function failed.");
|
||||
}
|
||||
_ctxPool->ReturnContextToPool(ctx);
|
||||
}
|
||||
|
||||
asIScriptObject* GetScriptObject() { return _obj; }
|
||||
|
||||
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) {
|
||||
auto func = _type->GetFunction(name);
|
||||
ctx->Prepare(func);
|
||||
ctx->SetObject(_obj);
|
||||
return func;
|
||||
}
|
||||
|
||||
ContextPool* GetContextPool() { return _ctxPool; }
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
||||
1
src/ScriptResolving/AngelScript/AngelScriptTypeInfo.cpp
Normal file
1
src/ScriptResolving/AngelScript/AngelScriptTypeInfo.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "AngelScriptTypeInfo.hpp"
|
||||
50
src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp
Normal file
50
src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|
||||
#define PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|
||||
|
||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||
#include <angelscript.h>
|
||||
#include <unordered_map>
|
||||
#include <Core/Exceptions/CreatureException.hpp>
|
||||
|
||||
class AngelScriptTypeInfo {
|
||||
private:
|
||||
asITypeInfo* _type = nullptr;
|
||||
std::unordered_map<std::string, asIScriptFunction*> _functions;
|
||||
|
||||
public:
|
||||
explicit AngelScriptTypeInfo(asITypeInfo* type) : _type(type){}
|
||||
~AngelScriptTypeInfo(){
|
||||
for (const auto& f: _functions){
|
||||
f.second->Release();
|
||||
}
|
||||
_functions.clear();
|
||||
}
|
||||
|
||||
asIScriptFunction* GetFunction(const std::string& functionName){
|
||||
auto find = _functions.find(functionName);
|
||||
if (find != _functions.end()){
|
||||
return find->second;
|
||||
}
|
||||
auto func = _type->GetMethodByName(functionName.c_str());
|
||||
if (func != nullptr){
|
||||
func->AddRef();
|
||||
}
|
||||
_functions.insert({functionName, func});
|
||||
return func;
|
||||
}
|
||||
|
||||
asIScriptObject* Instantiate(asIScriptContext* ctx){
|
||||
auto factory = _type->GetFactoryByIndex(0);
|
||||
ctx->Prepare(factory);
|
||||
auto result = ctx->Execute();
|
||||
if (result != asEXECUTION_FINISHED){
|
||||
throw CreatureException("Instantiation failed.");
|
||||
}
|
||||
asIScriptObject* obj = *(asIScriptObject**)ctx->GetAddressOfReturnValue();
|
||||
obj->AddRef();
|
||||
return obj;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|
||||
1
src/ScriptResolving/AngelScript/ContextPool.cpp
Normal file
1
src/ScriptResolving/AngelScript/ContextPool.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "ContextPool.hpp"
|
||||
37
src/ScriptResolving/AngelScript/ContextPool.hpp
Normal file
37
src/ScriptResolving/AngelScript/ContextPool.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef PKMNLIB_CONTEXTPOOL_HPP
|
||||
#define PKMNLIB_CONTEXTPOOL_HPP
|
||||
|
||||
#include <angelscript.h>
|
||||
#include <vector>
|
||||
|
||||
class ContextPool {
|
||||
std::vector<asIScriptContext*> _pool;
|
||||
asIScriptEngine* _engine;
|
||||
|
||||
public:
|
||||
ContextPool(asIScriptEngine* engine) : _engine(engine) {}
|
||||
|
||||
~ContextPool(){
|
||||
for (auto ctx: _pool){
|
||||
ctx->Release();
|
||||
}
|
||||
}
|
||||
|
||||
asIScriptContext* RequestContext() {
|
||||
// Get a context from the pool, or create a new
|
||||
asIScriptContext* ctx = nullptr;
|
||||
if (!_pool.empty()) {
|
||||
ctx = *_pool.rbegin();
|
||||
_pool.pop_back();
|
||||
} else
|
||||
ctx = _engine->CreateContext();
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void ReturnContextToPool(asIScriptContext* ctx) {
|
||||
_pool.push_back(ctx);
|
||||
ctx->Unprepare();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_CONTEXTPOOL_HPP
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "RegisterBattleLibrary.hpp"
|
||||
#include <cassert>
|
||||
#include "../../../../Battling/Library/DamageLibrary.hpp"
|
||||
|
||||
void RegisterBattleLibrary::Register(asIScriptEngine* engine) {
|
||||
RegisterDamageLibrary(engine);
|
||||
}
|
||||
void RegisterBattleLibrary::RegisterDamageLibrary(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("DamageLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("DamageLibrary", "int GetDamage() const",
|
||||
asMETHOD(PkmnLib::Battling::DamageLibrary, GetDamage), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef PKMNLIB_REGISTERBATTLELIBRARY_HPP
|
||||
#define PKMNLIB_REGISTERBATTLELIBRARY_HPP
|
||||
|
||||
#include <angelscript.h>
|
||||
class RegisterBattleLibrary {
|
||||
static void RegisterDamageLibrary(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERBATTLELIBRARY_HPP
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "RegisterExecutingAttack.hpp"
|
||||
#include <Battling/Models/ExecutingAttack.hpp>
|
||||
#include <cassert>
|
||||
|
||||
void RegisterExecutingAttack::Register(asIScriptEngine* engine) {
|
||||
RegisterHitData(engine);
|
||||
RegisterTargetData(engine);
|
||||
RegisterExecutingAttackType(engine);
|
||||
}
|
||||
void RegisterExecutingAttack::RegisterHitData(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("HitData", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("HitData", "bool get_IsCritical() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, IsCritical),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("HitData", "uint8 get_BasePower() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetBasePower),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("HitData", "float get_Effectiveness() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetEffectiveness),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("HitData", "float get_Damage() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetDamage),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("HitData", "uint8 get_Type() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetType),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
void RegisterExecutingAttack::RegisterTargetData(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("TargetData", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TargetData", "uint8 get_NumberOfHits() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack::TargetData, GetNumberOfHits),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TargetData", "bool get_IsHit() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack::TargetData, IsHit),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TargetData", "HitData@ GetHit(uint8 index) const",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack::TargetData, GetHit),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
}
|
||||
void RegisterExecutingAttack::RegisterExecutingAttackType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ExecutingMove", "TargetData& GetAttackDataForTarget(Pokemon@ pkmn) const",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetAttackDataForTarget),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetUser),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetAttack),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef PKMNLIB_REGISTEREXECUTINGATTACK_HPP
|
||||
#define PKMNLIB_REGISTEREXECUTINGATTACK_HPP
|
||||
|
||||
#include <angelscript.h>
|
||||
|
||||
class RegisterExecutingAttack {
|
||||
static void RegisterHitData(asIScriptEngine* engine);
|
||||
static void RegisterTargetData(asIScriptEngine* engine);
|
||||
static void RegisterExecutingAttackType(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTEREXECUTINGATTACK_HPP
|
||||
@@ -0,0 +1,143 @@
|
||||
#include "RegisterPokemonClass.hpp"
|
||||
#include <Battling/Models/LearnedAttack.hpp>
|
||||
#include <cassert>
|
||||
#include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
||||
|
||||
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
||||
#define ENUM__SIZE_WRAPPER(name, type, func) \
|
||||
int32_t name(type* obj) { return static_cast<int32_t>(obj->func()); }
|
||||
|
||||
void RegisterPokemonClass::Register(asIScriptEngine* engine) {
|
||||
RegisterDamageSource(engine);
|
||||
RegisterMoveLearnMethod(engine);
|
||||
RegisterLearnedAttack(engine);
|
||||
RegisterPokemonType(engine);
|
||||
}
|
||||
|
||||
void RegisterPokemonClass::RegisterDamageSource(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("DamageSource");
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("DamageSource", "AttackDamage",
|
||||
(int)CreatureLib::Battling::DamageSource::AttackDamage);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
void RegisterPokemonClass::RegisterMoveLearnMethod(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("MoveLearnMethod");
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("MoveLearnMethod", "Unknown", (int)CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("MoveLearnMethod", "Level", (int)CreatureLib::Battling::AttackLearnMethod::Level);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
ENUM__SIZE_WRAPPER(LearnedMove_LearnMethodWrapper, CreatureLib::Battling::LearnedAttack, GetLearnMethod)
|
||||
|
||||
void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("LearnedMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("LearnedMove", "const MoveData@ get_MoveData() const property",
|
||||
asMETHOD(CreatureLib::Battling::LearnedAttack, GetAttack), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_MaxUses() const property",
|
||||
asMETHOD(CreatureLib::Battling::LearnedAttack, GetMaxUses), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_RemainingUses() const property",
|
||||
asMETHOD(CreatureLib::Battling::LearnedAttack, GetRemainingUses), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("LearnedMove", "Gender get_LearnMethod() const property",
|
||||
asFUNCTION(LearnedMove_LearnMethodWrapper), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender)
|
||||
|
||||
CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) {
|
||||
asIScriptContext* ctx = asGetActiveContext();
|
||||
if (ctx) {
|
||||
asIScriptEngine* engine = ctx->GetEngine();
|
||||
asITypeInfo* t = engine->GetTypeInfoByDecl("array<uint8>");
|
||||
auto a = obj->GetTypes();
|
||||
CScriptArray* arr = CScriptArray::Create(t, a.size());
|
||||
for (size_t i = 0; i < a.size(); i++){
|
||||
arr->SetValue(i, &a[i]);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetSpecies), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetForme), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_Experience() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetExperience), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "Gender get_Gender() const property", asFUNCTION(Pkmn_GenderWrapper),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "bool get_Shiny() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetCurrentHealth), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const string& get_Nickname() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetNickname), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const string& get_ActiveAbility() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetActiveTalent), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint8[]@ GetTypes() const",
|
||||
asFUNCTION(GetTypes), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "void Damage(uint32 type, DamageSource source)",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, Damage), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ get_Moves() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetAttacks), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplaySpecies() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplaySpecies), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplayForme() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplayVariant), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetFlatStat(Statistic stat) const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetFlatStat), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetBoostedStat(Statistic stat) const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetBoostedStat), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetBaseStat(Statistic stat) const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetBaseStat), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "int8 GetStatBoost(Statistic stat) const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetStatBoost), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef PKMNLIB_REGISTERPOKEMONCLASS_HPP
|
||||
#define PKMNLIB_REGISTERPOKEMONCLASS_HPP
|
||||
|
||||
#include <angelscript.h>
|
||||
class RegisterPokemonClass {
|
||||
static void RegisterDamageSource(asIScriptEngine* engine);
|
||||
static void RegisterMoveLearnMethod(asIScriptEngine* engine);
|
||||
static void RegisterLearnedAttack(asIScriptEngine* engine);
|
||||
static void RegisterPokemonType(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERPOKEMONCLASS_HPP
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "RegisterGrowthRateTypes.hpp"
|
||||
#include <Library/GrowthRates/GrowthRate.hpp>
|
||||
#include <Library/GrowthRates/GrowthRateLibrary.hpp>
|
||||
#include <cassert>
|
||||
|
||||
void RegisterGrowthRateTypes::Register(asIScriptEngine* engine) {
|
||||
RegisterGrowthRateType(engine);
|
||||
RegisterGrowthRateLibrary(engine);
|
||||
}
|
||||
void RegisterGrowthRateTypes::RegisterGrowthRateType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("GrowthRate", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("GrowthRate", "uint8 CalculateLevel(uint experience) const",
|
||||
asMETHOD(CreatureLib::Library::GrowthRate, CalculateLevel), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("GrowthRate", "uint CalculateExperience(uint8 level) const",
|
||||
asMETHOD(CreatureLib::Library::GrowthRate, CalculateExperience), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
void RegisterGrowthRateTypes::RegisterGrowthRateLibrary(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("GrowthRateLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("GrowthRateLibrary", "uint8 CalculateLevel(const string &in growthRate, uint experience) const",
|
||||
asMETHOD(CreatureLib::Library::GrowthRateLibrary, CalculateLevel), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("GrowthRateLibrary", "uint CalculateExperience(const string &in growthRate, uint8 experience) const",
|
||||
asMETHOD(CreatureLib::Library::GrowthRateLibrary, CalculateExperience), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef PKMNLIB_REGISTERGROWTHRATETYPES_HPP
|
||||
#define PKMNLIB_REGISTERGROWTHRATETYPES_HPP
|
||||
#include <angelscript.h>
|
||||
|
||||
class RegisterGrowthRateTypes {
|
||||
static void RegisterGrowthRateType(asIScriptEngine* engine);
|
||||
static void RegisterGrowthRateLibrary(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERGROWTHRATETYPES_HPP
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "RegisterItemTypes.hpp"
|
||||
#include <cassert>
|
||||
#include "../../../../Library/Items/Item.hpp"
|
||||
#include "../../../../Library/Items/ItemLibrary.hpp"
|
||||
|
||||
void RegisterItemTypes::Register(asIScriptEngine* engine) {
|
||||
RegisterItemCategoryEnum(engine);
|
||||
RegisterBattleItemCategoryEnum(engine);
|
||||
RegisterItemType(engine);
|
||||
RegisterItemLibrary(engine);
|
||||
}
|
||||
|
||||
void RegisterItemTypes::RegisterItemCategoryEnum(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("ItemCategory");
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "Misc", (int)CreatureLib::Library::ItemCategory::MiscItem);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "Pokeball", (int)CreatureLib::Library::ItemCategory::CaptureDevice);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "Medicine", (int)CreatureLib::Library::ItemCategory::Medicine);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "Berry", (int)CreatureLib::Library::ItemCategory::Berry);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "TM", (int)CreatureLib::Library::ItemCategory::TM);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "VariantChanger", (int)CreatureLib::Library::ItemCategory::VariantChanger);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "KeyItem", (int)CreatureLib::Library::ItemCategory::KeyItem);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "Mail", (int)CreatureLib::Library::ItemCategory::Mail);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
void RegisterItemTypes::RegisterBattleItemCategoryEnum(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("BattleItemCategory");
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "None", (int)CreatureLib::Library::BattleItemCategory::None);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "Healing", (int)CreatureLib::Library::BattleItemCategory::Healing);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "StatusHealing", (int)CreatureLib::Library::BattleItemCategory::StatusHealing);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "CaptureDevice", (int)CreatureLib::Library::BattleItemCategory::CaptureDevice);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "Misc", (int)CreatureLib::Library::BattleItemCategory::MiscBattleItem);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
||||
#define ENUM__SIZE_WRAPPER(name, type, func) \
|
||||
int32_t name(type* obj) { return static_cast<int32_t>(obj->func()); }
|
||||
|
||||
ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::Item, GetCategory)
|
||||
ENUM__SIZE_WRAPPER(Move_BattleCategoryWrapper, PkmnLib::Library::Item, GetBattleCategory)
|
||||
|
||||
void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Item", "const string& get_Name() const property",
|
||||
asMETHOD(PkmnLib::Library::Item, GetName), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Item", "ItemCategory get_Category() const property",
|
||||
asFUNCTION(Move_CategoryWrapper), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Item", "BattleItemCategory get_BattleCategory() const property",
|
||||
asFUNCTION(Move_BattleCategoryWrapper), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Item", "int get_Price() const property",
|
||||
asMETHOD(PkmnLib::Library::Item, GetPrice), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Item", "bool HasFlag(const string &in flag) const",
|
||||
asMETHOD(PkmnLib::Library::Item, HasFlag), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
|
||||
}
|
||||
void RegisterItemTypes::RegisterItemLibrary(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("ItemLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ItemLibrary", "const Item@ GetItem(const string &in name) const",
|
||||
asMETHOD(PkmnLib::Library::ItemLibrary, GetItem), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef PKMNLIB_REGISTERITEMTYPES_HPP
|
||||
#define PKMNLIB_REGISTERITEMTYPES_HPP
|
||||
#include <angelscript.h>
|
||||
|
||||
class RegisterItemTypes {
|
||||
static void RegisterItemCategoryEnum(asIScriptEngine* engine);
|
||||
static void RegisterBattleItemCategoryEnum(asIScriptEngine* engine);
|
||||
static void RegisterItemType(asIScriptEngine* engine);
|
||||
static void RegisterItemLibrary(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERITEMTYPES_HPP
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "RegisterMoveTypes.hpp"
|
||||
#include <cassert>
|
||||
#include "../../../../Library/Moves/MoveData.hpp"
|
||||
#include "../../../../Library/Moves/MoveLibrary.hpp"
|
||||
|
||||
void RegisterMoveTypes::Register(asIScriptEngine* engine) {
|
||||
RegisterMoveCategory(engine);
|
||||
RegisterMoveTarget(engine);
|
||||
RegisterMoveType(engine);
|
||||
RegisterMoveLibrary(engine);
|
||||
}
|
||||
|
||||
#define REGISTER_ENUM_VALUE(asName, cName, valueName) \
|
||||
r = engine->RegisterEnumValue(#asName, #valueName, (int)cName::valueName); \
|
||||
assert(r >= 0);
|
||||
|
||||
void RegisterMoveTypes::RegisterMoveCategory(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("MoveCategory");
|
||||
assert(r >= 0);
|
||||
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Physical)
|
||||
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Special)
|
||||
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Status)
|
||||
}
|
||||
|
||||
void RegisterMoveTypes::RegisterMoveTarget(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("MoveTarget");
|
||||
assert(r >= 0);
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, Adjacent)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AdjacentAlly)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AdjacentAllySelf)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AdjacentOpponent)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, All)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AllAdjacent)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AllAdjacentOpponent)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AllAlly)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AllOpponent)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, Any)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, RandomOpponent)
|
||||
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, Self)
|
||||
}
|
||||
|
||||
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
||||
#define ENUM__SIZE_WRAPPER(name, type, func) \
|
||||
int32_t name(type* obj) { return static_cast<int32_t>(obj->func()); }
|
||||
|
||||
ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::MoveData, GetCategory)
|
||||
ENUM__SIZE_WRAPPER(Move_TargetWrapper, PkmnLib::Library::MoveData, GetTarget)
|
||||
|
||||
void RegisterMoveTypes::RegisterMoveType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("MoveData", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "const string& get_Name() const property",
|
||||
asMETHOD(PkmnLib::Library::MoveData, GetName), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Type() const property",
|
||||
asMETHOD(PkmnLib::Library::MoveData, GetType), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "MoveCategory get_Category() const property",
|
||||
asFUNCTION(Move_CategoryWrapper), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "uint8 get_BasePower() const property",
|
||||
asMETHOD(PkmnLib::Library::MoveData, GetBasePower), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Accuracy() const property",
|
||||
asMETHOD(PkmnLib::Library::MoveData, GetAccuracy), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "uint8 get_BaseUsages() const property",
|
||||
asMETHOD(PkmnLib::Library::MoveData, GetBaseUsages), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "MoveTarget get_Target() const property",
|
||||
asFUNCTION(Move_TargetWrapper), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property",
|
||||
asMETHOD(PkmnLib::Library::MoveData, GetPriority), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const string &in flag) const",
|
||||
asMETHOD(PkmnLib::Library::MoveData, HasFlag), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
void RegisterMoveTypes::RegisterMoveLibrary(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("MoveLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveLibrary", "const MoveData@ GetMove(const string &in name) const",
|
||||
asMETHOD(PkmnLib::Library::MoveLibrary, GetMove), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
#undef REGISTER_ENUM_VALUE
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef PKMNLIB_REGISTERMOVETYPES_HPP
|
||||
#define PKMNLIB_REGISTERMOVETYPES_HPP
|
||||
#include <angelscript.h>
|
||||
|
||||
class RegisterMoveTypes {
|
||||
static void RegisterMoveCategory(asIScriptEngine* engine);
|
||||
static void RegisterMoveTarget(asIScriptEngine* engine);
|
||||
static void RegisterMoveType(asIScriptEngine* engine);
|
||||
static void RegisterMoveLibrary(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERMOVETYPES_HPP
|
||||
@@ -0,0 +1,105 @@
|
||||
#include "RegisterSpeciesTypes.hpp"
|
||||
#include <cassert>
|
||||
#include "../../../../Library/Species/PokemonSpecies.hpp"
|
||||
#include "../../../../Library/Species/SpeciesLibrary.hpp"
|
||||
#include "../../../../Library/Statistic.hpp"
|
||||
|
||||
void RegisterSpeciesTypes::Register(asIScriptEngine* engine) {
|
||||
RegisterGenderEnum(engine);
|
||||
RegisterStatisticEnum(engine);
|
||||
RegisterFormeType(engine);
|
||||
RegisterSpeciesType(engine);
|
||||
RegisterSpeciesLibrary(engine);
|
||||
}
|
||||
|
||||
void RegisterSpeciesTypes::RegisterGenderEnum(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("Gender");
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Gender", "Male", (int)CreatureLib::Library::Gender::Male);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Gender", "Female", (int)CreatureLib::Library::Gender::Female);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Gender", "Genderless", (int)CreatureLib::Library::Gender::Genderless);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
void RegisterSpeciesTypes::RegisterStatisticEnum(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("Statistic");
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Statistic", "HP", PkmnLib::Library::Statistic::HealthPoints);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Statistic", "Attack", PkmnLib::Library::Statistic::PhysicalAttack);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Statistic", "Defense", PkmnLib::Library::Statistic::PhysicalDefense);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Statistic", "SpecialAttack", PkmnLib::Library::Statistic::SpecialAttack);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Statistic", "SpecialDefense", PkmnLib::Library::Statistic::SpecialDefense);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Statistic", "Speed", PkmnLib::Library::Statistic::Speed);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "const string& get_Name() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetName), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "uint16 get_Id() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetId), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "float get_GenderRate() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetGenderRate), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "uint8 get_CaptureRate() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetCaptureRate), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "Gender GetRandomGender() const",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetRandomGender), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "const Forme@ GetForme(string key) const",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetForme), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "const Forme@ GetDefaultForme() const",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetDefaultForme), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
|
||||
}
|
||||
void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Forme", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Forme", "const string& get_Name() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetName), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Forme", "float get_Weight() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetWeight), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Forme", "float get_Height() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetHeight), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Forme", "uint get_BaseExperience() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetBaseExperience), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Forme", "int get_TypeCount() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetTypeCount), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Forme", "uint8 GetType(int index) const",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetType), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Forme", "uint GetStatistic(Statistic stat) const",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetStatistic), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Forme", "const string& GetAbility(int index) const",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetTalent), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
}
|
||||
void RegisterSpeciesTypes::RegisterSpeciesLibrary(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("SpeciesLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SpeciesLibrary", "const Species@ GetSpecies(const string &in name) const",
|
||||
asMETHOD(PkmnLib::Library::SpeciesLibrary, GetPkmnSpecies), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef PKMNLIB_REGISTERSPECIESTYPES_HPP
|
||||
#define PKMNLIB_REGISTERSPECIESTYPES_HPP
|
||||
#include <angelscript.h>
|
||||
|
||||
class RegisterSpeciesTypes {
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
|
||||
private:
|
||||
static void RegisterGenderEnum(asIScriptEngine* engine);
|
||||
static void RegisterStatisticEnum(asIScriptEngine* engine);
|
||||
static void RegisterSpeciesType(asIScriptEngine* engine);
|
||||
static void RegisterFormeType(asIScriptEngine* engine);
|
||||
static void RegisterSpeciesLibrary(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERSPECIESTYPES_HPP
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "RegisterStaticLibraryTypes.hpp"
|
||||
#include <cassert>
|
||||
#include "../../../../Library/PokemonLibrary.hpp"
|
||||
|
||||
void RegisterStaticLibraryTypes::Register(asIScriptEngine* engine) {
|
||||
RegisterLibrarySettingsType(engine);
|
||||
RegisterLibraryType(engine);
|
||||
}
|
||||
|
||||
void RegisterStaticLibraryTypes::RegisterLibrarySettingsType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("LibrarySettings", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
r = engine->RegisterObjectMethod("LibrarySettings", "uint8 get_MaximalLevel() const property",
|
||||
asMETHOD(CreatureLib::Library::LibrarySettings, GetMaximalLevel), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("LibrarySettings", "uint8 get_MaximalMoves() const property",
|
||||
asMETHOD(CreatureLib::Library::LibrarySettings, GetMaximalMoves), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings@ get_Settings() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSettings), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSpeciesLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const MoveLibrary@ get_MoveLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetMoveLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const ItemLibrary@ get_ItemLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetItemLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const GrowthRateLibrary@ get_GrowthRateLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetGrowthRates), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetTypeLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
|
||||
#define PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
|
||||
|
||||
#include <angelscript.h>
|
||||
class RegisterStaticLibraryTypes {
|
||||
static void RegisterLibrarySettingsType(asIScriptEngine* engine);
|
||||
static void RegisterLibraryType(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "RegisterTypeLibrary.hpp"
|
||||
#include <Library/TypeLibrary.hpp>
|
||||
#include <cassert>
|
||||
|
||||
void RegisterTypeLibrary::Register(asIScriptEngine* engine) {
|
||||
RegisterTypeLibraryType(engine);
|
||||
}
|
||||
|
||||
void RegisterTypeLibrary::RegisterTypeLibraryType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("TypeLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TypeLibrary", "uint8 GetTypeId(const string &in name) const",
|
||||
asMETHOD(CreatureLib::Library::TypeLibrary, GetTypeId), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TypeLibrary", "float GetSingleEffectiveness(uint8 attacking, uint8 defensive) const",
|
||||
asMETHOD(CreatureLib::Library::TypeLibrary, GetSingleEffectiveness), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
//TODO: Register get full effectiveness method.
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef PKMNLIB_REGISTERTYPELIBRARY_HPP
|
||||
#define PKMNLIB_REGISTERTYPELIBRARY_HPP
|
||||
#include <angelscript.h>
|
||||
|
||||
class RegisterTypeLibrary {
|
||||
static void RegisterTypeLibraryType(asIScriptEngine* engine);
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_REGISTERTYPELIBRARY_HPP
|
||||
Reference in New Issue
Block a user