From 041bd998fa689d191cdb9e17305d0ebfb24d65d2 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 12 Jan 2020 19:30:44 +0100 Subject: [PATCH] Register more types to AngelScript interface. --- src/AngelScript/AngelScripResolver.cpp | 1 - .../TypeRegistry/RegisterPokemonTypes.cpp | 72 +++++++++++++++++-- .../TypeRegistry/RegisterPokemonTypes.hpp | 2 + tests/ScriptTests/ScriptResolverTests.cpp | 2 +- 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/AngelScript/AngelScripResolver.cpp b/src/AngelScript/AngelScripResolver.cpp index 8ec1540..c804694 100644 --- a/src/AngelScript/AngelScripResolver.cpp +++ b/src/AngelScript/AngelScripResolver.cpp @@ -12,7 +12,6 @@ void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* librar _engine->SetEngineProperty(asEP_DISALLOW_EMPTY_LIST_ELEMENTS, true); _engine->SetEngineProperty(asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE, true); - _engine->SetEngineProperty(asEP_ALLOW_IMPLICIT_HANDLE_TYPES, true); _engine->SetEngineProperty(asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT, true); _engine->SetEngineProperty(asEP_AUTO_GARBAGE_COLLECT, false); diff --git a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp b/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp index e45537c..0f29c55 100644 --- a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp +++ b/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp @@ -1,22 +1,45 @@ #include "RegisterPokemonTypes.hpp" #include #include "../../Library/Species/PokemonSpecies.hpp" +#include "../../Library/Statistic.hpp" void RegisterPokemonTypes::Register(asIScriptEngine* engine) { RegisterGenderEnum(engine); + RegisterStatisticEnum(engine); + RegisterFormeType(engine); RegisterSpeciesType(engine); } void RegisterPokemonTypes::RegisterGenderEnum(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterEnum("Gender"); assert(r >= 0); - r = engine->RegisterEnumValue("Gender", "Male", 0); assert(r >= 0); - r = engine->RegisterEnumValue("Gender", "Female", 1); assert(r >= 0); - r = engine->RegisterEnumValue("Gender", "Genderless", 2); assert(r >= 0); + [[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 RegisterPokemonTypes::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 RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) { - [[maybe_unused]] - int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT); + [[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); @@ -33,4 +56,41 @@ void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) { 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 RegisterPokemonTypes::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", "float 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); + +} \ No newline at end of file diff --git a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp b/src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp index 5a38945..bf39b21 100644 --- a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp +++ b/src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp @@ -8,7 +8,9 @@ public: private: static void RegisterGenderEnum(asIScriptEngine* engine); + static void RegisterStatisticEnum(asIScriptEngine* engine); static void RegisterSpeciesType(asIScriptEngine* engine); + static void RegisterFormeType(asIScriptEngine* engine); }; #endif // PKMNLIB_REGISTERPOKEMONTYPES_HPP diff --git a/tests/ScriptTests/ScriptResolverTests.cpp b/tests/ScriptTests/ScriptResolverTests.cpp index 4b195a9..fc49c20 100644 --- a/tests/ScriptTests/ScriptResolverTests.cpp +++ b/tests/ScriptTests/ScriptResolverTests.cpp @@ -11,7 +11,7 @@ class testScript1 { return a + b; } - void testFunc2(Species &s){ + void testFunc2(const Species@ s){ if (s.Name != "testSpecies2"){ throw("err"); }