mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 19:13:25 -08:00
[Refactor] Extract GameCreationOptions from DlgCreateGame (#7800)
* Extract GameCreationOptions from DlgCreateGame * Address review findings
This commit is contained in:
parent
870e4be310
commit
554368967d
6 changed files with 197 additions and 17 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "dlg_create_game.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../interface/widgets/game_hosting/game_creation_options.h"
|
||||
#include "../interface/widgets/tabs/tab_room.h"
|
||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||
#include "libcockatrice/protocol/pb/room_commands.pb.h"
|
||||
|
|
@ -14,6 +15,7 @@
|
|||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QList>
|
||||
#include <QMapIterator>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
|
|
@ -287,32 +289,37 @@ void DlgCreateGame::actReset()
|
|||
|
||||
void DlgCreateGame::actOK()
|
||||
{
|
||||
Command_CreateGame cmd;
|
||||
cmd.set_description(descriptionEdit->text().simplified().toStdString());
|
||||
cmd.set_password(passwordEdit->text().toStdString());
|
||||
cmd.set_max_players(maxPlayersEdit->value());
|
||||
cmd.set_only_buddies(onlyBuddiesCheckBox->isChecked());
|
||||
cmd.set_only_registered(onlyRegisteredCheckBox->isChecked());
|
||||
cmd.set_spectators_allowed(spectatorsAllowedCheckBox->isChecked());
|
||||
cmd.set_spectators_need_password(spectatorsNeedPasswordCheckBox->isChecked());
|
||||
cmd.set_spectators_can_talk(spectatorsCanTalkCheckBox->isChecked());
|
||||
cmd.set_spectators_see_everything(spectatorsSeeEverythingCheckBox->isChecked());
|
||||
cmd.set_join_as_judge(createGameAsJudgeCheckBox->isChecked());
|
||||
cmd.set_join_as_spectator(createGameAsSpectatorCheckBox->isChecked());
|
||||
cmd.set_starting_life_total(startingLifeTotalEdit->value());
|
||||
cmd.set_share_decklists_on_load(shareDecklistsOnLoadCheckBox->isChecked());
|
||||
cmd.set_shuffle_players(shufflePlayersCheckBox->isChecked());
|
||||
|
||||
auto _gameTypes = QString();
|
||||
QList<int> gameTypeIds;
|
||||
QMapIterator<int, QRadioButton *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
|
||||
while (gameTypeCheckBoxIterator.hasNext()) {
|
||||
gameTypeCheckBoxIterator.next();
|
||||
if (gameTypeCheckBoxIterator.value()->isChecked()) {
|
||||
cmd.add_game_type_ids(gameTypeCheckBoxIterator.key());
|
||||
gameTypeIds.append(gameTypeCheckBoxIterator.key());
|
||||
_gameTypes += gameTypeCheckBoxIterator.value()->text() + ", ";
|
||||
}
|
||||
}
|
||||
|
||||
GameCreationOptions options{
|
||||
.description = descriptionEdit->text(),
|
||||
.password = passwordEdit->text(),
|
||||
.maxPlayers = maxPlayersEdit->value(),
|
||||
.onlyBuddies = onlyBuddiesCheckBox->isChecked(),
|
||||
.onlyRegistered = onlyRegisteredCheckBox->isChecked(),
|
||||
.spectatorsAllowed = spectatorsAllowedCheckBox->isChecked(),
|
||||
.spectatorsNeedPassword = spectatorsNeedPasswordCheckBox->isChecked(),
|
||||
.spectatorsCanTalk = spectatorsCanTalkCheckBox->isChecked(),
|
||||
.spectatorsSeeEverything = spectatorsSeeEverythingCheckBox->isChecked(),
|
||||
.joinAsJudge = createGameAsJudgeCheckBox->isChecked(),
|
||||
.joinAsSpectator = createGameAsSpectatorCheckBox->isChecked(),
|
||||
.startingLifeTotal = startingLifeTotalEdit->value(),
|
||||
.shareDecklistsOnLoad = shareDecklistsOnLoadCheckBox->isChecked(),
|
||||
.shufflePlayers = shufflePlayersCheckBox->isChecked(),
|
||||
.gameTypeIds = gameTypeIds,
|
||||
};
|
||||
|
||||
Command_CreateGame cmd = options.toCreateGameCommand();
|
||||
|
||||
SettingsCache::instance().game().setRememberGameSettings(rememberGameSettings->isChecked());
|
||||
if (rememberGameSettings->isChecked()) {
|
||||
SettingsCache::instance().game().setGameDescription(descriptionEdit->text());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
#include "game_creation_options.h"
|
||||
|
||||
Command_CreateGame GameCreationOptions::toCreateGameCommand() const
|
||||
{
|
||||
Command_CreateGame cmd;
|
||||
cmd.set_description(description.simplified().toStdString());
|
||||
cmd.set_password(password.toStdString());
|
||||
cmd.set_max_players(maxPlayers);
|
||||
cmd.set_only_buddies(onlyBuddies);
|
||||
cmd.set_only_registered(onlyRegistered);
|
||||
cmd.set_spectators_allowed(spectatorsAllowed);
|
||||
cmd.set_spectators_need_password(spectatorsNeedPassword);
|
||||
cmd.set_spectators_can_talk(spectatorsCanTalk);
|
||||
cmd.set_spectators_see_everything(spectatorsSeeEverything);
|
||||
cmd.set_join_as_judge(joinAsJudge);
|
||||
cmd.set_join_as_spectator(joinAsSpectator);
|
||||
cmd.set_starting_life_total(startingLifeTotal);
|
||||
cmd.set_share_decklists_on_load(shareDecklistsOnLoad);
|
||||
cmd.set_shuffle_players(shufflePlayers);
|
||||
for (int gameTypeId : gameTypeIds) {
|
||||
cmd.add_game_type_ids(gameTypeId);
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* @file game_creation_options.h
|
||||
* @ingroup RoomWidgets
|
||||
*/
|
||||
|
||||
#ifndef GAME_CREATION_OPTIONS_H
|
||||
#define GAME_CREATION_OPTIONS_H
|
||||
|
||||
#include "libcockatrice/protocol/pb/room_commands.pb.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* @brief The values needed to create a game, independent of the widgets that edit them.
|
||||
*
|
||||
* Pure value object: it holds no widget or settings dependencies, so every host entry
|
||||
* point can build a @ref Command_CreateGame through the same conversion.
|
||||
*/
|
||||
struct GameCreationOptions
|
||||
{
|
||||
QString description;
|
||||
QString password;
|
||||
int maxPlayers = 2;
|
||||
bool onlyBuddies = false;
|
||||
bool onlyRegistered = false;
|
||||
bool spectatorsAllowed = true;
|
||||
bool spectatorsNeedPassword = false;
|
||||
bool spectatorsCanTalk = false;
|
||||
bool spectatorsSeeEverything = false;
|
||||
bool joinAsJudge = false;
|
||||
bool joinAsSpectator = false;
|
||||
int startingLifeTotal = 20;
|
||||
bool shareDecklistsOnLoad = false;
|
||||
bool shufflePlayers = false;
|
||||
QList<int> gameTypeIds;
|
||||
|
||||
/**
|
||||
* @brief Builds the room command, simplifying the description's whitespace.
|
||||
*/
|
||||
[[nodiscard]] Command_CreateGame toCreateGameCommand() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue