refactor(PlayerService): Split classes into multiple files (#310)
This commit is contained in:
parent
f41b44478b
commit
6624060398
84
BigBaseV2/src/services/players/player.cpp
Normal file
84
BigBaseV2/src/services/players/player.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#include "player.hpp"
|
||||||
|
#include "CNetGamePlayer.hpp"
|
||||||
|
#include "services/friends/friends_service.hpp"
|
||||||
|
|
||||||
|
namespace big
|
||||||
|
{
|
||||||
|
player::player(CNetGamePlayer* net_game_player)
|
||||||
|
: m_net_game_player(net_game_player)
|
||||||
|
{
|
||||||
|
m_is_friend = friends_service::is_friend(net_game_player);
|
||||||
|
}
|
||||||
|
|
||||||
|
CAutomobile* player::get_current_vehicle() const
|
||||||
|
{
|
||||||
|
if (const auto ped = this->get_ped(); ped != nullptr)
|
||||||
|
if (const auto vehicle = ped->m_vehicle; vehicle != nullptr)
|
||||||
|
return vehicle;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* player::get_name() const
|
||||||
|
{
|
||||||
|
return m_net_game_player == nullptr ? "" : m_net_game_player->get_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
rage::netPlayerData* player::get_net_data() const
|
||||||
|
{
|
||||||
|
return m_net_game_player == nullptr ? nullptr : m_net_game_player->get_net_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
CNetGamePlayer* player::get_net_game_player() const
|
||||||
|
{
|
||||||
|
return m_net_game_player;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPed* player::get_ped() const
|
||||||
|
{
|
||||||
|
if (const auto player_info = this->get_player_info(); player_info != nullptr)
|
||||||
|
if (const auto ped = player_info->m_ped; ped != nullptr)
|
||||||
|
return ped;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPlayerInfo* player::get_player_info() const
|
||||||
|
{
|
||||||
|
if (m_net_game_player != nullptr && m_net_game_player->m_player_info != nullptr)
|
||||||
|
return m_net_game_player->m_player_info;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t player::id() const
|
||||||
|
{
|
||||||
|
return m_net_game_player == nullptr ? -1 : m_net_game_player->m_player_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool player::is_host() const
|
||||||
|
{
|
||||||
|
return m_net_game_player == nullptr ? false : m_net_game_player->is_host();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool player::is_friend() const
|
||||||
|
{
|
||||||
|
return m_is_friend;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool player::is_valid() const
|
||||||
|
{
|
||||||
|
return m_net_game_player == nullptr ? false : m_net_game_player->is_valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool player::equals(const CNetGamePlayer* net_game_player) const
|
||||||
|
{
|
||||||
|
return net_game_player == m_net_game_player;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string player::to_lowercase_identifier() const
|
||||||
|
{
|
||||||
|
std::string lower = this->get_name();
|
||||||
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
||||||
|
|
||||||
|
return lower;
|
||||||
|
}
|
||||||
|
}
|
45
BigBaseV2/src/services/players/player.hpp
Normal file
45
BigBaseV2/src/services/players/player.hpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "player_service.hpp"
|
||||||
|
|
||||||
|
namespace big
|
||||||
|
{
|
||||||
|
class player final
|
||||||
|
{
|
||||||
|
friend class player_service;
|
||||||
|
|
||||||
|
CNetGamePlayer* m_net_game_player = nullptr;
|
||||||
|
std::string m_identifier;
|
||||||
|
bool m_is_friend;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit player(CNetGamePlayer* net_game_player);
|
||||||
|
~player() = default;
|
||||||
|
|
||||||
|
player(const player&) = default;
|
||||||
|
player(player&&) noexcept = default;
|
||||||
|
player& operator=(const player&) = default;
|
||||||
|
player& operator=(player&&) noexcept = default;
|
||||||
|
|
||||||
|
float screen_position_x = -1.f;
|
||||||
|
float screen_position_y = -1.f;
|
||||||
|
|
||||||
|
[[nodiscard]] CAutomobile* get_current_vehicle() const;
|
||||||
|
[[nodiscard]] const char* get_name() const;
|
||||||
|
[[nodiscard]] rage::netPlayerData* get_net_data() const;
|
||||||
|
[[nodiscard]] CNetGamePlayer* get_net_game_player() const;
|
||||||
|
[[nodiscard]] CPed* get_ped() const;
|
||||||
|
[[nodiscard]] CPlayerInfo* get_player_info() const;
|
||||||
|
|
||||||
|
[[nodiscard]] uint8_t id() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool is_friend() const;
|
||||||
|
[[nodiscard]] bool is_host() const;
|
||||||
|
[[nodiscard]] bool is_valid() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool equals(const CNetGamePlayer* net_game_player) const;
|
||||||
|
|
||||||
|
[[nodiscard]] std::string to_lowercase_identifier() const;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
@ -1,89 +1,10 @@
|
|||||||
#include "gta_util.hpp"
|
#include "gta_util.hpp"
|
||||||
#include "player_service.hpp"
|
#include "player_service.hpp"
|
||||||
#include "services/friends/friends_service.hpp"
|
|
||||||
|
|
||||||
namespace big
|
namespace big
|
||||||
{
|
{
|
||||||
player::player(CNetGamePlayer* net_game_player)
|
|
||||||
: m_net_game_player(net_game_player)
|
|
||||||
{
|
|
||||||
m_is_friend = friends_service::is_friend(net_game_player);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAutomobile* player::get_current_vehicle() const
|
|
||||||
{
|
|
||||||
if (const auto ped = this->get_ped(); ped != nullptr)
|
|
||||||
if (const auto vehicle = ped->m_vehicle; vehicle != nullptr)
|
|
||||||
return vehicle;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* player::get_name() const
|
|
||||||
{
|
|
||||||
return m_net_game_player == nullptr ? "" : m_net_game_player->get_name();
|
|
||||||
}
|
|
||||||
|
|
||||||
rage::netPlayerData* player::get_net_data() const
|
|
||||||
{
|
|
||||||
return m_net_game_player == nullptr ? nullptr : m_net_game_player->get_net_data();
|
|
||||||
}
|
|
||||||
|
|
||||||
CNetGamePlayer* player::get_net_game_player() const
|
|
||||||
{
|
|
||||||
return m_net_game_player;
|
|
||||||
}
|
|
||||||
|
|
||||||
CPed* player::get_ped() const
|
|
||||||
{
|
|
||||||
if (const auto player_info = this->get_player_info(); player_info != nullptr)
|
|
||||||
if (const auto ped = player_info->m_ped; ped != nullptr)
|
|
||||||
return ped;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
CPlayerInfo* player::get_player_info() const
|
|
||||||
{
|
|
||||||
if (m_net_game_player != nullptr && m_net_game_player->m_player_info != nullptr)
|
|
||||||
return m_net_game_player->m_player_info;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t player::id() const
|
|
||||||
{
|
|
||||||
return m_net_game_player == nullptr ? -1 : m_net_game_player->m_player_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool player::is_host() const
|
|
||||||
{
|
|
||||||
return m_net_game_player == nullptr ? false : m_net_game_player->is_host();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool player::is_friend() const
|
|
||||||
{
|
|
||||||
return m_is_friend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool player::is_valid() const
|
|
||||||
{
|
|
||||||
return m_net_game_player == nullptr ? false : m_net_game_player->is_valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool player::equals(const CNetGamePlayer* net_game_player) const
|
|
||||||
{
|
|
||||||
return net_game_player == m_net_game_player;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string player::to_lowercase_identifier() const
|
|
||||||
{
|
|
||||||
std::string lower = this->get_name();
|
|
||||||
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
||||||
|
|
||||||
return lower;
|
|
||||||
}
|
|
||||||
|
|
||||||
player_service::player_service()
|
player_service::player_service()
|
||||||
: m_selected_player(m_dummy)
|
: m_self(), m_selected_player(m_dummy)
|
||||||
{
|
{
|
||||||
g_player_service = this;
|
g_player_service = this;
|
||||||
|
|
||||||
|
@ -1,47 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "player.hpp"
|
||||||
|
|
||||||
namespace big
|
namespace big
|
||||||
{
|
{
|
||||||
class player_service;
|
class player;
|
||||||
class player final
|
|
||||||
{
|
|
||||||
friend player_service;
|
|
||||||
|
|
||||||
CNetGamePlayer* m_net_game_player = nullptr;
|
|
||||||
std::string m_identifier;
|
|
||||||
bool m_is_friend;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit player(CNetGamePlayer* net_game_player);
|
|
||||||
~player() = default;
|
|
||||||
|
|
||||||
player(const player&) = default;
|
|
||||||
player(player&&) noexcept = default;
|
|
||||||
player& operator=(const player&) = default;
|
|
||||||
player& operator=(player&&) noexcept = default;
|
|
||||||
|
|
||||||
float screen_position_x = -1.f;
|
|
||||||
float screen_position_y = -1.f;
|
|
||||||
|
|
||||||
[[nodiscard]] CAutomobile* get_current_vehicle() const;
|
|
||||||
[[nodiscard]] const char* get_name() const;
|
|
||||||
[[nodiscard]] rage::netPlayerData* get_net_data() const;
|
|
||||||
[[nodiscard]] CNetGamePlayer* get_net_game_player() const;
|
|
||||||
[[nodiscard]] CPed* get_ped() const;
|
|
||||||
[[nodiscard]] CPlayerInfo* get_player_info() const;
|
|
||||||
|
|
||||||
[[nodiscard]] uint8_t id() const;
|
|
||||||
|
|
||||||
[[nodiscard]] bool is_friend() const;
|
|
||||||
[[nodiscard]] bool is_host() const;
|
|
||||||
[[nodiscard]] bool is_valid() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool equals(const CNetGamePlayer* net_game_player) const;
|
|
||||||
|
|
||||||
[[nodiscard]] std::string to_lowercase_identifier() const;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
using player_ptr = std::shared_ptr<player>;
|
using player_ptr = std::shared_ptr<player>;
|
||||||
using players = std::map<std::string, player_ptr>;
|
using players = std::map<std::string, player_ptr>;
|
||||||
|
Reference in New Issue
Block a user