diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index 5e5c9e6cf..391598cbc 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -294,12 +294,16 @@ void DeckViewContainer::loadLocalDeck() if (!dialog.exec()) return; - QString fileName = dialog.selectedFiles().at(0); - DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName); + loadDeckFromFile(dialog.selectedFiles().at(0)); +} + +void DeckViewContainer::loadDeckFromFile(const QString &filePath) +{ + DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(filePath); QString deckString; DeckLoader deck; - bool error = !deck.loadFromFile(fileName, fmt); + bool error = !deck.loadFromFile(filePath, fmt); if (!error) { deckString = deck.writeToString_Native(); error = deckString.length() > MAX_FILE_LENGTH; @@ -378,6 +382,18 @@ void DeckViewContainer::setReadyStart(bool ready) sideboardLockButton->setEnabled(!readyStartButton->getState() && readyStartButton->isEnabled()); } +/** + * Sets the ready start to true, then sends the ready command so the server responds to the update + */ +void DeckViewContainer::readyAndUpdate() +{ + setReadyStart(true); + + Command_ReadyStart cmd; + cmd.set_ready(true); + parentGame->sendGameCommand(cmd, playerId); +} + void DeckViewContainer::setSideboardLocked(bool locked) { sideboardLockButton->setState(!locked); @@ -860,6 +876,15 @@ Player *TabGame::addPlayer(int playerId, const ServerInfo_User &info) connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *))); deckViewContainers.insert(playerId, deckView); deckViewContainerLayout->addWidget(deckView); + + // auto load deck for player if that debug setting is enabled + QString deckPath = SettingsCache::instance().debug().getDeckPathForPlayer(newPlayer->getName()); + if (!deckPath.isEmpty()) { + QTimer::singleShot(0, this, [deckView, deckPath] { + deckView->loadDeckFromFile(deckPath); + deckView->readyAndUpdate(); + }); + } } gameMenu->insertMenu(playersSeparator, newPlayer->getPlayerMenu()); diff --git a/cockatrice/src/client/tabs/tab_game.h b/cockatrice/src/client/tabs/tab_game.h index 0cabc697c..6b6af48d9 100644 --- a/cockatrice/src/client/tabs/tab_game.h +++ b/cockatrice/src/client/tabs/tab_game.h @@ -110,8 +110,10 @@ public: void retranslateUi(); void setButtonsVisible(bool _visible); void setReadyStart(bool ready); + void readyAndUpdate(); void setSideboardLocked(bool locked); void setDeck(const DeckLoader &deck); + void loadDeckFromFile(const QString &filePath); }; class TabGame : public Tab diff --git a/cockatrice/src/settings/debug_settings.cpp b/cockatrice/src/settings/debug_settings.cpp index a329e58a9..75276a091 100644 --- a/cockatrice/src/settings/debug_settings.cpp +++ b/cockatrice/src/settings/debug_settings.cpp @@ -24,4 +24,9 @@ bool DebugSettings::getLocalGameOnStartup() int DebugSettings::getLocalGamePlayerCount() { return getValue("playerCount", "localgame").toInt(); +} + +QString DebugSettings::getDeckPathForPlayer(const QString &playerName) +{ + return getValue(playerName, "localgame", "deck").toString(); } \ No newline at end of file diff --git a/cockatrice/src/settings/debug_settings.h b/cockatrice/src/settings/debug_settings.h index 4918a9a79..89ea33e4e 100644 --- a/cockatrice/src/settings/debug_settings.h +++ b/cockatrice/src/settings/debug_settings.h @@ -15,6 +15,8 @@ public: bool getLocalGameOnStartup(); int getLocalGamePlayerCount(); + + QString getDeckPathForPlayer(const QString &playerName); }; #endif // DEBUG_SETTINGS_H