mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-23 02:41:58 -05:00
Add addGroup, removeGroup, groups, players API
This commit is contained in:
parent
06bbf5ddda
commit
7b9fa972b6
2 changed files with 61 additions and 5 deletions
9
distribution/openrct2.d.ts
vendored
9
distribution/openrct2.d.ts
vendored
|
@ -562,13 +562,16 @@ declare global {
|
|||
*/
|
||||
interface Network {
|
||||
readonly mode: NetworkMode;
|
||||
readonly groups: number;
|
||||
readonly players: number;
|
||||
readonly numGroups: number;
|
||||
readonly numPlayers: number;
|
||||
readonly groups: PlayerGroup[];
|
||||
readonly players: Player[];
|
||||
defaultGroup: number;
|
||||
|
||||
getServerInfo(): ServerInfo;
|
||||
addGroup(): void;
|
||||
getGroup(index: number): PlayerGroup;
|
||||
setGroups(groups: PlayerGroup[]): void;
|
||||
removeGroup(index: number): void;
|
||||
getPlayer(index: number): Player;
|
||||
kickPlayer(index: number): void;
|
||||
sendMessage(message: string): void;
|
||||
|
|
|
@ -271,7 +271,7 @@ namespace OpenRCT2::Scripting
|
|||
# endif
|
||||
return "none";
|
||||
}
|
||||
int32_t players_get() const
|
||||
int32_t numPlayers_get() const
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
return network_get_num_players();
|
||||
|
@ -279,7 +279,7 @@ namespace OpenRCT2::Scripting
|
|||
return 0;
|
||||
# endif
|
||||
}
|
||||
int32_t groups_get() const
|
||||
int32_t numGroups_get() const
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
return network_get_num_groups();
|
||||
|
@ -303,6 +303,34 @@ namespace OpenRCT2::Scripting
|
|||
# endif
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<ScPlayerGroup>> groups_get() const
|
||||
{
|
||||
std::vector<std::shared_ptr<ScPlayerGroup>> groups;
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto numGroups = network_get_num_groups();
|
||||
for (int32_t i = 0; i < numGroups; i++)
|
||||
{
|
||||
auto groupId = network_get_group_id(i);
|
||||
groups.push_back(std::make_shared<ScPlayerGroup>(groupId));
|
||||
}
|
||||
# endif
|
||||
return groups;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<ScPlayer>> players_get() const
|
||||
{
|
||||
std::vector<std::shared_ptr<ScPlayer>> players;
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto numPlayers = network_get_num_players();
|
||||
for (int32_t i = 0; i < numPlayers; i++)
|
||||
{
|
||||
auto playerId = network_get_player_id(i);
|
||||
players.push_back(std::make_shared<ScPlayer>(playerId));
|
||||
}
|
||||
# endif
|
||||
return players;
|
||||
}
|
||||
|
||||
std::shared_ptr<ScPlayer> getPlayer(int32_t index) const
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
|
@ -329,6 +357,27 @@ namespace OpenRCT2::Scripting
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void addGroup()
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::AddGroup);
|
||||
GameActions::Execute(&networkModifyGroup);
|
||||
# endif
|
||||
}
|
||||
|
||||
void removeGroup(int32_t index)
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto numGroups = network_get_num_groups();
|
||||
if (index < numGroups)
|
||||
{
|
||||
auto groupId = network_get_group_id(index);
|
||||
auto networkAction = NetworkModifyGroupAction(ModifyGroupType::RemoveGroup, groupId);
|
||||
GameActions::Execute(&networkAction);
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
void kickPlayer(int32_t index)
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
|
@ -359,10 +408,14 @@ namespace OpenRCT2::Scripting
|
|||
static void Register(duk_context* ctx)
|
||||
{
|
||||
dukglue_register_property(ctx, &ScNetwork::mode_get, nullptr, "mode");
|
||||
dukglue_register_property(ctx, &ScNetwork::numGroups_get, nullptr, "numGroups");
|
||||
dukglue_register_property(ctx, &ScNetwork::numPlayers_get, nullptr, "numPlayers");
|
||||
dukglue_register_property(ctx, &ScNetwork::groups_get, nullptr, "groups");
|
||||
dukglue_register_property(ctx, &ScNetwork::players_get, nullptr, "players");
|
||||
dukglue_register_property(ctx, &ScNetwork::defaultGroup_get, &ScNetwork::defaultGroup_set, "defaultGroup");
|
||||
dukglue_register_method(ctx, &ScNetwork::addGroup, "addGroup");
|
||||
dukglue_register_method(ctx, &ScNetwork::getGroup, "getGroup");
|
||||
dukglue_register_method(ctx, &ScNetwork::removeGroup, "removeGroup");
|
||||
dukglue_register_method(ctx, &ScNetwork::getPlayer, "getPlayer");
|
||||
dukglue_register_method(ctx, &ScNetwork::kickPlayer, "kickPlayer");
|
||||
dukglue_register_method(ctx, &ScNetwork::sendMessage, "sendMessage");
|
||||
|
|
Loading…
Reference in a new issue