Move teamMembers impl to Lua bindings
avoiding including UniverseClient.hpp and TeamClient.hpp in StarPlayer
This commit is contained in:
parent
f270c3f168
commit
e3aa302a8c
@ -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(); }
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<JsonArray> {
|
||||
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)); });
|
||||
|
Loading…
x
Reference in New Issue
Block a user