Adds Angelscript wrappers for Party.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-05-08 12:12:36 +02:00
parent 1c66aa8696
commit 6def68cf72
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
7 changed files with 87 additions and 11 deletions

View File

@ -32,10 +32,17 @@ function(include_angelscript)
SET(BUILD_SHARED_LIBS ${SHARED})
SET(LINK_STD_STATICALLY ${STATICC})
SET(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
if (WINDOWS)
SET(MSVC 1)
endif()
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/Angelscript/src/AngelscriptProj/angelscript/projects/cmake
${CMAKE_CURRENT_BINARY_DIR}/Angelscript/bin
EXCLUDE_FROM_ALL)
if (WINDOWS)
set_target_properties(angelscript PROPERTIES SUFFIX ".dll")
endif (WINDOWS)
execute_process(COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/Angelscript/include)
include_directories(SYSTEM ${CMAKE_CURRENT_BINARY_DIR}/Angelscript/src/AngelscriptProj/angelscript/include)
endfunction()

View File

@ -12,8 +12,8 @@ void PkmnLib::Battling::Pokemon::Evolve(ArbUt::BorrowedPtr<const Library::Pokemo
// If the pokemon is genderless, but it's new evolution is not, we want to set its gender
if (_gender != CreatureLib::Library::Gender::Genderless && _species->GetGenderRate() != -1) {
// If we are currently in battle, use the battle random so we can get predictable events.
if (_battle.HasValue()) {
_gender = _species->GetRandomGender(_battle.GetValue()->GetRandom()->GetRNG());
if (_battleData.Battle.HasValue()) {
_gender = _species->GetRandomGender(_battleData.Battle.GetValue()->GetRandom()->GetRNG());
}
// Else create a new random.
else {
@ -34,8 +34,8 @@ void PkmnLib::Battling::Pokemon::SetStatus(const ArbUt::StringView& name) {
}
_statusScript = std::unique_ptr<CreatureLib::Battling::BattleScript>(
_library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Status), name));
if (_battle.HasValue()) {
_battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, name);
if (_battleData.Battle.HasValue()) {
_battleData.Battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, name);
}
}
void PkmnLib::Battling::Pokemon::ClearStatus() {
@ -43,8 +43,8 @@ void PkmnLib::Battling::Pokemon::ClearStatus() {
return;
_statusScript->OnRemove();
_statusScript = nullptr;
if (_battle.HasValue()) {
_battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, ""_cnc);
if (_battleData.Battle.HasValue()) {
_battleData.Battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, ""_cnc);
}
}
@ -69,9 +69,10 @@ CreatureLib::Battling::Creature* PkmnLib::Battling::Pokemon::Clone() const {
c->_statBoost = _statBoost;
c->_flatStats = _flatStats;
c->_boostedStats = _boostedStats;
c->_battle = _battle;
c->_side = _side;
c->_onBattleField = _onBattleField;
c->_battleData.Battle = _battleData.Battle;
c->_battleData.Side = _battleData.Side;
c->_battleData.OnBattleField = _battleData.OnBattleField;
c->_battleData.Index = _battleData.Index;
if (_activeTalent != nullptr) {
c->_activeTalent = std::unique_ptr<PkmnScript::BattleScript>(_activeTalent->Clone());
}

View File

@ -12,7 +12,7 @@ namespace PkmnLib::Battling {
: CreatureLib::Battling::CreatureParty(party) {}
PokemonParty(size_t size) : CreatureLib::Battling::CreatureParty(size) {}
ArbUt::OptionalBorrowedPtr<Pokemon> GetAtIndex(int index) const {
ArbUt::OptionalBorrowedPtr<Pokemon> GetAtIndex(size_t index) const {
return CreatureLib::Battling::CreatureParty::GetAtIndex(index).As<Pokemon>();
}

View File

@ -13,6 +13,7 @@
#include "TypeRegistry/Battling/RegisterBattleClass.hpp"
#include "TypeRegistry/Battling/RegisterBattleLibrary.hpp"
#include "TypeRegistry/Battling/RegisterExecutingAttack.hpp"
#include "TypeRegistry/Battling/RegisterParty.hpp"
#include "TypeRegistry/Battling/RegisterPokemonClass.hpp"
#include "TypeRegistry/Battling/RegisterTurnChoices.hpp"
#include "TypeRegistry/ConstString.hpp"
@ -120,6 +121,7 @@ void AngelScriptResolver::RegisterTypes() {
Ensure(r >= 0);
RegisterPokemonClass::Register(_engine);
RegisterParty::Register(_engine);
RegisterExecutingAttack::Register(_engine);
RegisterTurnChoices::Register(_engine);
RegisterBattleLibrary::Register(_engine);

View File

@ -49,11 +49,22 @@ void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) {
}
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Battle, CreatureLib::Battling::ChoiceQueue, GetCurrentTurnQueue);
CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battle* battle, u8 index) {
return battle->GetSides()[index];
}
CreatureLib::Battling::BattleParty* GetPartyWrapper(PkmnLib::Battling::Battle* battle, u8 index) {
return battle->GetParties()[index];
}
CreatureLib::Battling::BattleParty* FindPartyWrapper(PkmnLib::Battling::Battle* battle, PkmnLib::Battling::Pokemon* p) {
auto v = battle->FindPartyForCreature(p);
if (v.HasValue()) {
return v.GetValue();
}
return {};
}
static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) {
auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
@ -117,4 +128,10 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Battle", "BattleSide@ GetBattleSide(uint8 index)",
asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "Party@ GetParty(uint8 index)", asFUNCTION(GetPartyWrapper),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "Party@ FindPartyForPokemon(Pokemon@ pokemon)",
asFUNCTION(FindPartyWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
}

View File

@ -0,0 +1,36 @@
#include "RegisterParty.hpp"
#include "../../../../Battling/Pokemon/PokemonParty.hpp"
#include "../HelperFile.hpp"
#include <CreatureLib/Battling/Models/BattleParty.hpp>
void RegisterParty::Register(asIScriptEngine* engine) {
RegisterPartyClass(engine);
RegisterBattleParty(engine);
}
static PkmnLib::Battling::Pokemon* GetAtIndexWrapper(PkmnLib::Battling::PokemonParty* obj, size_t i) {
auto v = obj->GetAtIndex(i);
if (v.HasValue()) {
return v.GetValue();
}
return {};
}
void RegisterParty::RegisterPartyClass(asIScriptEngine* engine) {
auto r = engine->RegisterObjectType("Party", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Party", "Pokemon@ GetAtIndex(int index) const", asFUNCTION(GetAtIndexWrapper),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Party", "int get_Length() const property",
asMETHOD(PkmnLib::Battling::PokemonParty, GetLength), asCALL_THISCALL);
Ensure(r >= 0);
}
void RegisterParty::RegisterBattleParty(asIScriptEngine* engine) {
auto r = engine->RegisterObjectType("BattleParty", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleParty", "Party@ get_Party() const property",
asMETHOD(CreatureLib::Battling::BattleParty, GetParty), asCALL_THISCALL);
Ensure(r >= 0);
}

View File

@ -0,0 +1,13 @@
#ifndef PKMNLIB_REGISTERPARTY_HPP
#define PKMNLIB_REGISTERPARTY_HPP
#include <angelscript.h>
class RegisterParty {
static void RegisterPartyClass(asIScriptEngine* engine);
static void RegisterBattleParty(asIScriptEngine* engine);
public:
static void Register(asIScriptEngine* engine);
};
#endif // PKMNLIB_REGISTERPARTY_HPP