Player refactor (#6112)

* Player refactor.

Took 1 hour 43 minutes

Took 1 minute


Took 23 seconds

* Tiny lint.

Took 3 minutes

* Hook up tap logic again.

Took 13 minutes

* Fix an include.

Took 3 minutes

* Stuff.

Took 6 minutes

* Fix typo.

Took 7 minutes

* Include.

Took 1 minute

* Reorganize method/variable definitions, remove unused ones.

Took 1 hour 8 minutes


Took 24 seconds

* Clean up some unused imports.

Took 6 minutes

* Player holds the deck, emits deckChanged(), other elements player->getDeck() to respond to changes.

Took 37 minutes

* Connect player->openDeckEditor signal directly in the player constructor

Took 6 minutes

* Emit openDeckEditor signal in player_actions again.

Took 3 minutes

* Do to-do's

Took 3 hours 32 minutes

* Lint.

Took 3 minutes

* Lint again.

Took 2 minutes

* Fix include.

Took 32 minutes

* The stack should ensure card visibility.

Took 21 minutes

* Fine, the game can remember the tab.

Took 10 minutes

Took 21 seconds

Took 9 seconds

* zoneId is a dynamic gameplay property and thus belongs in player.cpp

Took 11 minutes

Took 19 seconds

* Signal view removal, addition.

Took 5 minutes

* Ensure all players are considered local in local game.

Took 10 minutes

* ENSURE they are.

Took 8 minutes

* Bounds check data sent by QAction()

Took 54 minutes

* Move comment.

Took 20 seconds

* Reimplement logging category for game_event_handler.cpp, remove linebreaks.

Took 36 seconds

* PlayerGraphicsItem is responsible for retranslateUi, not Player.


Took 14 seconds

* Set menu for sideboard again, translate some menu titles, reimplement actIncPT action

Took 54 seconds

* Comment spacing.

Took 43 seconds

* Change message_log_widget.cpp slots to take CardZoneLogic parameters as emitted by PlayerEventHandler.

Took 7 minutes

Took 14 seconds

* Remove unused player_logger.cpp

Took 2 minutes

* Query local game state correctly from tab_supervisor again

Took 3 minutes

* Revert Deck legality checker.

Took 3 minutes

* Instantiate menu before graphics item.

Took 1 hour 5 minutes

Took 55 minutes

* Differentiate games and replays.


Took 9 seconds

* Lint.

Took 10 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-09-11 00:49:33 +02:00 committed by GitHub
parent b8e545bfa4
commit 9601a1fa4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
92 changed files with 7104 additions and 5827 deletions

View file

@ -1,13 +1,13 @@
#ifndef COCKATRICE_GAME_STATE_H
#define COCKATRICE_GAME_STATE_H
#include "../client/tabs/tab_game.h"
#include "../server/abstract_client.h"
#include "pb/serverinfo_game.pb.h"
#include "pb/serverinfo_playerproperties.pb.h"
#include <QObject>
#include <QTimer>
class AbstractGame;
class ServerInfo_PlayerProperties;
class ServerInfo_User;
@ -16,149 +16,31 @@ class GameState : public QObject
Q_OBJECT
public:
explicit GameState(int secondsElapsed,
explicit GameState(AbstractGame *_game,
int secondsElapsed,
int hostId,
int localPlayerId,
bool isLocalGame,
QList<AbstractClient *> clients,
bool spectator,
bool judge,
bool gameStateKnown,
bool resuming,
int currentPhase,
bool gameClosed);
const QMap<int, Player *> &getPlayers() const
{
return players;
}
int getPlayerCount() const
{
return players.size();
}
const QMap<int, ServerInfo_User> &getSpectators() const
{
return spectators;
}
ServerInfo_User getSpectator(int playerId) const
{
return spectators.value(playerId);
}
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);
}
bool isHost() const
{
return hostId == localPlayerId;
}
void setHostId(int _hostId)
{
hostId = _hostId;
}
bool isJudge() const
{
return judge;
}
int getLocalPlayerId() const
{
return localPlayerId;
}
QList<AbstractClient *> getClients() const
{
return clients;
}
bool isLocalPlayer(int playerId) const
{
return clients.size() > 1 || playerId == getLocalPlayerId();
}
Player *addPlayer(int playerId, const ServerInfo_User &info, TabGame *game)
{
auto *newPlayer = new Player(info, playerId, isLocalPlayer(playerId), isJudge(), game);
// TODO
// connect(newPlayer, &Player::openDeckEditor, game, &TabGame::openDeckEditor);
players.insert(playerId, newPlayer);
emit playerAdded(newPlayer);
return newPlayer;
}
void removePlayer(int playerId)
{
Player *player = getPlayer(playerId);
if (!player) {
return;
}
players.remove(playerId);
emit playerRemoved(player);
}
Player *getPlayer(int playerId)
{
Player *player = players.value(playerId, 0);
if (!player)
return nullptr;
return player;
}
Player *getActiveLocalPlayer() const
{
Player *active = players.value(activePlayer, 0);
if (active)
if (active->getLocal())
return active;
QMapIterator<int, Player *> playerIterator(players);
while (playerIterator.hasNext()) {
Player *temp = playerIterator.next().value();
if (temp->getLocal())
return temp;
}
return nullptr;
}
void setActivePlayer(int activePlayerId)
{
activePlayer = activePlayerId;
emit activePlayerChanged(activePlayer);
}
bool getIsLocalGame() const
{
return isLocalGame;
}
bool isSpectator() const
{
return spectator;
}
bool isResuming() const
{
return resuming;
@ -185,10 +67,15 @@ public:
emit activePhaseChanged(phase);
}
bool isMainPlayerConceded() const
void setActivePlayer(int activePlayerId)
{
Player *player = players.value(localPlayerId, nullptr);
return player && player->getConceded();
activePlayer = activePlayerId;
emit activePlayerChanged(activePlayer);
}
int getActivePlayer() const
{
return activePlayer;
}
void setGameClosed(bool closed)
@ -213,17 +100,28 @@ public:
void startGameTimer();
QMap<int, QString> getRoomGameTypes() const
{
return roomGameTypes;
}
void setRoomGameTypes(QMap<int, QString> _roomGameTypes)
{
roomGameTypes = _roomGameTypes;
}
void setGameStateKnown(bool known)
{
gameStateKnown = known;
}
int getHostId() const
{
return hostId;
}
signals:
void updateTimeElapsedLabel(QString newTime);
void playerAdded(Player *player);
void playerRemoved(Player *player);
void spectatorAdded(ServerInfo_PlayerProperties spectator);
void spectatorRemoved(int spectatorId, ServerInfo_User spectator);
void gameStarted(bool resuming);
void gameStopped();
void activePhaseChanged(int activePhase);
@ -234,16 +132,13 @@ public slots:
void setGameTime(int _secondsElapsed);
private:
AbstractGame *game;
QTimer *gameTimer;
int secondsElapsed;
QMap<int, QString> roomGameTypes;
int hostId;
int localPlayerId;
const bool isLocalGame;
QMap<int, Player *> players;
QMap<int, ServerInfo_User> spectators;
QList<AbstractClient *> clients;
bool spectator;
bool judge;
bool gameStateKnown;
bool resuming;
QStringList phasesList;