[Refactor] Split CreateGameFormWidget out of DlgCreateGame (#7801)

* Extract CreateGameFormWidget from DlgCreateGame

* Address review findings
This commit is contained in:
BruebachL 2026-11-08 16:22:31 +01:00 • committed by GitHub
parent 554368967d
commit 39220a2ea9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 864 additions and 325 deletions

View file

@ -1,5 +1,69 @@
#include "game_creation_options.h"
#include <QSet>
#include <libcockatrice/interfaces/interface_game_settings_provider.h>
#include <libcockatrice/protocol/pb/serverinfo_game.pb.h>
GameCreationOptions GameCreationOptions::fromSettings(const IGameSettingsProvider &settings,
const QMap<int, QString> &gameTypes,
bool registeredUser)
{
GameCreationOptions options;
options.description = settings.getGameDescription();
options.maxPlayers = settings.getMaxPlayers();
if (registeredUser) {
options.onlyBuddies = settings.getOnlyBuddies();
options.onlyRegistered = settings.getOnlyRegistered();
}
options.spectatorsAllowed = settings.getSpectatorsAllowed();
options.spectatorsNeedPassword = settings.getSpectatorsNeedPassword();
options.spectatorsCanTalk = settings.getSpectatorsCanTalk();
options.spectatorsSeeEverything = settings.getSpectatorsCanSeeEverything();
options.joinAsSpectator = settings.getCreateGameAsSpectator();
options.startingLifeTotal = settings.getDefaultStartingLifeTotal();
options.shareDecklistsOnLoad = settings.getShareDecklistsOnLoad();
options.shufflePlayers = settings.getShufflePlayers();
// The old dialog stored game type names as "Name, " in one string; keep the exact
// substring test so an existing game.ini selects the same types after the split.
const QString savedGameTypes = settings.getGameTypes();
for (auto it = gameTypes.cbegin(); it != gameTypes.cend(); ++it) {
if (savedGameTypes.contains(it.value() + ", ")) {
options.gameTypeIds.append(it.key());
}
}
return options;
}
GameCreationOptions GameCreationOptions::fromGameInfo(const ServerInfo_Game &gameInfo,
const QMap<int, QString> &gameTypes)
{
GameCreationOptions options;
options.description = QString::fromStdString(gameInfo.description());
options.maxPlayers = gameInfo.max_players();
options.onlyBuddies = gameInfo.only_buddies();
options.onlyRegistered = gameInfo.only_registered();
options.spectatorsAllowed = gameInfo.spectators_allowed();
options.spectatorsNeedPassword = gameInfo.spectators_need_password();
options.spectatorsCanTalk = gameInfo.spectators_can_chat();
options.spectatorsSeeEverything = gameInfo.spectators_omniscient();
options.shareDecklistsOnLoad = gameInfo.share_decklists_on_load();
options.shufflePlayers = gameInfo.shuffle_players();
QSet<int> selectedTypes;
for (int i = 0; i < gameInfo.game_types_size(); ++i) {
selectedTypes.insert(gameInfo.game_types(i));
}
for (auto it = gameTypes.cbegin(); it != gameTypes.cend(); ++it) {
if (selectedTypes.contains(it.key())) {
options.gameTypeIds.append(it.key());
}
}
return options;
}
Command_CreateGame GameCreationOptions::toCreateGameCommand() const
{
Command_CreateGame cmd;