Register more types to AngelScript interface.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-01-12 19:30:44 +01:00
parent 72c2e38ea8
commit 041bd998fa
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 69 additions and 8 deletions

View File

@ -12,7 +12,6 @@ void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* librar
_engine->SetEngineProperty(asEP_DISALLOW_EMPTY_LIST_ELEMENTS, true); _engine->SetEngineProperty(asEP_DISALLOW_EMPTY_LIST_ELEMENTS, true);
_engine->SetEngineProperty(asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE, 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_ALWAYS_IMPL_DEFAULT_CONSTRUCT, true);
_engine->SetEngineProperty(asEP_AUTO_GARBAGE_COLLECT, false); _engine->SetEngineProperty(asEP_AUTO_GARBAGE_COLLECT, false);

View File

@ -1,22 +1,45 @@
#include "RegisterPokemonTypes.hpp" #include "RegisterPokemonTypes.hpp"
#include <cassert> #include <cassert>
#include "../../Library/Species/PokemonSpecies.hpp" #include "../../Library/Species/PokemonSpecies.hpp"
#include "../../Library/Statistic.hpp"
void RegisterPokemonTypes::Register(asIScriptEngine* engine) { void RegisterPokemonTypes::Register(asIScriptEngine* engine) {
RegisterGenderEnum(engine); RegisterGenderEnum(engine);
RegisterStatisticEnum(engine);
RegisterFormeType(engine);
RegisterSpeciesType(engine); RegisterSpeciesType(engine);
} }
void RegisterPokemonTypes::RegisterGenderEnum(asIScriptEngine* engine) { void RegisterPokemonTypes::RegisterGenderEnum(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("Gender"); assert(r >= 0); [[maybe_unused]] int r = engine->RegisterEnum("Gender");
r = engine->RegisterEnumValue("Gender", "Male", 0); assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("Gender", "Female", 1); assert(r >= 0); r = engine->RegisterEnumValue("Gender", "Male", (int)CreatureLib::Library::Gender::Male);
r = engine->RegisterEnumValue("Gender", "Genderless", 2); assert(r >= 0); 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) { void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) {
[[maybe_unused]] [[maybe_unused]] int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("Species", "const string& get_Name() const property", r = engine->RegisterObjectMethod("Species", "const string& get_Name() const property",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetName), asCALL_THISCALL); asMETHOD(PkmnLib::Library::PokemonSpecies, GetName), asCALL_THISCALL);
@ -33,4 +56,41 @@ void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Species", "Gender GetRandomGender() const", r = engine->RegisterObjectMethod("Species", "Gender GetRandomGender() const",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetRandomGender), asCALL_THISCALL); asMETHOD(PkmnLib::Library::PokemonSpecies, GetRandomGender), asCALL_THISCALL);
assert(r >= 0); 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);
}

View File

@ -8,7 +8,9 @@ public:
private: private:
static void RegisterGenderEnum(asIScriptEngine* engine); static void RegisterGenderEnum(asIScriptEngine* engine);
static void RegisterStatisticEnum(asIScriptEngine* engine);
static void RegisterSpeciesType(asIScriptEngine* engine); static void RegisterSpeciesType(asIScriptEngine* engine);
static void RegisterFormeType(asIScriptEngine* engine);
}; };
#endif // PKMNLIB_REGISTERPOKEMONTYPES_HPP #endif // PKMNLIB_REGISTERPOKEMONTYPES_HPP

View File

@ -11,7 +11,7 @@ class testScript1 {
return a + b; return a + b;
} }
void testFunc2(Species &s){ void testFunc2(const Species@ s){
if (s.Name != "testSpecies2"){ if (s.Name != "testSpecies2"){
throw("err"); throw("err");
} }