Merge pull request #131 from KrashV/main

player.teamMembers callback
This commit is contained in:
Kae 2024-10-21 16:55:59 +11:00 committed by GitHub
commit 250869e215
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 0 deletions

View File

@ -527,3 +527,9 @@ Returns uuid, type, and orbits for all system objects in the specified system;
#### `List<String>` player.collectables(`String` collectionName) #### `List<String>` player.collectables(`String` collectionName)
Returns a list of names of the collectables the player has unlocked in the specified collection. Returns a list of names of the collectables the player has unlocked in the specified collection.
---
#### `List<Json>` player.teamMembers()
Returns an array, each entry being a table with `name`, `uuid`, `entity`, `healthPercentage` and `energyPercentage`

View File

@ -293,6 +293,10 @@ void Player::setUniverseClient(UniverseClient* client) {
m_questManager->setUniverseClient(client); m_questManager->setUniverseClient(client);
} }
UniverseClient* Player::universeClient() const {
return m_client;
}
EntityType Player::entityType() const { EntityType Player::entityType() const {
return EntityType::Player; return EntityType::Player;
} }

View File

@ -88,6 +88,7 @@ public:
void setStatistics(StatisticsPtr statistics); void setStatistics(StatisticsPtr statistics);
void setUniverseClient(UniverseClient* universeClient); void setUniverseClient(UniverseClient* universeClient);
UniverseClient* universeClient() const;
QuestManagerPtr questManager() const; QuestManagerPtr questManager() const;

View File

@ -11,6 +11,8 @@
#include "StarStatistics.hpp" #include "StarStatistics.hpp"
#include "StarPlayerUniverseMap.hpp" #include "StarPlayerUniverseMap.hpp"
#include "StarJsonExtra.hpp" #include "StarJsonExtra.hpp"
#include "StarUniverseClient.hpp"
#include "StarTeamClient.hpp"
namespace Star { namespace Star {
@ -27,6 +29,20 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
} }
}); });
callbacks.registerCallback("teamMembers", [player]() -> Maybe<JsonArray> {
if (auto client = player->universeClient()) {
return client->teamClient()->members().transformed([](TeamClient::Member const& 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( "humanoidIdentity", [player]() { return player->humanoid()->identity().toJson(); });
callbacks.registerCallback("setHumanoidIdentity", [player](Json const& id) { player->setIdentity(HumanoidIdentity(id)); }); callbacks.registerCallback("setHumanoidIdentity", [player](Json const& id) { player->setIdentity(HumanoidIdentity(id)); });