From 0745996cb44178380ce7025430e94f1e3fa9bdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 7 Sep 2025 21:14:41 +0200 Subject: [PATCH] Fix regressions. Took 17 minutes Took 9 seconds --- cockatrice/src/client/tabs/tab_game.cpp | 23 +++++++++++--------- cockatrice/src/client/tabs/tab_game.h | 1 + cockatrice/src/game/game_state.h | 4 ++++ cockatrice/src/server/message_log_widget.cpp | 3 +-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index fe3a6d0c3..9b8aa06c3 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -53,8 +53,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay) gameMetaInfo = new GameMetaInfo(); gameState = new GameState(0, -1, -1, _tabSupervisor->getIsLocalGame(), QList(), true, false, false, false, -1, false); - connect(gameState, &GameState::playerAdded, this, &TabGame::addPlayer); - connect(gameState, &GameState::gameStarted, this, &TabGame::startGame); + connectToGameState(); gameEventHandler = new GameEventHandler(this); connectToGameEventHandler(); @@ -101,13 +100,12 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, gameMetaInfo->setRoomGameTypes(_roomGameTypes); gameState = new GameState(0, event.host_id(), event.player_id(), _tabSupervisor->getIsLocalGame(), _clients, event.spectator(), event.judge(), false, event.resuming(), -1, false); + connectToGameState(); // THIS CTOR IS USED ON GAMES gameMetaInfo->setStarted(false); - connect(gameState, &GameState::playerAdded, this, &TabGame::addPlayer); connect(gameMetaInfo, &GameMetaInfo::startedChanged, gameState, &GameState::onStartedChanged); - connect(gameState, &GameState::gameStarted, this, &TabGame::startGame); gameEventHandler = new GameEventHandler(this); connectToGameEventHandler(); @@ -146,6 +144,14 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QTimer::singleShot(0, this, &TabGame::loadLayout); } +void TabGame::connectToGameState() +{ + connect(gameState, &GameState::playerAdded, this, &TabGame::addPlayer); + connect(gameState, &GameState::gameStarted, this, &TabGame::startGame); + connect(gameState, &GameState::activePhaseChanged, this, &TabGame::setActivePhase); + connect(gameState, &GameState::activePlayerChanged, this, &TabGame::setActivePlayer); +} + void TabGame::connectToGameEventHandler() { connect(this, &TabGame::gameLeft, gameEventHandler, &GameEventHandler::handleGameLeft); @@ -230,7 +236,7 @@ void TabGame::resetChatAndPhase() messageLog->clearChat(); // reset phase markers - setActivePhase(-1); + gameState->setCurrentPhase(-1); } void TabGame::emitUserEvent() @@ -826,7 +832,7 @@ Player *TabGame::setActivePlayer(int id) Player *player = gameState->getPlayer(id); if (!player) return nullptr; - gameState->setActivePlayer(id); + playerListWidget->setActivePlayer(id); QMapIterator i(gameState->getPlayers()); while (i.hasNext()) { @@ -848,10 +854,7 @@ Player *TabGame::setActivePlayer(int id) void TabGame::setActivePhase(int phase) { - if (gameState->getCurrentPhase() != phase) { - gameState->setCurrentPhase(phase); - phasesToolbar->setActivePhase(phase); - } + phasesToolbar->setActivePhase(phase); } void TabGame::newCardAdded(AbstractCardItem *card) diff --git a/cockatrice/src/client/tabs/tab_game.h b/cockatrice/src/client/tabs/tab_game.h index a62b1257d..a336ebd4a 100644 --- a/cockatrice/src/client/tabs/tab_game.h +++ b/cockatrice/src/client/tabs/tab_game.h @@ -172,6 +172,7 @@ public: QList &_clients, const Event_GameJoined &event, const QMap &_roomGameTypes); + void connectToGameState(); void connectToGameEventHandler(); void connectMessageLogToGameEventHandler(); void connectPlayerListToGameEventHandler(); diff --git a/cockatrice/src/game/game_state.h b/cockatrice/src/game/game_state.h index 4699f89b4..ed6fdbc49 100644 --- a/cockatrice/src/game/game_state.h +++ b/cockatrice/src/game/game_state.h @@ -146,6 +146,7 @@ public: void setActivePlayer(int activePlayerId) { activePlayer = activePlayerId; + emit activePlayerChanged(activePlayer); } bool getIsLocalGame() const @@ -181,6 +182,7 @@ public: void setCurrentPhase(int phase) { currentPhase = phase; + emit activePhaseChanged(phase); } bool isMainPlayerConceded() const @@ -224,6 +226,8 @@ signals: void spectatorRemoved(int spectatorId, ServerInfo_User spectator); void gameStarted(bool resuming); void gameStopped(); + void activePhaseChanged(int activePhase); + void activePlayerChanged(int playerId); public slots: void incrementGameTime(); diff --git a/cockatrice/src/server/message_log_widget.cpp b/cockatrice/src/server/message_log_widget.cpp index 780ed0b78..b29a68671 100644 --- a/cockatrice/src/server/message_log_widget.cpp +++ b/cockatrice/src/server/message_log_widget.cpp @@ -805,8 +805,7 @@ void MessageLogWidget::connectToPlayer(Player *player) connect(player, &Player::logAttachCard, this, &MessageLogWidget::logAttachCard); connect(player, &Player::logUnattachCard, this, &MessageLogWidget::logUnattachCard); connect(player, &Player::logDumpZone, this, &MessageLogWidget::logDumpZone); - // TODO: Reconnect this - // connect(player, &Player::AlogDrawCards, this, &MessageLogWidget::logDrawCards); + connect(player, &Player::logDrawCards, this, &MessageLogWidget::logDrawCards); connect(player, &Player::logUndoDraw, this, &MessageLogWidget::logUndoDraw); connect(player, &Player::logRevealCards, this, &MessageLogWidget::logRevealCards); connect(player, &Player::logAlwaysRevealTopCard, this, &MessageLogWidget::logAlwaysRevealTopCard);