mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
38 lines
1.2 KiB
C++
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);
|
|
}
|