Cockatrice/libcockatrice_game/libcockatrice/game/abstract_game.cpp
BruebachL 345b0e8ba9
[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>
2026-10-31 18:44:15 +01:00

62 lines
No EOL
1.6 KiB
C++

#include "abstract_game.h"
#include "game_event_handler.h"
#include "game_meta_info.h"
#include "game_state.h"
#include "libcockatrice/protocol/pb/game_replay.pb.h"
#include "player/player_info.h"
#include "player/player_logic.h"
#include "player/player_manager.h"
#include "zones/card_zone_logic.h"
#include <QList>
#include <QMap>
class AbstractClient;
AbstractGame::AbstractGame(QObject *_parent) : QObject(_parent)
{
gameMetaInfo = new GameMetaInfo(this);
gameEventHandler = new GameEventHandler(this);
}
bool AbstractGame::isHost() const
{
return gameState->getHostId() == playerManager->getLocalPlayerId();
}
AbstractClient *AbstractGame::getClientForPlayer(int playerId) const
{
if (gameState->getClients().size() > 1) {
if (playerId == -1) {
playerId = playerManager->getActiveLocalPlayer(gameState->getActivePlayer())->getPlayerInfo()->getId();
}
return gameState->getClients().at(playerId);
} else if (gameState->getClients().isEmpty()) {
return nullptr;
} else {
return gameState->getClients().first();
}
}
void AbstractGame::loadReplay(const GameReplay *replay)
{
gameMetaInfo->setFromProto(replay->game_info());
gameMetaInfo->setSpectatorsOmniscient(true);
}
CardState *AbstractGame::getCard(int playerId, const QString &zoneName, int cardId) const
{
PlayerLogic *player = playerManager->getPlayer(playerId);
if (!player) {
return nullptr;
}
CardZoneLogic *zone = player->getZones().value(zoneName, 0);
if (!zone) {
return nullptr;
}
return zone->getCard(cardId);
}