mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-12 21:10:01 -08:00
[Refactor] Move game logic into libcockatrice_game (#7437)
* [Refactor] Move game logic into libcockatrice_game * [Refactor] Include card_state.h in player_actions.h * [Game] Inject settings providers into libcockatrice_game, drop Widgets * [Game] Follow base rename to createCardRequested after rebase * [Game] Drop unused CardItem forward declaration * [Game] Fix includes after moving game logic into libcockatrice_game --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
78964779c6
commit
345b0e8ba9
108 changed files with 598 additions and 281 deletions
|
|
@ -1,128 +0,0 @@
|
|||
/**
|
||||
* @file player_manager.h
|
||||
* @ingroup GameLogicPlayers
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_PLAYER_MANAGER_H
|
||||
#define COCKATRICE_PLAYER_MANAGER_H
|
||||
|
||||
#include "libcockatrice/protocol/pb/serverinfo_user.pb.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_playerproperties.pb.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
class AbstractGame;
|
||||
class PlayerLogic;
|
||||
|
||||
class PlayerManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlayerManager(AbstractGame *_game, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator);
|
||||
|
||||
AbstractGame *game;
|
||||
QMap<int, PlayerLogic *> players;
|
||||
int localPlayerId;
|
||||
bool localPlayerIsJudge;
|
||||
bool localPlayerIsSpectator;
|
||||
QMap<int, ServerInfo_User> spectators;
|
||||
|
||||
[[nodiscard]] bool isSpectator() const
|
||||
{
|
||||
return localPlayerIsSpectator;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isJudge() const
|
||||
{
|
||||
return localPlayerIsJudge;
|
||||
}
|
||||
|
||||
[[nodiscard]] int getLocalPlayerId() const
|
||||
{
|
||||
return localPlayerId;
|
||||
}
|
||||
|
||||
[[nodiscard]] const QMap<int, PlayerLogic *> &getPlayers() const
|
||||
{
|
||||
return players;
|
||||
}
|
||||
|
||||
[[nodiscard]] int getPlayerCount() const
|
||||
{
|
||||
return players.size();
|
||||
}
|
||||
|
||||
[[nodiscard]] PlayerLogic *getActiveLocalPlayer(int activePlayer) const;
|
||||
bool isLocalPlayer(int playerId);
|
||||
|
||||
PlayerLogic *addPlayer(int playerId, const ServerInfo_User &info);
|
||||
|
||||
void removePlayer(int playerId);
|
||||
|
||||
[[nodiscard]] PlayerLogic *getPlayer(int playerId) const;
|
||||
|
||||
void onPlayerConceded(int playerId, bool conceded);
|
||||
|
||||
[[nodiscard]] bool isMainPlayerConceded() const;
|
||||
|
||||
[[nodiscard]] bool isLocalPlayer(int playerId) const
|
||||
{
|
||||
return playerId == getLocalPlayerId();
|
||||
}
|
||||
|
||||
[[nodiscard]] const QMap<int, ServerInfo_User> &getSpectators() const
|
||||
{
|
||||
return spectators;
|
||||
}
|
||||
|
||||
[[nodiscard]] ServerInfo_User getSpectator(int playerId) const
|
||||
{
|
||||
return spectators.value(playerId);
|
||||
}
|
||||
|
||||
[[nodiscard]] QString getSpectatorName(int spectatorId) const
|
||||
{
|
||||
return QString::fromStdString(spectators.value(spectatorId).name());
|
||||
}
|
||||
|
||||
void addSpectator(int spectatorId, const ServerInfo_PlayerProperties &prop)
|
||||
{
|
||||
if (!spectators.contains(spectatorId)) {
|
||||
spectators.insert(spectatorId, prop.user_info());
|
||||
emit spectatorAdded(prop);
|
||||
}
|
||||
}
|
||||
|
||||
void removeSpectator(int spectatorId)
|
||||
{
|
||||
ServerInfo_User spectatorInfo = spectators.value(spectatorId);
|
||||
spectators.remove(spectatorId);
|
||||
emit spectatorRemoved(spectatorId, spectatorInfo);
|
||||
}
|
||||
|
||||
/** @brief Remove all spectators, emitting the removal signal for each. */
|
||||
void clearSpectators();
|
||||
|
||||
[[nodiscard]] AbstractGame *getGame() const
|
||||
{
|
||||
return game;
|
||||
}
|
||||
|
||||
signals:
|
||||
void playerAdded(PlayerLogic *player);
|
||||
void playerRemoved(PlayerLogic *player);
|
||||
void activeLocalPlayerConceded();
|
||||
void activeLocalPlayerUnconceded();
|
||||
void playerConceded(int playerId);
|
||||
void playerUnconceded(int playerId);
|
||||
void playerCountChanged();
|
||||
void spectatorAdded(ServerInfo_PlayerProperties spectator);
|
||||
void spectatorRemoved(int spectatorId, ServerInfo_User spectator);
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_MANAGER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue