Cockatrice/cockatrice/src/interface/intents/intent_open_local_deck.cpp
BruebachL 6f0c5dca12
[Refactor] Move LoadedDeck and DeckFileFormat data types into libcockatrice_deck_list (#7424)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-10-31 18:44:11 +01:00

38 lines
1.2 KiB
C++

#include "intent_open_local_deck.h"
#include "../deck_loader/deck_loader.h"
#include "../widgets/tabs/tab_supervisor.h"
#include "intent_wait_for_database_load.h"
#include "libcockatrice/card/database/card_database.h"
#include "libcockatrice/card/database/card_database_loader.h"
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/deck_list/deck_file_format.h>
#include <libcockatrice/deck_list/loaded_deck.h>
#include <optional>
IntentOpenLocalDeck::IntentOpenLocalDeck(TabSupervisor *_tabSupervisor, const QString &_file)
: Intent(), tabSupervisor(_tabSupervisor), file(_file)
{
}
bool IntentOpenLocalDeck::checkPrecondition() const
{
return CardDatabaseManager::getInstance()->getLoadStatus() == LoadStatus::Ok;
}
void IntentOpenLocalDeck::onPreconditionSatisfied()
{
std::optional<LoadedDeck> deckOpt = DeckLoader::loadFromFile(file, DeckFileFormat::getFormatFromName(file), true);
if (deckOpt) {
tabSupervisor->openDeckInNewTab(deckOpt.value());
emitFinished();
} else {
emitFailed(tr("Unable to load deck file %1").arg(file));
}
}
void IntentOpenLocalDeck::onPreconditionNotSatisfied()
{
runDependency(new IntentWaitForDatabaseLoad);
}