Register Move Types.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
574776dbe0
commit
797044aa8c
|
@ -2,6 +2,7 @@
|
||||||
#include "../../extern/angelscript_addons/scripthelper/scripthelper.h"
|
#include "../../extern/angelscript_addons/scripthelper/scripthelper.h"
|
||||||
#include "../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h"
|
#include "../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h"
|
||||||
#include "TypeRegistry/RegisterItemTypes.hpp"
|
#include "TypeRegistry/RegisterItemTypes.hpp"
|
||||||
|
#include "TypeRegistry/RegisterMoveTypes.hpp"
|
||||||
#include "TypeRegistry/RegisterPokemonTypes.hpp"
|
#include "TypeRegistry/RegisterPokemonTypes.hpp"
|
||||||
|
|
||||||
CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver() {
|
CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver() {
|
||||||
|
@ -22,12 +23,14 @@ void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* librar
|
||||||
|
|
||||||
RegisterStdString(_engine);
|
RegisterStdString(_engine);
|
||||||
r = _engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(Print), asCALL_CDECL);
|
r = _engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(Print), asCALL_CDECL);
|
||||||
if (r < 0) throw CreatureException("Registering print function failed.");
|
if (r < 0)
|
||||||
|
throw CreatureException("Registering print function failed.");
|
||||||
|
|
||||||
RegisterExceptionRoutines(_engine);
|
RegisterExceptionRoutines(_engine);
|
||||||
|
|
||||||
RegisterPokemonTypes::Register(_engine);
|
RegisterPokemonTypes::Register(_engine);
|
||||||
RegisterItemTypes::Register(_engine);
|
RegisterItemTypes::Register(_engine);
|
||||||
|
RegisterMoveTypes::Register(_engine);
|
||||||
|
|
||||||
_mainModule = _engine->GetModule("pkmn", asGM_ALWAYS_CREATE);
|
_mainModule = _engine->GetModule("pkmn", asGM_ALWAYS_CREATE);
|
||||||
|
|
||||||
|
@ -57,7 +60,8 @@ void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param)
|
||||||
}
|
}
|
||||||
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const std::string& scriptName) {
|
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const std::string& scriptName) {
|
||||||
auto typeInfo = GetTypeInfo(scriptName);
|
auto typeInfo = GetTypeInfo(scriptName);
|
||||||
if (typeInfo == nullptr) return nullptr;
|
if (typeInfo == nullptr)
|
||||||
|
return nullptr;
|
||||||
auto ctx = _contextPool->RequestContext();
|
auto ctx = _contextPool->RequestContext();
|
||||||
auto obj = typeInfo->Instantiate(ctx);
|
auto obj = typeInfo->Instantiate(ctx);
|
||||||
_contextPool->ReturnContextToPool(ctx);
|
_contextPool->ReturnContextToPool(ctx);
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
#include "RegisterMoveTypes.hpp"
|
||||||
|
#include <cassert>
|
||||||
|
#include "../../Library/Moves/MoveData.hpp"
|
||||||
|
|
||||||
|
void RegisterMoveTypes::Register(asIScriptEngine* engine) {
|
||||||
|
RegisterMoveCategory(engine);
|
||||||
|
RegisterMoveTarget(engine);
|
||||||
|
RegisterMoveType(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)
|
||||||
|
}
|
||||||
|
|
||||||
|
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", "const string& get_Type() const property",
|
||||||
|
asMETHOD(PkmnLib::Library::MoveData, GetType), asCALL_THISCALL);
|
||||||
|
assert(r >= 0);
|
||||||
|
r = engine->RegisterObjectMethod("MoveData", "MoveCategory get_Category() const property",
|
||||||
|
asMETHOD(PkmnLib::Library::MoveData, GetCategory), asCALL_THISCALL);
|
||||||
|
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",
|
||||||
|
asMETHOD(PkmnLib::Library::MoveData, GetTarget), asCALL_THISCALL);
|
||||||
|
assert(r >= 0);
|
||||||
|
r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property",
|
||||||
|
asMETHOD(PkmnLib::Library::MoveData, GetTarget), 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef REGISTER_ENUM_VALUE
|
|
@ -0,0 +1,13 @@
|
||||||
|
#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);
|
||||||
|
public:
|
||||||
|
static void Register(asIScriptEngine* engine);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PKMNLIB_REGISTERMOVETYPES_HPP
|
Loading…
Reference in New Issue