mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
style: Add braces to all control flow statements (#6887)
* style: Add braces to all control flow statements Standardize code style by adding explicit braces to all single-statement control flow blocks (if, else, for, while) across the entire codebase. Also documents the InsertBraces clang-format option (requires v15+) for future automated enforcement. * InsertBraces-check-enabled
This commit is contained in:
parent
7153f7d4c1
commit
aadee34238
173 changed files with 2725 additions and 1461 deletions
|
|
@ -36,8 +36,9 @@ GameEventHandler::GameEventHandler(AbstractGame *_game) : QObject(_game), game(_
|
|||
void GameEventHandler::sendGameCommand(PendingCommand *pend, int playerId)
|
||||
{
|
||||
AbstractClient *client = game->getClientForPlayer(playerId);
|
||||
if (!client)
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
connect(pend, &PendingCommand::finished, this, &GameEventHandler::commandFinished);
|
||||
client->sendCommand(pend);
|
||||
|
|
@ -46,8 +47,9 @@ void GameEventHandler::sendGameCommand(PendingCommand *pend, int playerId)
|
|||
void GameEventHandler::sendGameCommand(const google::protobuf::Message &command, int playerId)
|
||||
{
|
||||
AbstractClient *client = game->getClientForPlayer(playerId);
|
||||
if (!client)
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
PendingCommand *pend = prepareGameCommand(command);
|
||||
connect(pend, &PendingCommand::finished, this, &GameEventHandler::commandFinished);
|
||||
|
|
@ -56,8 +58,9 @@ void GameEventHandler::sendGameCommand(const google::protobuf::Message &command,
|
|||
|
||||
void GameEventHandler::commandFinished(const Response &response)
|
||||
{
|
||||
if (response.response_code() == Response::RespChatFlood)
|
||||
if (response.response_code() == Response::RespChatFlood) {
|
||||
emit gameFlooded();
|
||||
}
|
||||
}
|
||||
|
||||
PendingCommand *GameEventHandler::prepareGameCommand(const ::google::protobuf::Message &cmd)
|
||||
|
|
@ -117,9 +120,11 @@ void GameEventHandler::processGameEventContainer(const GameEventContainer &cont,
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
if ((game->getGameState()->getClients().size() > 1) && (playerId != -1))
|
||||
if (game->getGameState()->getClients().at(playerId) != client)
|
||||
if ((game->getGameState()->getClients().size() > 1) && (playerId != -1)) {
|
||||
if (game->getGameState()->getClients().at(playerId) != client) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch (eventType) {
|
||||
case GameEvent::GAME_STATE_CHANGED:
|
||||
|
|
@ -284,8 +289,9 @@ void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event
|
|||
if (event.game_started() && !game->getGameMetaInfo()->started()) {
|
||||
game->getGameState()->setResuming(!game->getGameState()->isGameStateKnown());
|
||||
game->getGameMetaInfo()->setStarted(event.game_started());
|
||||
if (game->getGameState()->isGameStateKnown())
|
||||
if (game->getGameState()->isGameStateKnown()) {
|
||||
emit logGameStart();
|
||||
}
|
||||
game->getGameState()->setActivePlayer(event.active_player_id());
|
||||
game->getGameState()->setCurrentPhase(event.active_phase());
|
||||
} else if (!event.game_started() && game->getGameMetaInfo()->started()) {
|
||||
|
|
@ -305,8 +311,9 @@ void GameEventHandler::processCardAttachmentsForPlayers(const Event_GameStateCha
|
|||
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
||||
if (!prop.spectator()) {
|
||||
Player *player = game->getPlayerManager()->getPlayers().value(prop.player_id(), 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
continue;
|
||||
}
|
||||
player->processCardAttachment(playerInfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -317,8 +324,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
|||
const GameEventContext &context)
|
||||
{
|
||||
Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
const ServerInfo_PlayerProperties &prop = event.player_properties();
|
||||
emit playerPropertiesChanged(prop, eventPlayerId);
|
||||
|
||||
|
|
@ -326,8 +334,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
|||
switch (contextType) {
|
||||
case GameEventContext::READY_START: {
|
||||
bool ready = prop.ready_start();
|
||||
if (player->getPlayerInfo()->getLocal())
|
||||
if (player->getPlayerInfo()->getLocal()) {
|
||||
emit localPlayerReadyStateChanged(player->getPlayerInfo()->getId(), ready);
|
||||
}
|
||||
if (ready) {
|
||||
emit logReadyStart(player);
|
||||
} else {
|
||||
|
|
@ -339,8 +348,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
|||
player->setConceded(true);
|
||||
|
||||
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||
while (playerIterator.hasNext())
|
||||
while (playerIterator.hasNext()) {
|
||||
playerIterator.next().value()->updateZones();
|
||||
}
|
||||
|
||||
emit logConcede(eventPlayerId);
|
||||
|
||||
|
|
@ -350,8 +360,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
|||
player->setConceded(false);
|
||||
|
||||
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||
while (playerIterator.hasNext())
|
||||
while (playerIterator.hasNext()) {
|
||||
playerIterator.next().value()->updateZones();
|
||||
}
|
||||
|
||||
emit logUnconcede(eventPlayerId);
|
||||
|
||||
|
|
@ -389,8 +400,9 @@ void GameEventHandler::eventJoin(const Event_Join &event, int /*eventPlayerId*/,
|
|||
QString playerName = QString::fromStdString(playerInfo.user_info().name());
|
||||
emit addPlayerToAutoCompleteList(playerName);
|
||||
|
||||
if (game->getPlayerManager()->getPlayers().contains(playerId))
|
||||
if (game->getPlayerManager()->getPlayers().contains(playerId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playerInfo.spectator()) {
|
||||
game->getPlayerManager()->addSpectator(playerId, playerInfo);
|
||||
|
|
@ -426,8 +438,9 @@ QString GameEventHandler::getLeaveReason(Event_Leave::LeaveReason reason)
|
|||
void GameEventHandler::eventLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext & /*context*/)
|
||||
{
|
||||
Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
|
||||
player->clear();
|
||||
emit playerLeft(eventPlayerId);
|
||||
|
|
@ -440,8 +453,9 @@ void GameEventHandler::eventLeave(const Event_Leave &event, int eventPlayerId, c
|
|||
|
||||
// Rearrange all remaining zones so that attachment relationship updates take place
|
||||
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||
while (playerIterator.hasNext())
|
||||
while (playerIterator.hasNext()) {
|
||||
playerIterator.next().value()->updateZones();
|
||||
}
|
||||
|
||||
emitUserEvent();
|
||||
}
|
||||
|
|
@ -461,8 +475,9 @@ void GameEventHandler::eventReverseTurn(const Event_ReverseTurn &event,
|
|||
const GameEventContext & /*context*/)
|
||||
{
|
||||
Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit logTurnReversed(player, event.reversed());
|
||||
}
|
||||
|
|
@ -491,8 +506,9 @@ void GameEventHandler::eventSetActivePlayer(const Event_SetActivePlayer &event,
|
|||
{
|
||||
game->getGameState()->setActivePlayer(event.active_player_id());
|
||||
Player *player = game->getPlayerManager()->getPlayer(event.active_player_id());
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
emit logActivePlayer(player);
|
||||
emitUserEvent();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue