From faf22c9562a1ae1e0573f8e34be8b424dc0d5a32 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 13 Jan 2020 19:52:32 +0100 Subject: [PATCH] Register GrowthRate in AngelScript. --- src/AngelScript/AngelScripResolver.cpp | 8 +++++--- .../Library/RegisterGrowthRateTypes.cpp | 17 +++++++++++++++++ .../Library/RegisterGrowthRateTypes.hpp | 11 +++++++++++ .../{ => Library}/RegisterItemTypes.cpp | 2 +- .../{ => Library}/RegisterItemTypes.hpp | 0 .../{ => Library}/RegisterMoveTypes.cpp | 2 +- .../{ => Library}/RegisterMoveTypes.hpp | 0 .../{ => Library}/RegisterPokemonTypes.cpp | 4 ++-- .../{ => Library}/RegisterPokemonTypes.hpp | 0 9 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 src/AngelScript/TypeRegistry/Library/RegisterGrowthRateTypes.cpp create mode 100644 src/AngelScript/TypeRegistry/Library/RegisterGrowthRateTypes.hpp rename src/AngelScript/TypeRegistry/{ => Library}/RegisterItemTypes.cpp (98%) rename src/AngelScript/TypeRegistry/{ => Library}/RegisterItemTypes.hpp (100%) rename src/AngelScript/TypeRegistry/{ => Library}/RegisterMoveTypes.cpp (98%) rename src/AngelScript/TypeRegistry/{ => Library}/RegisterMoveTypes.hpp (100%) rename src/AngelScript/TypeRegistry/{ => Library}/RegisterPokemonTypes.cpp (98%) rename src/AngelScript/TypeRegistry/{ => Library}/RegisterPokemonTypes.hpp (100%) diff --git a/src/AngelScript/AngelScripResolver.cpp b/src/AngelScript/AngelScripResolver.cpp index 192dae2..1839d8c 100644 --- a/src/AngelScript/AngelScripResolver.cpp +++ b/src/AngelScript/AngelScripResolver.cpp @@ -1,9 +1,10 @@ #include "AngelScripResolver.hpp" #include "../../extern/angelscript_addons/scripthelper/scripthelper.h" #include "../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h" -#include "TypeRegistry/RegisterItemTypes.hpp" -#include "TypeRegistry/RegisterMoveTypes.hpp" -#include "TypeRegistry/RegisterPokemonTypes.hpp" +#include "TypeRegistry/Library/RegisterGrowthRateTypes.hpp" +#include "TypeRegistry/Library/RegisterItemTypes.hpp" +#include "TypeRegistry/Library/RegisterMoveTypes.hpp" +#include "TypeRegistry/Library/RegisterPokemonTypes.hpp" CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver() { return new AngelScripResolver(); @@ -31,6 +32,7 @@ void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* librar RegisterPokemonTypes::Register(_engine); RegisterItemTypes::Register(_engine); RegisterMoveTypes::Register(_engine); + RegisterGrowthRateTypes::Register(_engine); _mainModule = _engine->GetModule("pkmn", asGM_ALWAYS_CREATE); diff --git a/src/AngelScript/TypeRegistry/Library/RegisterGrowthRateTypes.cpp b/src/AngelScript/TypeRegistry/Library/RegisterGrowthRateTypes.cpp new file mode 100644 index 0000000..865e3e6 --- /dev/null +++ b/src/AngelScript/TypeRegistry/Library/RegisterGrowthRateTypes.cpp @@ -0,0 +1,17 @@ +#include "RegisterGrowthRateTypes.hpp" +#include +#include + +void RegisterGrowthRateTypes::Register(asIScriptEngine* engine) { + RegisterGrowthRateType(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); +} diff --git a/src/AngelScript/TypeRegistry/Library/RegisterGrowthRateTypes.hpp b/src/AngelScript/TypeRegistry/Library/RegisterGrowthRateTypes.hpp new file mode 100644 index 0000000..7282701 --- /dev/null +++ b/src/AngelScript/TypeRegistry/Library/RegisterGrowthRateTypes.hpp @@ -0,0 +1,11 @@ +#ifndef PKMNLIB_REGISTERGROWTHRATETYPES_HPP +#define PKMNLIB_REGISTERGROWTHRATETYPES_HPP +#include + +class RegisterGrowthRateTypes { + static void RegisterGrowthRateType(asIScriptEngine* engine); +public: + static void Register(asIScriptEngine* engine); +}; + +#endif // PKMNLIB_REGISTERGROWTHRATETYPES_HPP diff --git a/src/AngelScript/TypeRegistry/RegisterItemTypes.cpp b/src/AngelScript/TypeRegistry/Library/RegisterItemTypes.cpp similarity index 98% rename from src/AngelScript/TypeRegistry/RegisterItemTypes.cpp rename to src/AngelScript/TypeRegistry/Library/RegisterItemTypes.cpp index 7b59711..60d5286 100644 --- a/src/AngelScript/TypeRegistry/RegisterItemTypes.cpp +++ b/src/AngelScript/TypeRegistry/Library/RegisterItemTypes.cpp @@ -1,6 +1,6 @@ #include "RegisterItemTypes.hpp" #include -#include "../../Library/Items/Item.hpp" +#include "../../../Library/Items/Item.hpp" void RegisterItemTypes::Register(asIScriptEngine* engine) { RegisterItemCategoryEnum(engine); diff --git a/src/AngelScript/TypeRegistry/RegisterItemTypes.hpp b/src/AngelScript/TypeRegistry/Library/RegisterItemTypes.hpp similarity index 100% rename from src/AngelScript/TypeRegistry/RegisterItemTypes.hpp rename to src/AngelScript/TypeRegistry/Library/RegisterItemTypes.hpp diff --git a/src/AngelScript/TypeRegistry/RegisterMoveTypes.cpp b/src/AngelScript/TypeRegistry/Library/RegisterMoveTypes.cpp similarity index 98% rename from src/AngelScript/TypeRegistry/RegisterMoveTypes.cpp rename to src/AngelScript/TypeRegistry/Library/RegisterMoveTypes.cpp index b32da94..f85cab5 100644 --- a/src/AngelScript/TypeRegistry/RegisterMoveTypes.cpp +++ b/src/AngelScript/TypeRegistry/Library/RegisterMoveTypes.cpp @@ -1,6 +1,6 @@ #include "RegisterMoveTypes.hpp" #include -#include "../../Library/Moves/MoveData.hpp" +#include "../../../Library/Moves/MoveData.hpp" void RegisterMoveTypes::Register(asIScriptEngine* engine) { RegisterMoveCategory(engine); diff --git a/src/AngelScript/TypeRegistry/RegisterMoveTypes.hpp b/src/AngelScript/TypeRegistry/Library/RegisterMoveTypes.hpp similarity index 100% rename from src/AngelScript/TypeRegistry/RegisterMoveTypes.hpp rename to src/AngelScript/TypeRegistry/Library/RegisterMoveTypes.hpp diff --git a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp b/src/AngelScript/TypeRegistry/Library/RegisterPokemonTypes.cpp similarity index 98% rename from src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp rename to src/AngelScript/TypeRegistry/Library/RegisterPokemonTypes.cpp index 0f29c55..2535eaa 100644 --- a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp +++ b/src/AngelScript/TypeRegistry/Library/RegisterPokemonTypes.cpp @@ -1,7 +1,7 @@ #include "RegisterPokemonTypes.hpp" #include -#include "../../Library/Species/PokemonSpecies.hpp" -#include "../../Library/Statistic.hpp" +#include "../../../Library/Species/PokemonSpecies.hpp" +#include "../../../Library/Statistic.hpp" void RegisterPokemonTypes::Register(asIScriptEngine* engine) { RegisterGenderEnum(engine); diff --git a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp b/src/AngelScript/TypeRegistry/Library/RegisterPokemonTypes.hpp similarity index 100% rename from src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp rename to src/AngelScript/TypeRegistry/Library/RegisterPokemonTypes.hpp