Many tweaks and fixes relating to AngelScript, implements shininess.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
cade351bc2
commit
f33d96d922
|
@ -40,7 +40,7 @@ class PkmnLibConan(ConanFile):
|
||||||
self.options["AngelScript"].link_std_statically = True
|
self.options["AngelScript"].link_std_statically = True
|
||||||
|
|
||||||
def requirements(self):
|
def requirements(self):
|
||||||
self.requires("CreatureLib/7e0a1ec033f476dba24a7d091df997f31e2ac076@creaturelib/master")
|
self.requires("CreatureLib/bb9b9609a6e595ff8e6d4f4682b4be5b5e8d9d7e@creaturelib/master")
|
||||||
if self.options.script_handler == "angelscript":
|
if self.options.script_handler == "angelscript":
|
||||||
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
|
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -26,7 +26,9 @@ public:
|
||||||
return find->second;
|
return find->second;
|
||||||
}
|
}
|
||||||
auto func = _type->GetMethodByName(functionName.c_str());
|
auto func = _type->GetMethodByName(functionName.c_str());
|
||||||
func->AddRef();
|
if (func != nullptr){
|
||||||
|
func->AddRef();
|
||||||
|
}
|
||||||
_functions.insert({functionName, func});
|
_functions.insert({functionName, func});
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "RegisterPokemonClass.hpp"
|
#include "RegisterPokemonClass.hpp"
|
||||||
#include <Battling/Models/LearnedAttack.hpp>
|
#include <Battling/Models/LearnedAttack.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include "../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||||
#include "../../../Battling/Pokemon/Pokemon.hpp"
|
#include "../../../Battling/Pokemon/Pokemon.hpp"
|
||||||
|
|
||||||
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
||||||
|
@ -52,8 +53,23 @@ void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) {
|
||||||
|
|
||||||
ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender)
|
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) {
|
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||||
[[maybe_unused]]int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property",
|
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property",
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, GetSpecies), asCALL_THISCALL);
|
asMETHOD(PkmnLib::Battling::Pokemon, GetSpecies), asCALL_THISCALL);
|
||||||
|
@ -73,6 +89,9 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||||
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property",
|
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property",
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL);
|
asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL);
|
||||||
assert(r >= 0);
|
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",
|
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property",
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL);
|
asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
|
@ -89,7 +108,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL);
|
asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("Pokemon", "uint8[]@ GetTypes() const",
|
r = engine->RegisterObjectMethod("Pokemon", "uint8[]@ GetTypes() const",
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, GetTypes), asCALL_THISCALL);
|
asFUNCTION(GetTypes), asCALL_CDECL_OBJLAST);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const",
|
r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const",
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL);
|
asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL);
|
||||||
|
|
|
@ -20,7 +20,7 @@ void RegisterStaticLibraryTypes::RegisterLibrarySettingsType(asIScriptEngine* en
|
||||||
void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
|
void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
|
||||||
[[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
[[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings& get_Settings() const property",
|
r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings@ get_Settings() const property",
|
||||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSettings), asCALL_THISCALL);
|
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSettings), asCALL_THISCALL);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
|
r = engine->RegisterObjectMethod("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
|
||||||
|
|
|
@ -17,6 +17,10 @@ namespace PkmnLib::Battling {
|
||||||
: CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary,
|
: CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary,
|
||||||
scriptResolver, miscLibrary) {}
|
scriptResolver, miscLibrary) {}
|
||||||
|
|
||||||
|
const Library::LibrarySettings* GetSettings() const{
|
||||||
|
return static_cast<const Library::LibrarySettings*>(_staticLib->GetSettings());
|
||||||
|
}
|
||||||
|
|
||||||
const Library::PokemonLibrary* GetStaticLib() const{
|
const Library::PokemonLibrary* GetStaticLib() const{
|
||||||
return dynamic_cast<const Library::PokemonLibrary*>(CreatureLib::Battling::BattleLibrary::_staticLib);
|
return dynamic_cast<const Library::PokemonLibrary*>(CreatureLib::Battling::BattleLibrary::_staticLib);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "CreatePokemon.hpp"
|
#include "CreatePokemon.hpp"
|
||||||
|
|
||||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) {
|
PkmnLib::Battling::CreatePokemon*
|
||||||
|
PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) {
|
||||||
_ivHp = rand.Get(0, 32);
|
_ivHp = rand.Get(0, 32);
|
||||||
_ivAttack = rand.Get(0, 32);
|
_ivAttack = rand.Get(0, 32);
|
||||||
_ivDefense = rand.Get(0, 32);
|
_ivDefense = rand.Get(0, 32);
|
||||||
|
@ -10,7 +11,8 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIn
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value) {
|
PkmnLib::Battling::CreatePokemon*
|
||||||
|
PkmnLib::Battling::CreatePokemon::WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value) {
|
||||||
switch (stat) {
|
switch (stat) {
|
||||||
case PkmnLib::Library::Statistic::HealthPoints: _ivHp = value; break;
|
case PkmnLib::Library::Statistic::HealthPoints: _ivHp = value; break;
|
||||||
case PkmnLib::Library::Statistic::PhysicalAttack: _ivAttack = value; break;
|
case PkmnLib::Library::Statistic::PhysicalAttack: _ivAttack = value; break;
|
||||||
|
@ -22,7 +24,8 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividu
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortValue(CreatureLib::Core::Statistic stat, uint8_t value) {
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortValue(CreatureLib::Core::Statistic stat,
|
||||||
|
uint8_t value) {
|
||||||
switch (stat) {
|
switch (stat) {
|
||||||
case PkmnLib::Library::Statistic::HealthPoints: _evHp = value; break;
|
case PkmnLib::Library::Statistic::HealthPoints: _evHp = value; break;
|
||||||
case PkmnLib::Library::Statistic::PhysicalAttack: _evAttack = value; break;
|
case PkmnLib::Library::Statistic::PhysicalAttack: _evAttack = value; break;
|
||||||
|
@ -36,8 +39,11 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||||
|
|
||||||
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||||
auto rand = CreatureLib::Core::Random();
|
auto rand = CreatureLib::Core::Random();
|
||||||
auto species = this->_library->GetSpeciesLibrary()->GetPkmnSpecies(this->_species);
|
const PkmnLib::Library::PokemonSpecies* species = nullptr;
|
||||||
auto forme = species->GetForme(this->_variant);
|
if (!this->_library->GetSpeciesLibrary()->TryGetPkmnSpecies(this->_species, species)){
|
||||||
|
throw CreatureException("Invalid species: " + _species);
|
||||||
|
}
|
||||||
|
auto forme = species->GetForme(this->_forme);
|
||||||
int8_t ability;
|
int8_t ability;
|
||||||
if (this->_ability.empty()) {
|
if (this->_ability.empty()) {
|
||||||
ability = forme->GetRandomTalent(&rand);
|
ability = forme->GetRandomTalent(&rand);
|
||||||
|
@ -54,7 +60,9 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||||
}
|
}
|
||||||
const Library::Item* heldItem = nullptr;
|
const Library::Item* heldItem = nullptr;
|
||||||
if (!this->_heldItem.empty()) {
|
if (!this->_heldItem.empty()) {
|
||||||
heldItem = _library->GetItemLibrary()->GetItem(this->_heldItem);
|
if (!_library->GetItemLibrary()->TryGetItem(this->_heldItem, heldItem)){
|
||||||
|
throw CreatureException("Unknown Item: " + this->_heldItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||||
|
|
||||||
|
@ -66,12 +74,20 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||||
auto ivs = CreatureLib::Core::StatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, _ivSpDef, _ivSpeed);
|
auto ivs = CreatureLib::Core::StatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, _ivSpDef, _ivSpeed);
|
||||||
auto evs = CreatureLib::Core::StatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, _evSpDef, _evSpeed);
|
auto evs = CreatureLib::Core::StatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, _evSpDef, _evSpeed);
|
||||||
|
|
||||||
if (_nature == 255){
|
if (_nature == 255) {
|
||||||
_nature = _library->GetNatureLibrary()->GetRandomNature(rand);
|
_nature = _library->GetNatureLibrary()->GetRandomNature(rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, _coloring, heldItem, _nickname,
|
auto shiny = false;
|
||||||
ability, attacks, ivs, evs,_nature);
|
if (_shininessSet){
|
||||||
|
shiny = _isShiny;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
shiny = rand.Get(_library->GetSettings()->GetShinyRate()) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, shiny, heldItem,
|
||||||
|
_nickname, ability, attacks, ivs, evs, _nature);
|
||||||
pkmn->Initialize();
|
pkmn->Initialize();
|
||||||
return pkmn;
|
return pkmn;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +101,7 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividu
|
||||||
_ivHp = hp;
|
_ivHp = hp;
|
||||||
_ivAttack = att;
|
_ivAttack = att;
|
||||||
_ivDefense = def;
|
_ivDefense = def;
|
||||||
_ivSpAtt = spAtt;
|
_ivSpAtt = spAtt;
|
||||||
_ivSpDef = spDef;
|
_ivSpDef = spDef;
|
||||||
_ivSpeed = speed;
|
_ivSpeed = speed;
|
||||||
return this;
|
return this;
|
||||||
|
@ -96,8 +112,25 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||||
_evHp = hp;
|
_evHp = hp;
|
||||||
_evAttack = att;
|
_evAttack = att;
|
||||||
_evDefense = def;
|
_evDefense = def;
|
||||||
_evSpAtt = spAtt;
|
_evSpAtt = spAtt;
|
||||||
_evSpDef = spDef;
|
_evSpDef = spDef;
|
||||||
_evSpeed = speed;
|
_evSpeed = speed;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithForme(const std::string& forme) {
|
||||||
|
_forme = forme;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithGender(CreatureLib::Library::Gender gender) {
|
||||||
|
_gender = gender;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::IsShiny(bool value) {
|
||||||
|
_shininessSet = true;
|
||||||
|
_isShiny = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem(const std::string& item) {
|
||||||
|
_heldItem = item;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
|
@ -8,14 +8,13 @@ namespace PkmnLib::Battling {
|
||||||
private:
|
private:
|
||||||
const BattleLibrary* _library;
|
const BattleLibrary* _library;
|
||||||
std::string _species;
|
std::string _species;
|
||||||
std::string _variant = "default";
|
std::string _forme = "default";
|
||||||
uint8_t _level;
|
uint8_t _level;
|
||||||
std::string _nickname = "";
|
std::string _nickname = "";
|
||||||
|
|
||||||
std::string _ability = "";
|
std::string _ability = "";
|
||||||
uint8_t _nature = 255;
|
uint8_t _nature = 255;
|
||||||
CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1);
|
CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1);
|
||||||
uint8_t _coloring = 0;
|
|
||||||
std::string _heldItem = "";
|
std::string _heldItem = "";
|
||||||
uint32_t _identifier = 0;
|
uint32_t _identifier = 0;
|
||||||
std::vector<std::tuple<const Library::MoveData*, CreatureLib::Battling::AttackLearnMethod>> _attacks = {};
|
std::vector<std::tuple<const Library::MoveData*, CreatureLib::Battling::AttackLearnMethod>> _attacks = {};
|
||||||
|
@ -34,10 +33,18 @@ namespace PkmnLib::Battling {
|
||||||
uint8_t _evSpDef = 0;
|
uint8_t _evSpDef = 0;
|
||||||
uint8_t _evSpeed = 0;
|
uint8_t _evSpeed = 0;
|
||||||
|
|
||||||
|
bool _shininessSet = false;
|
||||||
|
bool _isShiny = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CreatePokemon(const BattleLibrary* library, std::string species, uint8_t level)
|
CreatePokemon(const BattleLibrary* library, std::string species, uint8_t level)
|
||||||
: _library(library), _species(std::move(species)), _level(level) {}
|
: _library(library), _species(std::move(species)), _level(level) {}
|
||||||
|
|
||||||
|
CreatePokemon* WithForme(const std::string& forme);
|
||||||
|
CreatePokemon* WithGender(CreatureLib::Library::Gender gender);
|
||||||
|
CreatePokemon* IsShiny(bool value);
|
||||||
|
CreatePokemon* WithHeldItem(const std::string& item);
|
||||||
|
|
||||||
CreatePokemon* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random());
|
CreatePokemon* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random());
|
||||||
CreatePokemon* WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value);
|
CreatePokemon* WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value);
|
||||||
CreatePokemon* WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef,
|
CreatePokemon* WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef,
|
||||||
|
|
|
@ -33,6 +33,10 @@ namespace PkmnLib::Battling {
|
||||||
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
|
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool IsShiny() const{
|
||||||
|
return _coloring == 1;
|
||||||
|
}
|
||||||
|
|
||||||
const Library::Nature& GetNature() const;
|
const Library::Nature& GetNature() const;
|
||||||
uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const { return _individualValues.GetStat(stat); }
|
uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const { return _individualValues.GetStat(stat); }
|
||||||
uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); }
|
uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); }
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
namespace PkmnLib::Library {
|
namespace PkmnLib::Library {
|
||||||
class ItemLibrary : public CreatureLib::Library::ItemLibrary {
|
class ItemLibrary : public CreatureLib::Library::ItemLibrary {
|
||||||
public:
|
public:
|
||||||
|
inline bool TryGetItem(const std::string& name, const Item*& item) const {
|
||||||
|
return CreatureLib::Library::ItemLibrary::TryGetItem(name, (const CreatureLib::Library::Item*&)item);
|
||||||
|
}
|
||||||
const Item* GetItem(const std::string& name) const {
|
const Item* GetItem(const std::string& name) const {
|
||||||
return reinterpret_cast<const Item*>(CreatureLib::Library::ItemLibrary::GetItem(name));
|
return reinterpret_cast<const Item*>(CreatureLib::Library::ItemLibrary::GetItem(name));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef PKMNLIB_LIBRARYSETTINGS_HPP
|
||||||
|
#define PKMNLIB_LIBRARYSETTINGS_HPP
|
||||||
|
|
||||||
|
#include <Library/LibrarySettings.hpp>
|
||||||
|
|
||||||
|
namespace PkmnLib::Library {
|
||||||
|
class LibrarySettings : public CreatureLib::Library::LibrarySettings {
|
||||||
|
uint16_t _shinyRate;
|
||||||
|
|
||||||
|
public:
|
||||||
|
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves, uint16_t shinyRate)
|
||||||
|
: CreatureLib::Library::LibrarySettings(maximalLevel, maximalMoves), _shinyRate(shinyRate) {}
|
||||||
|
|
||||||
|
uint16_t GetShinyRate() const { return _shinyRate; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PKMNLIB_LIBRARYSETTINGS_HPP
|
|
@ -10,6 +10,9 @@ namespace PkmnLib::Library {
|
||||||
|
|
||||||
virtual const MoveData* operator[](const std::string& name) const { return GetAttack(name); }
|
virtual const MoveData* operator[](const std::string& name) const { return GetAttack(name); }
|
||||||
|
|
||||||
|
inline bool TryGetMove(const std::string& name, const MoveData*& move) const{
|
||||||
|
return TryGetAttack(name, (const CreatureLib::Library::AttackData*&)move);
|
||||||
|
}
|
||||||
const MoveData* GetMove(const std::string& name) const { return GetAttack(name); }
|
const MoveData* GetMove(const std::string& name) const { return GetAttack(name); }
|
||||||
|
|
||||||
const MoveData* GetAttack(const std::string& name) const {
|
const MoveData* GetAttack(const std::string& name) const {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <Library/DataLibrary.hpp>
|
#include <Library/DataLibrary.hpp>
|
||||||
#include "Items/ItemLibrary.hpp"
|
#include "Items/ItemLibrary.hpp"
|
||||||
|
#include "LibrarySettings.hpp"
|
||||||
#include "Moves/MoveLibrary.hpp"
|
#include "Moves/MoveLibrary.hpp"
|
||||||
#include "Natures/NatureLibrary.hpp"
|
#include "Natures/NatureLibrary.hpp"
|
||||||
#include "Species/SpeciesLibrary.hpp"
|
#include "Species/SpeciesLibrary.hpp"
|
||||||
|
@ -17,11 +18,15 @@ namespace PkmnLib::Library {
|
||||||
delete _natures;
|
delete _natures;
|
||||||
}
|
}
|
||||||
|
|
||||||
PokemonLibrary(CreatureLib::Library::LibrarySettings settings, SpeciesLibrary* species, MoveLibrary* moves,
|
PokemonLibrary(PkmnLib::Library::LibrarySettings* settings, SpeciesLibrary* species, MoveLibrary* moves,
|
||||||
ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates,
|
ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates,
|
||||||
CreatureLib::Library::TypeLibrary* typeLibrary, NatureLibrary* natures)
|
CreatureLib::Library::TypeLibrary* typeLibrary, NatureLibrary* natures)
|
||||||
: DataLibrary(settings, species, moves, items, growthRates, typeLibrary), _natures(natures) {}
|
: DataLibrary(settings, species, moves, items, growthRates, typeLibrary), _natures(natures) {}
|
||||||
|
|
||||||
|
const PkmnLib::Library::LibrarySettings* GetSettings() const{
|
||||||
|
return static_cast<const LibrarySettings*>(CreatureLib::Library::DataLibrary::GetSettings());
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const {
|
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const {
|
||||||
return (const SpeciesLibrary*)(CreatureLib::Library::DataLibrary::GetSpeciesLibrary());
|
return (const SpeciesLibrary*)(CreatureLib::Library::DataLibrary::GetSpeciesLibrary());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
namespace PkmnLib::Library {
|
namespace PkmnLib::Library {
|
||||||
class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary {
|
class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
inline bool TryGetPkmnSpecies(const std::string& name, const PokemonSpecies*& outSpecies) const{
|
||||||
|
return TryGetSpecies(name, (const CreatureLib::Library::CreatureSpecies*&)outSpecies);
|
||||||
|
}
|
||||||
|
|
||||||
inline const PokemonSpecies* GetPkmnSpecies(const std::string& name) const {
|
inline const PokemonSpecies* GetPkmnSpecies(const std::string& name) const {
|
||||||
return reinterpret_cast<const PokemonSpecies*>(CreatureLib::Library::SpeciesLibrary::GetSpecies(name));
|
return reinterpret_cast<const PokemonSpecies*>(CreatureLib::Library::SpeciesLibrary::GetSpecies(name));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,255 @@
|
||||||
|
#ifdef TESTS_BUILD
|
||||||
|
#include "../../../../extern/catch.hpp"
|
||||||
|
#include "../../../../src/AngelScript/AngelScripResolver.hpp"
|
||||||
|
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
|
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
||||||
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
|
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||||
|
class testScript1 {
|
||||||
|
bool testSpecies(Pokemon@ p, const Species@ species){ return p.Species is species; }
|
||||||
|
bool testForme(Pokemon@ p, const Forme@ forme){ return p.Forme is forme; }
|
||||||
|
bool testLevel(Pokemon@ p, uint8 level){ return p.Level == level; }
|
||||||
|
bool testExperience(Pokemon@ p, uint experience){ return p.Experience == experience; }
|
||||||
|
bool testGender(Pokemon@ p, Gender gender){ return p.Gender == gender; }
|
||||||
|
bool testShiny(Pokemon@ p, bool shiny){ return p.Shiny == shiny; }
|
||||||
|
bool testHeldItem(Pokemon@ p, Item@ item){ return p.HeldItem is item; }
|
||||||
|
bool testCurrentHealth(Pokemon@ p, uint health){ return p.CurrentHealth == health; }
|
||||||
|
bool testNickname(Pokemon@ p, const string &in name){ return p.Nickname == name; }
|
||||||
|
bool testActiveAbility(Pokemon@ p, const string &in ability){ return p.ActiveAbility == ability; }
|
||||||
|
bool testIsFainted(Pokemon@ p, bool b){ return p.IsFainted == b; }
|
||||||
|
bool testType(Pokemon@ p, uint index, uint8 type){ return p.GetTypes()[index] == type; }
|
||||||
|
}
|
||||||
|
)"}};
|
||||||
|
|
||||||
|
static const char* _testLoadFunc(const char* name) { return _scripts[name]; }
|
||||||
|
|
||||||
|
struct ScriptData {
|
||||||
|
AngelScriptScript* Script;
|
||||||
|
AngelScripResolver* Resolver;
|
||||||
|
asIScriptFunction* Func;
|
||||||
|
asIScriptContext* Context;
|
||||||
|
|
||||||
|
~ScriptData() {
|
||||||
|
Script->GetContextPool()->ReturnContextToPool(Context);
|
||||||
|
delete Script;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static AngelScripResolver* _resolverCache = nullptr;
|
||||||
|
static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib) {
|
||||||
|
if (_resolverCache == nullptr) {
|
||||||
|
_resolverCache = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
_resolverCache->Initialize(mainLib);
|
||||||
|
_resolverCache->SetCreateFunction(&_testLoadFunc);
|
||||||
|
_resolverCache->CreateScript("testScript1");
|
||||||
|
_resolverCache->FinalizeModule();
|
||||||
|
}
|
||||||
|
return _resolverCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
||||||
|
auto lib = GetScriptResolver(mainLib);
|
||||||
|
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
||||||
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
|
auto ctxPool = script->GetContextPool();
|
||||||
|
auto ctx = ctxPool->RequestContext();
|
||||||
|
|
||||||
|
auto func = script->PrepareMethod(funcName, ctx);
|
||||||
|
REQUIRE(func != nullptr);
|
||||||
|
|
||||||
|
return {.Script = script, .Resolver = lib, .Func = func, .Context = ctx};
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Species in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testSpecies");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30).Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgObject(1, (void*)mon->GetSpecies());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Forme in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testForme");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30).WithForme("default")->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgObject(1, (void*)mon->GetForme());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Level in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testLevel");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30).WithForme("default")->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgByte(1, mon->GetLevel());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Experience in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testExperience");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30).WithForme("default")->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgDWord(1, mon->GetExperience());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Gender in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testGender");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgDWord(1, (int)mon->GetGender());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Shininess in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testShiny");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgByte(1, mon->IsShiny());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon HeldItem in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testHeldItem");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithHeldItem("testItem")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgObject(1, (void*)mon->GetHeldItem());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon CurrentHealth in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testCurrentHealth");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgDWord(1, mon->GetCurrentHealth());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Nickname in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testNickname");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
auto name = mon->GetNickname();
|
||||||
|
data.Context->SetArgAddress(1, &name);
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Active Ability in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testActiveAbility");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
auto name = mon->GetActiveTalent();
|
||||||
|
data.Context->SetArgAddress(1, &name);
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon IsFainted in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
auto data = GetScript(mainLib, "testIsFainted");
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgByte(1, mon->IsFainted());
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon GetTypes in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
for (auto i = 0; i < mon->GetTypes().size(); i++){
|
||||||
|
auto data = GetScript(mainLib, "testType");
|
||||||
|
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgDWord(1, i);
|
||||||
|
data.Context->SetArgByte(2, mon->GetTypes()[i]);
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -28,16 +28,23 @@ struct ScriptData {
|
||||||
~ScriptData() {
|
~ScriptData() {
|
||||||
Script->GetContextPool()->ReturnContextToPool(Context);
|
Script->GetContextPool()->ReturnContextToPool(Context);
|
||||||
delete Script;
|
delete Script;
|
||||||
delete Resolver;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static AngelScripResolver* _resolverCache = nullptr;
|
||||||
|
static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib){
|
||||||
|
if (_resolverCache == nullptr){
|
||||||
|
_resolverCache = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
_resolverCache->Initialize(mainLib);
|
||||||
|
_resolverCache->SetCreateFunction(&_testLoadFunc);
|
||||||
|
_resolverCache->CreateScript("testScript1");
|
||||||
|
_resolverCache->FinalizeModule();
|
||||||
|
}
|
||||||
|
return _resolverCache;
|
||||||
|
}
|
||||||
|
|
||||||
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
||||||
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
auto lib = GetScriptResolver(mainLib);
|
||||||
lib->Initialize(mainLib);
|
|
||||||
lib->SetCreateFunction(&_testLoadFunc);
|
|
||||||
lib->CreateScript("testScript1");
|
|
||||||
lib->FinalizeModule();
|
|
||||||
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
|
|
|
@ -24,16 +24,23 @@ struct ScriptData {
|
||||||
~ScriptData() {
|
~ScriptData() {
|
||||||
Script->GetContextPool()->ReturnContextToPool(Context);
|
Script->GetContextPool()->ReturnContextToPool(Context);
|
||||||
delete Script;
|
delete Script;
|
||||||
delete Resolver;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static AngelScripResolver* _resolverCache = nullptr;
|
||||||
|
static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib){
|
||||||
|
if (_resolverCache == nullptr){
|
||||||
|
_resolverCache = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
_resolverCache->Initialize(mainLib);
|
||||||
|
_resolverCache->SetCreateFunction(&_testLoadFunc);
|
||||||
|
_resolverCache->CreateScript("testScript1");
|
||||||
|
_resolverCache->FinalizeModule();
|
||||||
|
}
|
||||||
|
return _resolverCache;
|
||||||
|
}
|
||||||
|
|
||||||
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
||||||
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
auto lib = GetScriptResolver(mainLib);
|
||||||
lib->Initialize(mainLib);
|
|
||||||
lib->SetCreateFunction(&_testLoadFunc);
|
|
||||||
lib->CreateScript("testScript1");
|
|
||||||
lib->FinalizeModule();
|
|
||||||
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
|
|
|
@ -28,16 +28,23 @@ struct ScriptData {
|
||||||
~ScriptData() {
|
~ScriptData() {
|
||||||
Script->GetContextPool()->ReturnContextToPool(Context);
|
Script->GetContextPool()->ReturnContextToPool(Context);
|
||||||
delete Script;
|
delete Script;
|
||||||
delete Resolver;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static AngelScripResolver* _resolverCache = nullptr;
|
||||||
|
static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib){
|
||||||
|
if (_resolverCache == nullptr){
|
||||||
|
_resolverCache = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
_resolverCache->Initialize(mainLib);
|
||||||
|
_resolverCache->SetCreateFunction(&_testLoadFunc);
|
||||||
|
_resolverCache->CreateScript("testScript1");
|
||||||
|
_resolverCache->FinalizeModule();
|
||||||
|
}
|
||||||
|
return _resolverCache;
|
||||||
|
}
|
||||||
|
|
||||||
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
||||||
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
auto lib = GetScriptResolver(mainLib);
|
||||||
lib->Initialize(mainLib);
|
|
||||||
lib->SetCreateFunction(&_testLoadFunc);
|
|
||||||
lib->CreateScript("testScript1");
|
|
||||||
lib->FinalizeModule();
|
|
||||||
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
|
|
|
@ -17,25 +17,32 @@ class testScript1 {
|
||||||
|
|
||||||
static const char* _testLoadFunc(const char* name) { return _scripts[name]; }
|
static const char* _testLoadFunc(const char* name) { return _scripts[name]; }
|
||||||
|
|
||||||
struct ScriptData{
|
struct ScriptData {
|
||||||
AngelScriptScript* Script;
|
AngelScriptScript* Script;
|
||||||
AngelScripResolver* Resolver;
|
AngelScripResolver* Resolver;
|
||||||
asIScriptFunction* Func;
|
asIScriptFunction* Func;
|
||||||
asIScriptContext* Context;
|
asIScriptContext* Context;
|
||||||
|
|
||||||
~ScriptData(){
|
~ScriptData() {
|
||||||
Script->GetContextPool()->ReturnContextToPool(Context);
|
Script->GetContextPool()->ReturnContextToPool(Context);
|
||||||
delete Script;
|
delete Script;
|
||||||
delete Resolver;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName){
|
static AngelScripResolver* _resolverCache = nullptr;
|
||||||
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib){
|
||||||
lib->Initialize(mainLib);
|
if (_resolverCache == nullptr){
|
||||||
lib->SetCreateFunction(&_testLoadFunc);
|
_resolverCache = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
lib->CreateScript("testScript1");
|
_resolverCache->Initialize(mainLib);
|
||||||
lib->FinalizeModule();
|
_resolverCache->SetCreateFunction(&_testLoadFunc);
|
||||||
|
_resolverCache->CreateScript("testScript1");
|
||||||
|
_resolverCache->FinalizeModule();
|
||||||
|
}
|
||||||
|
return _resolverCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
||||||
|
auto lib = GetScriptResolver(mainLib);
|
||||||
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
|
@ -44,12 +51,7 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const cha
|
||||||
auto func = script->PrepareMethod(funcName, ctx);
|
auto func = script->PrepareMethod(funcName, ctx);
|
||||||
REQUIRE(func != nullptr);
|
REQUIRE(func != nullptr);
|
||||||
|
|
||||||
return {
|
return {.Script = script, .Resolver = lib, .Func = func, .Context = ctx};
|
||||||
.Script = script,
|
|
||||||
.Resolver = lib,
|
|
||||||
.Func = func,
|
|
||||||
.Context = ctx
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Validate Species Name in Script") {
|
TEST_CASE("Validate Species Name in Script") {
|
||||||
|
|
|
@ -27,16 +27,23 @@ struct ScriptData {
|
||||||
~ScriptData() {
|
~ScriptData() {
|
||||||
Script->GetContextPool()->ReturnContextToPool(Context);
|
Script->GetContextPool()->ReturnContextToPool(Context);
|
||||||
delete Script;
|
delete Script;
|
||||||
delete Resolver;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static AngelScripResolver* _resolverCache = nullptr;
|
||||||
|
static AngelScripResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib){
|
||||||
|
if (_resolverCache == nullptr){
|
||||||
|
_resolverCache = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
|
_resolverCache->Initialize(mainLib);
|
||||||
|
_resolverCache->SetCreateFunction(&_testLoadFunc);
|
||||||
|
_resolverCache->CreateScript("testScript1");
|
||||||
|
_resolverCache->FinalizeModule();
|
||||||
|
}
|
||||||
|
return _resolverCache;
|
||||||
|
}
|
||||||
|
|
||||||
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const char* funcName) {
|
||||||
auto lib = dynamic_cast<AngelScripResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
auto lib = GetScriptResolver(mainLib);
|
||||||
lib->Initialize(mainLib);
|
|
||||||
lib->SetCreateFunction(&_testLoadFunc);
|
|
||||||
lib->CreateScript("testScript1");
|
|
||||||
lib->FinalizeModule();
|
|
||||||
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
auto s = lib->LoadScript(AngelScripResolver::ScriptCategory::Creature, "testScript1");
|
||||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||||
auto ctxPool = script->GetContextPool();
|
auto ctxPool = script->GetContextPool();
|
||||||
|
@ -53,7 +60,7 @@ TEST_CASE("Validate StaticLibrary Maximum Level in Script") {
|
||||||
auto data = GetScript(mainLib, "testMaximumLevel");
|
auto data = GetScript(mainLib, "testMaximumLevel");
|
||||||
|
|
||||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||||
data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings().GetMaximalLevel());
|
data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings()->GetMaximalLevel());
|
||||||
|
|
||||||
auto result = data.Context->Execute();
|
auto result = data.Context->Execute();
|
||||||
REQUIRE(result == asEXECUTION_FINISHED);
|
REQUIRE(result == asEXECUTION_FINISHED);
|
||||||
|
@ -66,7 +73,7 @@ TEST_CASE("Validate StaticLibrary Maximum Moves in Script") {
|
||||||
auto data = GetScript(mainLib, "testMaximumMoves");
|
auto data = GetScript(mainLib, "testMaximumMoves");
|
||||||
|
|
||||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
|
||||||
data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings().GetMaximalMoves());
|
data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings()->GetMaximalMoves());
|
||||||
|
|
||||||
auto result = data.Context->Execute();
|
auto result = data.Context->Execute();
|
||||||
REQUIRE(result == asEXECUTION_FINISHED);
|
REQUIRE(result == asEXECUTION_FINISHED);
|
||||||
|
|
|
@ -26,6 +26,15 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
|
||||||
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"},
|
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"},
|
||||||
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)),
|
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)),
|
||||||
0.5f, "testGrowthRate", 100, 100));
|
0.5f, "testGrowthRate", 100, 100));
|
||||||
|
lib->LoadSpecies("testSpecies3",
|
||||||
|
new PkmnLib::Library::PokemonSpecies(
|
||||||
|
2, "testSpecies3",
|
||||||
|
new PkmnLib::Library::PokemonForme(
|
||||||
|
"default", 1.0f, 1.0f, 100, {0, 4},
|
||||||
|
CreatureLib::Core::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"},
|
||||||
|
{"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)),
|
||||||
|
0.5f, "testGrowthRate", 100, 100));
|
||||||
|
|
||||||
|
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static PkmnLib::Library::PokemonLibrary* BuildStaticLibrary() {
|
static PkmnLib::Library::PokemonLibrary* BuildStaticLibrary() {
|
||||||
return new PkmnLib::Library::PokemonLibrary(CreatureLib::Library::LibrarySettings(100, 4),
|
return new PkmnLib::Library::PokemonLibrary(new PkmnLib::Library::LibrarySettings(100, 4, 4096),
|
||||||
BuildSpeciesLibrary(), BuildMoveLibrary(), BuildItemLibrary(),
|
BuildSpeciesLibrary(), BuildMoveLibrary(), BuildItemLibrary(),
|
||||||
BuildGrowthRateLibrary(), BuildTypeLibrary(), BuildNatureLibrary());
|
BuildGrowthRateLibrary(), BuildTypeLibrary(), BuildNatureLibrary());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue