mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-23 06:44:38 +01:00
Move ScPlayerGroup into its own files
This commit is contained in:
@@ -781,6 +781,8 @@
|
||||
9DF65BAE250C4307AE5794DB /* ScStaff.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C30AB6C640464647ABE90EC4 /* ScStaff.hpp */; };
|
||||
8E6484F6C43644F4B644D361 /* ScLitter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36C67B84754D4FEFA3678AA9 /* ScLitter.cpp */; };
|
||||
359328A3A65D49578912CA40 /* ScLitter.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C30388F4F6D34DF59EF7072C /* ScLitter.hpp */; };
|
||||
149D1ACFD5FA42938364C843 /* ScPlayerGroup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DA49170D35604E6A986D09D9 /* ScPlayerGroup.cpp */; };
|
||||
97C222A2A4F543E9AEC3912B /* ScPlayerGroup.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 887EBCE57E4A48C88191346E /* ScPlayerGroup.hpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -1864,6 +1866,8 @@
|
||||
C30AB6C640464647ABE90EC4 /* ScStaff.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScStaff.hpp; path = src/openrct2/scripting/bindings/entity/ScStaff.hpp; sourceTree = SOURCE_ROOT; };
|
||||
36C67B84754D4FEFA3678AA9 /* ScLitter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScLitter.cpp; path = src/openrct2/scripting/bindings/entity/ScLitter.cpp; sourceTree = SOURCE_ROOT; };
|
||||
C30388F4F6D34DF59EF7072C /* ScLitter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScLitter.hpp; path = src/openrct2/scripting/bindings/entity/ScLitter.hpp; sourceTree = SOURCE_ROOT; };
|
||||
DA49170D35604E6A986D09D9 /* ScPlayerGroup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScPlayerGroup.cpp; path = src/openrct2/scripting/bindings/network/ScPlayerGroup.cpp; sourceTree = SOURCE_ROOT; };
|
||||
887EBCE57E4A48C88191346E /* ScPlayerGroup.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScPlayerGroup.hpp; path = src/openrct2/scripting/bindings/network/ScPlayerGroup.hpp; sourceTree = SOURCE_ROOT; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -3407,6 +3411,8 @@
|
||||
children = (
|
||||
BDEB01D4A8144819A82E3CB4 /* ScNetwork.hpp */,
|
||||
D4DD54E62DAE4E4889E26DF6 /* ScSocket.hpp */,
|
||||
DA49170D35604E6A986D09D9 /* ScPlayerGroup.cpp */,
|
||||
887EBCE57E4A48C88191346E /* ScPlayerGroup.hpp */,
|
||||
);
|
||||
name = network;
|
||||
sourceTree = "<group>";
|
||||
@@ -3588,6 +3594,7 @@
|
||||
D7B575F07C4D4E42887C72AA /* ScPeep.hpp in Headers */,
|
||||
9DF65BAE250C4307AE5794DB /* ScStaff.hpp in Headers */,
|
||||
359328A3A65D49578912CA40 /* ScLitter.hpp in Headers */,
|
||||
97C222A2A4F543E9AEC3912B /* ScPlayerGroup.hpp in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -4397,6 +4404,7 @@
|
||||
BC39D70B9A2249E4B14E99FA /* ScGuest.cpp in Sources */,
|
||||
7A06F880718F49CA9FB71F52 /* ScStaff.cpp in Sources */,
|
||||
8E6484F6C43644F4B644D361 /* ScLitter.cpp in Sources */,
|
||||
149D1ACFD5FA42938364C843 /* ScPlayerGroup.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -410,6 +410,7 @@
|
||||
<ClInclude Include="scripting\bindings\entity\ScPeep.hpp" />
|
||||
<ClInclude Include="scripting\bindings\entity\ScStaff.hpp" />
|
||||
<ClInclude Include="scripting\bindings\entity\ScVehicle.hpp" />
|
||||
<ClInclude Include="scripting\bindings\network\ScPlayerGroup.hpp" />
|
||||
<ClInclude Include="scripting\Duktape.hpp" />
|
||||
<ClInclude Include="scripting\HookEngine.h" />
|
||||
<ClInclude Include="scripting\Plugin.h" />
|
||||
@@ -858,6 +859,7 @@
|
||||
<ClCompile Include="scripting\bindings\entity\ScLitter.cpp" />
|
||||
<ClCompile Include="scripting\bindings\entity\ScStaff.cpp" />
|
||||
<ClCompile Include="scripting\bindings\entity\ScVehicle.cpp" />
|
||||
<ClCompile Include="scripting\bindings\network\ScPlayerGroup.cpp" />
|
||||
<ClCompile Include="scripting\HookEngine.cpp" />
|
||||
<ClCompile Include="scripting\Plugin.cpp" />
|
||||
<ClCompile Include="scripting\ScriptEngine.cpp" />
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
# include "bindings/game/ScContext.hpp"
|
||||
# include "bindings/game/ScDisposable.hpp"
|
||||
# include "bindings/network/ScNetwork.hpp"
|
||||
# include "bindings/network/ScPlayerGroup.hpp"
|
||||
# include "bindings/network/ScSocket.hpp"
|
||||
# include "bindings/object/ScObject.hpp"
|
||||
# include "bindings/ride/ScRide.hpp"
|
||||
|
||||
@@ -19,140 +19,10 @@
|
||||
# include "../../../network/network.h"
|
||||
# include "../../Duktape.hpp"
|
||||
# include "../network/ScSocket.hpp"
|
||||
# include "ScPlayerGroup.hpp"
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
class ScPlayerGroup
|
||||
{
|
||||
private:
|
||||
int32_t _id;
|
||||
|
||||
public:
|
||||
ScPlayerGroup(int32_t id)
|
||||
: _id(id)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t id_get()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
std::string name_get() const
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto index = network_get_group_index(_id);
|
||||
if (index == -1)
|
||||
return {};
|
||||
return network_get_group_name(index);
|
||||
# else
|
||||
return {};
|
||||
# endif
|
||||
}
|
||||
void name_set(std::string value)
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto action = NetworkModifyGroupAction(ModifyGroupType::SetName, _id, value);
|
||||
GameActions::Execute(&action);
|
||||
# endif
|
||||
}
|
||||
|
||||
std::vector<std::string> permissions_get() const
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto index = network_get_group_index(_id);
|
||||
if (index == -1)
|
||||
return {};
|
||||
|
||||
// Create array of permissions
|
||||
std::vector<std::string> result;
|
||||
auto permissionIndex = 0;
|
||||
for (const auto& action : NetworkActions::Actions)
|
||||
{
|
||||
if (network_can_perform_action(index, static_cast<NetworkPermission>(permissionIndex)))
|
||||
{
|
||||
result.push_back(TransformPermissionKeyToJS(action.PermissionName));
|
||||
}
|
||||
permissionIndex++;
|
||||
}
|
||||
return result;
|
||||
# else
|
||||
return {};
|
||||
# endif
|
||||
}
|
||||
void permissions_set(std::vector<std::string> value)
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto groupIndex = network_get_group_index(_id);
|
||||
if (groupIndex == -1)
|
||||
return;
|
||||
|
||||
// First clear all permissions
|
||||
auto networkAction = NetworkModifyGroupAction(
|
||||
ModifyGroupType::SetPermissions, _id, "", 0, PermissionState::ClearAll);
|
||||
GameActions::Execute(&networkAction);
|
||||
|
||||
std::vector<bool> enabledPermissions;
|
||||
enabledPermissions.resize(NetworkActions::Actions.size());
|
||||
for (const auto& p : value)
|
||||
{
|
||||
auto permissionName = TransformPermissionKeyToInternal(p);
|
||||
|
||||
auto permissionIndex = 0;
|
||||
for (const auto& action : NetworkActions::Actions)
|
||||
{
|
||||
if (action.PermissionName == permissionName)
|
||||
{
|
||||
enabledPermissions[permissionIndex] = true;
|
||||
}
|
||||
permissionIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < enabledPermissions.size(); i++)
|
||||
{
|
||||
auto toggle
|
||||
= (enabledPermissions[i]
|
||||
!= (network_can_perform_action(groupIndex, static_cast<NetworkPermission>(i)) != 0));
|
||||
if (toggle)
|
||||
{
|
||||
auto networkAction2 = NetworkModifyGroupAction(
|
||||
ModifyGroupType::SetPermissions, _id, "", static_cast<uint32_t>(i), PermissionState::Toggle);
|
||||
GameActions::Execute(&networkAction2);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
static void Register(duk_context* ctx)
|
||||
{
|
||||
dukglue_register_property(ctx, &ScPlayerGroup::id_get, nullptr, "id");
|
||||
dukglue_register_property(ctx, &ScPlayerGroup::name_get, &ScPlayerGroup::name_set, "name");
|
||||
dukglue_register_property(ctx, &ScPlayerGroup::permissions_get, &ScPlayerGroup::permissions_set, "permissions");
|
||||
}
|
||||
|
||||
private:
|
||||
static std::string TransformPermissionKeyToJS(const std::string& s)
|
||||
{
|
||||
auto result = s.substr(sizeof("PERMISSION_") - 1);
|
||||
for (auto& c : result)
|
||||
{
|
||||
c = std::tolower(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::string TransformPermissionKeyToInternal(const std::string& s)
|
||||
{
|
||||
auto result = "PERMISSION_" + s;
|
||||
for (auto& c : result)
|
||||
{
|
||||
c = std::toupper(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
class ScPlayer
|
||||
{
|
||||
private:
|
||||
|
||||
150
src/openrct2/scripting/bindings/network/ScPlayerGroup.cpp
Normal file
150
src/openrct2/scripting/bindings/network/ScPlayerGroup.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
|
||||
# include "ScPlayerGroup.hpp"
|
||||
|
||||
# include "../../../Context.h"
|
||||
# include "../../../actions/NetworkModifyGroupAction.h"
|
||||
# include "../../../actions/PlayerSetGroupAction.h"
|
||||
# include "../../../network/NetworkAction.h"
|
||||
# include "../../../network/network.h"
|
||||
# include "../../Duktape.hpp"
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
ScPlayerGroup::ScPlayerGroup(int32_t id)
|
||||
: _id(id)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t ScPlayerGroup::id_get()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
std::string ScPlayerGroup::name_get() const
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto index = network_get_group_index(_id);
|
||||
if (index == -1)
|
||||
return {};
|
||||
return network_get_group_name(index);
|
||||
# else
|
||||
return {};
|
||||
# endif
|
||||
}
|
||||
|
||||
void ScPlayerGroup::name_set(std::string value)
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto action = NetworkModifyGroupAction(ModifyGroupType::SetName, _id, value);
|
||||
GameActions::Execute(&action);
|
||||
# endif
|
||||
}
|
||||
|
||||
static std::string TransformPermissionKeyToJS(const std::string& s)
|
||||
{
|
||||
auto result = s.substr(sizeof("PERMISSION_") - 1);
|
||||
for (auto& c : result)
|
||||
{
|
||||
c = std::tolower(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> ScPlayerGroup::permissions_get() const
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto index = network_get_group_index(_id);
|
||||
if (index == -1)
|
||||
return {};
|
||||
|
||||
// Create array of permissions
|
||||
std::vector<std::string> result;
|
||||
auto permissionIndex = 0;
|
||||
for (const auto& action : NetworkActions::Actions)
|
||||
{
|
||||
if (network_can_perform_action(index, static_cast<NetworkPermission>(permissionIndex)))
|
||||
{
|
||||
result.push_back(TransformPermissionKeyToJS(action.PermissionName));
|
||||
}
|
||||
permissionIndex++;
|
||||
}
|
||||
return result;
|
||||
# else
|
||||
return {};
|
||||
# endif
|
||||
}
|
||||
|
||||
static std::string TransformPermissionKeyToInternal(const std::string& s)
|
||||
{
|
||||
auto result = "PERMISSION_" + s;
|
||||
for (auto& c : result)
|
||||
{
|
||||
c = std::toupper(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ScPlayerGroup::permissions_set(std::vector<std::string> value)
|
||||
{
|
||||
# ifndef DISABLE_NETWORK
|
||||
auto groupIndex = network_get_group_index(_id);
|
||||
if (groupIndex == -1)
|
||||
return;
|
||||
|
||||
// First clear all permissions
|
||||
auto networkAction = NetworkModifyGroupAction(ModifyGroupType::SetPermissions, _id, "", 0, PermissionState::ClearAll);
|
||||
GameActions::Execute(&networkAction);
|
||||
|
||||
std::vector<bool> enabledPermissions;
|
||||
enabledPermissions.resize(NetworkActions::Actions.size());
|
||||
for (const auto& p : value)
|
||||
{
|
||||
auto permissionName = TransformPermissionKeyToInternal(p);
|
||||
|
||||
auto permissionIndex = 0;
|
||||
for (const auto& action : NetworkActions::Actions)
|
||||
{
|
||||
if (action.PermissionName == permissionName)
|
||||
{
|
||||
enabledPermissions[permissionIndex] = true;
|
||||
}
|
||||
permissionIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < enabledPermissions.size(); i++)
|
||||
{
|
||||
auto toggle
|
||||
= (enabledPermissions[i] != (network_can_perform_action(groupIndex, static_cast<NetworkPermission>(i)) != 0));
|
||||
if (toggle)
|
||||
{
|
||||
auto networkAction2 = NetworkModifyGroupAction(
|
||||
ModifyGroupType::SetPermissions, _id, "", static_cast<uint32_t>(i), PermissionState::Toggle);
|
||||
GameActions::Execute(&networkAction2);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
void ScPlayerGroup::Register(duk_context* ctx)
|
||||
{
|
||||
dukglue_register_property(ctx, &ScPlayerGroup::id_get, nullptr, "id");
|
||||
dukglue_register_property(ctx, &ScPlayerGroup::name_get, &ScPlayerGroup::name_set, "name");
|
||||
dukglue_register_property(ctx, &ScPlayerGroup::permissions_get, &ScPlayerGroup::permissions_set, "permissions");
|
||||
}
|
||||
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
#endif
|
||||
41
src/openrct2/scripting/bindings/network/ScPlayerGroup.hpp
Normal file
41
src/openrct2/scripting/bindings/network/ScPlayerGroup.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
|
||||
# include "../../Duktape.hpp"
|
||||
|
||||
# include <string>
|
||||
# include <vector>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
class ScPlayerGroup
|
||||
{
|
||||
int32_t _id;
|
||||
|
||||
public:
|
||||
ScPlayerGroup(int32_t id);
|
||||
|
||||
int32_t id_get();
|
||||
|
||||
std::string name_get() const;
|
||||
void name_set(std::string value);
|
||||
|
||||
std::vector<std::string> permissions_get() const;
|
||||
void permissions_set(std::vector<std::string> value);
|
||||
|
||||
static void Register(duk_context* ctx);
|
||||
};
|
||||
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user