add debug setting to load deck and ready on join (#5409)

* new property

* refactor deck loading to new method

* another new method

* works now
This commit is contained in:
RickyRister 2025-01-02 14:08:51 -08:00 committed by GitHub
parent 8a427955e7
commit 0402d4b853
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 3 deletions

View file

@ -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());

View file

@ -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

View file

@ -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();
}

View file

@ -15,6 +15,8 @@ public:
bool getLocalGameOnStartup();
int getLocalGamePlayerCount();
QString getDeckPathForPlayer(const QString &playerName);
};
#endif // DEBUG_SETTINGS_H