mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-06 10:03:26 -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,100 +0,0 @@
|
|||
#include "player_manager.h"
|
||||
|
||||
#include "../abstract_game.h"
|
||||
#include "../game_state.h"
|
||||
#include "player_info.h"
|
||||
#include "player_logic.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QMapIterator>
|
||||
#include <QSharedPointer>
|
||||
|
||||
PlayerManager::PlayerManager(AbstractGame *_game,
|
||||
int _localPlayerId,
|
||||
bool _localPlayerIsJudge,
|
||||
bool localPlayerIsSpectator)
|
||||
: QObject(_game), game(_game), players(QMap<int, PlayerLogic *>()), localPlayerId(_localPlayerId),
|
||||
localPlayerIsJudge(_localPlayerIsJudge), localPlayerIsSpectator(localPlayerIsSpectator)
|
||||
{
|
||||
}
|
||||
|
||||
bool PlayerManager::isMainPlayerConceded() const
|
||||
{
|
||||
PlayerLogic *player = players.value(localPlayerId, nullptr);
|
||||
return player && player->getConceded();
|
||||
}
|
||||
|
||||
PlayerLogic *PlayerManager::getActiveLocalPlayer(int activePlayer) const
|
||||
{
|
||||
PlayerLogic *active = players.value(activePlayer, 0);
|
||||
if (active) {
|
||||
if (active->getPlayerInfo()->getLocal()) {
|
||||
return active;
|
||||
}
|
||||
}
|
||||
|
||||
QMapIterator<int, PlayerLogic *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
PlayerLogic *temp = playerIterator.next().value();
|
||||
if (temp->getPlayerInfo()->getLocal()) {
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PlayerManager::isLocalPlayer(int playerId)
|
||||
{
|
||||
return game->getGameState()->getIsLocalGame() || playerId == localPlayerId;
|
||||
}
|
||||
|
||||
PlayerLogic *PlayerManager::addPlayer(int playerId, const ServerInfo_User &info)
|
||||
{
|
||||
auto *newPlayer = new PlayerLogic(info, playerId, isLocalPlayer(playerId) || game->getGameState()->getIsLocalGame(),
|
||||
isJudge(), getGame());
|
||||
connect(newPlayer, &PlayerLogic::concededChanged, this, &PlayerManager::onPlayerConceded);
|
||||
players.insert(playerId, newPlayer);
|
||||
emit playerAdded(newPlayer);
|
||||
emit playerCountChanged();
|
||||
return newPlayer;
|
||||
}
|
||||
|
||||
void PlayerManager::removePlayer(int playerId)
|
||||
{
|
||||
PlayerLogic *player = getPlayer(playerId);
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
emit playerRemoved(player);
|
||||
emit playerCountChanged();
|
||||
players.remove(playerId);
|
||||
player->deleteLater();
|
||||
}
|
||||
|
||||
PlayerLogic *PlayerManager::getPlayer(int playerId) const
|
||||
{
|
||||
PlayerLogic *player = players.value(playerId, 0);
|
||||
if (!player) {
|
||||
return nullptr;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
void PlayerManager::clearSpectators()
|
||||
{
|
||||
const QList<int> spectatorIds = spectators.keys();
|
||||
for (int spectatorId : spectatorIds) {
|
||||
removeSpectator(spectatorId);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerManager::onPlayerConceded(int playerId, bool conceded)
|
||||
{
|
||||
// Everything else cares about this
|
||||
if (conceded) {
|
||||
emit playerConceded(playerId);
|
||||
} else {
|
||||
emit playerUnconceded(playerId);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue