diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp index 15890bb..2f89ff3 100644 --- a/source/game/StarPlayer.cpp +++ b/source/game/StarPlayer.cpp @@ -35,8 +35,6 @@ #include "StarInspectionTool.hpp" #include "StarUtilityLuaBindings.hpp" #include "StarCelestialLuaBindings.hpp" -#include "StarUniverseClient.hpp" -#include "StarTeamClient.hpp" namespace Star { @@ -295,6 +293,10 @@ void Player::setUniverseClient(UniverseClient* client) { m_questManager->setUniverseClient(client); } +UniverseClient* Player::universeClient() const { + return m_client; +} + EntityType Player::entityType() const { return EntityType::Player; } @@ -2074,20 +2076,6 @@ Vec2F Player::nametagOrigin() const { void Player::updateIdentity() { m_identityUpdated = true; m_humanoid->setIdentity(m_identity); } -JsonArray Player::teamMembers() { - JsonArray jarray; - for (auto member : m_client->teamClient()->members()) { - jarray.push_back(JsonObject{ - {"name", member.name}, - {"uuid", member.uuid.hex()}, - {"entity", member.entity}, - {"healthPercentage", member.healthPercentage}, - {"energyPercentage", member.energyPercentage} - }); - } - return jarray; -} - void Player::setBodyDirectives(String const& directives) { m_identity.bodyDirectives = directives; updateIdentity(); } diff --git a/source/game/StarPlayer.hpp b/source/game/StarPlayer.hpp index fe97fce..1a6a5c2 100644 --- a/source/game/StarPlayer.hpp +++ b/source/game/StarPlayer.hpp @@ -88,6 +88,7 @@ public: void setStatistics(StatisticsPtr statistics); void setUniverseClient(UniverseClient* universeClient); + UniverseClient* universeClient() const; QuestManagerPtr questManager() const; @@ -316,8 +317,6 @@ public: void updateIdentity(); - JsonArray teamMembers(); - void setBodyDirectives(String const& directives); void setEmoteDirectives(String const& directives); diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index 4343531..b0b44a8 100644 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -11,6 +11,8 @@ #include "StarStatistics.hpp" #include "StarPlayerUniverseMap.hpp" #include "StarJsonExtra.hpp" +#include "StarUniverseClient.hpp" +#include "StarTeamClient.hpp" namespace Star { @@ -27,7 +29,19 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { } }); - callbacks.registerCallback("teamMembers", [player]() { return player->teamMembers(); }); + callbacks.registerCallback("teamMembers", [player]() -> Maybe { + if (auto client = player->universeClient()) { + return client->teamClient()->members().transformed([](TeamClient::Member& member) -> Json { + return JsonObject{ + {"name", member.name}, + {"uuid", member.uuid.hex()}, + {"entity", member.entity}, + {"healthPercentage", member.healthPercentage}, + {"energyPercentage", member.energyPercentage}}; + }); + } + return {}; + }); callbacks.registerCallback( "humanoidIdentity", [player]() { return player->humanoid()->identity().toJson(); }); callbacks.registerCallback("setHumanoidIdentity", [player](Json const& id) { player->setIdentity(HumanoidIdentity(id)); });