mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
Prototype intents
Took 53 minutes Took 6 seconds
This commit is contained in:
parent
3b3a563cfc
commit
ea6d9366a3
8 changed files with 133 additions and 10 deletions
|
|
@ -125,6 +125,9 @@ set(cockatrice_SOURCES
|
||||||
src/interface/card_picture_loader/card_picture_loader_worker.cpp
|
src/interface/card_picture_loader/card_picture_loader_worker.cpp
|
||||||
src/interface/card_picture_loader/card_picture_loader_worker_work.cpp
|
src/interface/card_picture_loader/card_picture_loader_worker_work.cpp
|
||||||
src/interface/card_picture_loader/card_picture_to_load.cpp
|
src/interface/card_picture_loader/card_picture_to_load.cpp
|
||||||
|
src/interface/intents/intent.cpp
|
||||||
|
src/interface/intents/intent_open_local_deck.cpp
|
||||||
|
src/interface/intents/intent_wait_for_database_load.cpp
|
||||||
src/interface/layouts/flow_layout.cpp
|
src/interface/layouts/flow_layout.cpp
|
||||||
src/interface/layouts/overlap_layout.cpp
|
src/interface/layouts/overlap_layout.cpp
|
||||||
src/interface/widgets/utility/line_edit_completer.cpp
|
src/interface/widgets/utility/line_edit_completer.cpp
|
||||||
|
|
|
||||||
1
cockatrice/src/interface/intents/intent.cpp
Normal file
1
cockatrice/src/interface/intents/intent.cpp
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
#include "intent.h"
|
||||||
49
cockatrice/src/interface/intents/intent.h
Normal file
49
cockatrice/src/interface/intents/intent.h
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#ifndef COCKATRICE_INTENT_H
|
||||||
|
#define COCKATRICE_INTENT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class Intent : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Intent(QObject *parent = nullptr) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual ~Intent() = default;
|
||||||
|
|
||||||
|
void execute()
|
||||||
|
{
|
||||||
|
if (checkPrecondition()) {
|
||||||
|
onPreconditionSatisfied();
|
||||||
|
} else {
|
||||||
|
onPreconditionNotSatisfied();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void finished();
|
||||||
|
void failed(QString reason);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// --- Subclasses must implement these ---
|
||||||
|
virtual bool checkPrecondition() const = 0;
|
||||||
|
virtual void onPreconditionSatisfied() = 0;
|
||||||
|
virtual void onPreconditionNotSatisfied() = 0;
|
||||||
|
|
||||||
|
// Helper to chain another intent
|
||||||
|
void runDependency(Intent *dependency)
|
||||||
|
{
|
||||||
|
connect(dependency, &Intent::finished, this, [this]() {
|
||||||
|
// Re-check after dependency finishes
|
||||||
|
this->execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(dependency, &Intent::failed, this, &Intent::failed);
|
||||||
|
|
||||||
|
dependency->execute();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COCKATRICE_INTENT_H
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
#include "intent_open_local_deck.h"
|
||||||
44
cockatrice/src/interface/intents/intent_open_local_deck.h
Normal file
44
cockatrice/src/interface/intents/intent_open_local_deck.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef COCKATRICE_INTENT_OPEN_LOCAL_DECK_H
|
||||||
|
#define COCKATRICE_INTENT_OPEN_LOCAL_DECK_H
|
||||||
|
#include "../widgets/tabs/tab_supervisor.h"
|
||||||
|
#include "intent.h"
|
||||||
|
#include "intent_wait_for_database_load.h"
|
||||||
|
#include "libcockatrice/card/database/card_database_manager.h"
|
||||||
|
|
||||||
|
class IntentOpenLocalDeck : public Intent
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
IntentOpenLocalDeck(TabSupervisor *_tabSupervisor, const QString &_file)
|
||||||
|
: Intent(), tabSupervisor(_tabSupervisor), file(_file)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool checkPrecondition() const override
|
||||||
|
{
|
||||||
|
return CardDatabaseManager::getInstance()->getLoadStatus() == LoadStatus::Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void onPreconditionSatisfied() override
|
||||||
|
{
|
||||||
|
std::optional<LoadedDeck> deckOpt =
|
||||||
|
DeckLoader::loadFromFile(file, DeckFileFormat::getFormatFromName(file), true);
|
||||||
|
if (deckOpt) {
|
||||||
|
tabSupervisor->openDeckInNewTab(deckOpt.value());
|
||||||
|
}
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onPreconditionNotSatisfied() override
|
||||||
|
{
|
||||||
|
runDependency(new IntentWaitForDatabaseLoad);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
TabSupervisor *tabSupervisor;
|
||||||
|
const QString &file;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COCKATRICE_INTENT_OPEN_LOCAL_DECK_H
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
#include "intent_wait_for_database_load.h"
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef COCKATRICE_INTENT_WAIT_FOR_DATABASE_LOAD_H
|
||||||
|
#define COCKATRICE_INTENT_WAIT_FOR_DATABASE_LOAD_H
|
||||||
|
|
||||||
|
#include "intent.h"
|
||||||
|
#include "libcockatrice/card/database/card_database_manager.h"
|
||||||
|
|
||||||
|
class IntentWaitForDatabaseLoad : public Intent
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool checkPrecondition() const override
|
||||||
|
{
|
||||||
|
return CardDatabaseManager::getInstance()->getLoadStatus() == LoadStatus::Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void onPreconditionSatisfied() override
|
||||||
|
{
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onPreconditionNotSatisfied() override
|
||||||
|
{
|
||||||
|
connect(CardDatabaseManager::getInstance(), &CardDatabase::cardDatabaseLoadingFinished, this,
|
||||||
|
[this]() { emit finished(); });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COCKATRICE_INTENT_WAIT_FOR_DATABASE_LOAD_H
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "client/settings/cache_settings.h"
|
#include "client/settings/cache_settings.h"
|
||||||
#include "client/sound_engine.h"
|
#include "client/sound_engine.h"
|
||||||
#include "database/interface/settings_card_preference_provider.h"
|
#include "database/interface/settings_card_preference_provider.h"
|
||||||
|
#include "interface/intents/intent_open_local_deck.h"
|
||||||
#include "interface/logger.h"
|
#include "interface/logger.h"
|
||||||
#include "interface/pixel_map_generator.h"
|
#include "interface/pixel_map_generator.h"
|
||||||
#include "interface/theme_manager.h"
|
#include "interface/theme_manager.h"
|
||||||
|
|
@ -318,11 +319,8 @@ int main(int argc, char *argv[])
|
||||||
if (file.startsWith("cockatrice://")) {
|
if (file.startsWith("cockatrice://")) {
|
||||||
// ui.openUrl(QUrl(file));
|
// ui.openUrl(QUrl(file));
|
||||||
} else if (QFileInfo(file).exists()) {
|
} else if (QFileInfo(file).exists()) {
|
||||||
std::optional<LoadedDeck> deckOpt =
|
auto openDeckIntent = new IntentOpenLocalDeck(ui.getTabSupervisor(), file);
|
||||||
DeckLoader::loadFromFile(file, DeckFileFormat::getFormatFromName(file), true);
|
openDeckIntent->execute();
|
||||||
if (deckOpt) {
|
|
||||||
ui.getTabSupervisor()->openDeckInNewTab(deckOpt.value());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,11 +330,8 @@ int main(int argc, char *argv[])
|
||||||
if (file.startsWith("cockatrice://")) {
|
if (file.startsWith("cockatrice://")) {
|
||||||
// ui.openUrl(QUrl(file));
|
// ui.openUrl(QUrl(file));
|
||||||
} else if (QFileInfo(file).exists()) {
|
} else if (QFileInfo(file).exists()) {
|
||||||
std::optional<LoadedDeck> deckOpt =
|
auto openDeckIntent = new IntentOpenLocalDeck(ui.getTabSupervisor(), file);
|
||||||
DeckLoader::loadFromFile(file, DeckFileFormat::getFormatFromName(file), true);
|
openDeckIntent->execute();
|
||||||
if (deckOpt) {
|
|
||||||
ui.getTabSupervisor()->openDeckInNewTab(deckOpt.value());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue