Cockatrice/cockatrice/src/game/game_state.cpp
BruebachL 750d5b3c21
[Client] Add option to use game time in game log timestamps (#7265)
* [Client] Add option to use game time in game log timestamps (#2202)

Game log timestamps showed the local clock time, which is meaningless in
a replay or in a log read after the fact — nobody can tell when a play
happened relative to the game.

Add a "Use game time instead of local time in game logs" setting. When
enabled, the message log stamps entries with the elapsed game time
(HH:MM:SS since the game started); regular chat views keep the local
clock.

* [Game] Move formatElapsedTime helper out of public slots (#2202)

The message log needs the HH:MM:SS formatter used by the game timer, but
it lives in GameState's public slots, tying a pure formatting helper to
the signal-slot machinery.

Move formatElapsedTime into a public section of GameState so the log can
call it directly, and add the missing trailing newline to game_state.cpp.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-10-02 17:30:48 +02:00

45 lines
1.5 KiB
C++

#include "game_state.h"
#include "abstract_game.h"
GameState::GameState(AbstractGame *parent,
int _secondsElapsed,
int _hostId,
bool _isLocalGame,
const QList<AbstractClient *> _clients,
bool _gameStateKnown,
bool _resuming,
int _currentPhase,
bool _gameClosed)
: QObject(parent), gameTimer(nullptr), secondsElapsed(_secondsElapsed), hostId(_hostId), isLocalGame(_isLocalGame),
clients(_clients), gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase),
activePlayer(-1), gameClosed(_gameClosed)
{
gameTimer = new QTimer(this);
gameTimer->setInterval(1000);
connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime);
gameTimer->start();
}
void GameState::incrementGameTime()
{
setGameTime(++secondsElapsed);
}
void GameState::setGameTime(int _secondsElapsed)
{
secondsElapsed = _secondsElapsed;
emit updateTimeElapsedLabel(formatElapsedTime(_secondsElapsed));
}
QString GameState::formatElapsedTime(int _secondsElapsed)
{
int seconds = _secondsElapsed;
int minutes = seconds / 60;
seconds -= minutes * 60;
int hours = minutes / 60;
minutes -= hours * 60;
return QString::number(hours).rightJustified(2, '0') + ":" + QString::number(minutes).rightJustified(2, '0') + ":" +
QString::number(seconds).rightJustified(2, '0');
}