From bc69e67a5b6f7cb97c9bdc6a5061992fce2ea291 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 21 May 2017 00:15:47 -0500 Subject: [PATCH] Add PluginArgs for plugin system --- scripts/setup_build | 1 + .../core/studio/import_tilesheet_wizard.cpp | 12 ++++++++--- .../core/studio/import_tilesheet_wizard.hpp | 6 +++++- src/nostalgia/core/studio/plugin.cpp | 21 +++++++++++-------- src/nostalgia/core/studio/plugin.hpp | 2 ++ src/nostalgia/studio/lib/plugin.cpp | 12 ++++------- src/nostalgia/studio/lib/plugin.hpp | 13 +++++++++--- src/nostalgia/studio/mainwindow.cpp | 15 ++++++++++--- src/nostalgia/studio/mainwindow.hpp | 2 +- 9 files changed, 56 insertions(+), 28 deletions(-) diff --git a/scripts/setup_build b/scripts/setup_build index 4214694d..6716244b 100755 --- a/scripts/setup_build +++ b/scripts/setup_build @@ -26,6 +26,7 @@ mkdir -p $buildDir pushd $buildDir cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DCMAKE_INSTALL_PREFIX="$distDir" \ + -DCMAKE_INSTALL_RPATH="$project/dist/${TARGET}-${BUILD_TYPE}/lib/nostalgia" \ $buildTypeArgs \ $toolchain \ $project diff --git a/src/nostalgia/core/studio/import_tilesheet_wizard.cpp b/src/nostalgia/core/studio/import_tilesheet_wizard.cpp index 9b1aae06..521f379c 100644 --- a/src/nostalgia/core/studio/import_tilesheet_wizard.cpp +++ b/src/nostalgia/core/studio/import_tilesheet_wizard.cpp @@ -17,7 +17,8 @@ const QString ImportTilesheetWizardPage::TILESHEET_NAME = "projectName"; const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath"; const QString ImportTilesheetWizardPage::BPP = "bpp"; -ImportTilesheetWizardPage::ImportTilesheetWizardPage() { +ImportTilesheetWizardPage::ImportTilesheetWizardPage(studio::PluginArgs args) { + m_project = args.project; addLineEdit(tr("&Tile Sheet Name:"), TILESHEET_NAME + "*", "", [this](QString) { auto importPath = field(IMPORT_PATH).toString(); if (QFile(importPath).exists()) { @@ -37,12 +38,17 @@ ImportTilesheetWizardPage::ImportTilesheetWizardPage() { int ImportTilesheetWizardPage::accept() { auto tilesheetName = field(TILESHEET_NAME).toString(); auto importPath = field(IMPORT_PATH).toString(); - if (QFile(importPath).exists()) { - return 0; + QFile importFile(importPath); + if (importFile.exists()) { + return importImage(importFile, field(TILESHEET_NAME).toString()); } else { return 1; } } +int ImportTilesheetWizardPage::importImage(QFile &src, QString tilesetName) { + return 1; +} + } } diff --git a/src/nostalgia/core/studio/import_tilesheet_wizard.hpp b/src/nostalgia/core/studio/import_tilesheet_wizard.hpp index 6f4de009..120f6a89 100644 --- a/src/nostalgia/core/studio/import_tilesheet_wizard.hpp +++ b/src/nostalgia/core/studio/import_tilesheet_wizard.hpp @@ -18,11 +18,15 @@ class ImportTilesheetWizardPage: public studio::WizardFormPage { static const QString TILESHEET_NAME; static const QString IMPORT_PATH; static const QString BPP; + studio::Project *m_project = nullptr; public: - ImportTilesheetWizardPage(); + ImportTilesheetWizardPage(studio::PluginArgs args); int accept(); + + private: + int importImage(QFile &src, QString dest); }; } diff --git a/src/nostalgia/core/studio/plugin.cpp b/src/nostalgia/core/studio/plugin.cpp index 04716c4d..30dc4d56 100644 --- a/src/nostalgia/core/studio/plugin.cpp +++ b/src/nostalgia/core/studio/plugin.cpp @@ -6,8 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include - #include "import_tilesheet_wizard.hpp" #include "plugin.hpp" @@ -18,14 +16,19 @@ namespace nostalgia { namespace core { Plugin::Plugin() { - addImportWizard( - tr("Tile Sheet"), - []() { - QVector pgs; - pgs.push_back(new ImportTilesheetWizardPage()); - return pgs; +} + +QVector Plugin::importWizards(studio::PluginArgs args) { + return { + { + tr("Tile Sheet"), + [args]() { + QVector pgs; + pgs.push_back(new ImportTilesheetWizardPage(args)); + return pgs; + } } - ); + }; } } diff --git a/src/nostalgia/core/studio/plugin.hpp b/src/nostalgia/core/studio/plugin.hpp index 6193ca48..0aa8956d 100644 --- a/src/nostalgia/core/studio/plugin.hpp +++ b/src/nostalgia/core/studio/plugin.hpp @@ -22,6 +22,8 @@ class Plugin: public QObject, studio::Plugin { public: Plugin(); + + QVector importWizards(studio::PluginArgs args) override; }; } diff --git a/src/nostalgia/studio/lib/plugin.cpp b/src/nostalgia/studio/lib/plugin.cpp index f9ed6bfb..86b55a5b 100644 --- a/src/nostalgia/studio/lib/plugin.cpp +++ b/src/nostalgia/studio/lib/plugin.cpp @@ -15,16 +15,12 @@ void Plugin::addNewWizard(QString name, std::function()> m m_newWizards.push_back({name, make}); } -void Plugin::addImportWizard(QString name, std::function()> make) { - m_importWizards.push_back({name, make}); +QVector Plugin::newWizards(PluginArgs) { + return {}; } -QVector Plugin::newWizards() { - return m_newWizards; -} - -QVector Plugin::importWizards() { - return m_importWizards; +QVector Plugin::importWizards(PluginArgs) { + return {}; } } diff --git a/src/nostalgia/studio/lib/plugin.hpp b/src/nostalgia/studio/lib/plugin.hpp index fd98c14a..fd0a2792 100644 --- a/src/nostalgia/studio/lib/plugin.hpp +++ b/src/nostalgia/studio/lib/plugin.hpp @@ -11,12 +11,20 @@ #include #include +#include +#include #include #include +#include "project.hpp" + namespace nostalgia { namespace studio { +struct PluginArgs { + Project *project = nullptr; +}; + struct WizardMaker { QString name; std::function()> make; @@ -25,16 +33,15 @@ struct WizardMaker { class Plugin { private: QVector m_newWizards; - QVector m_importWizards; public: void addNewWizard(QString name, std::function()> make); void addImportWizard(QString name, std::function()> make); - QVector newWizards(); + virtual QVector newWizards(PluginArgs); - QVector importWizards(); + virtual QVector importWizards(PluginArgs); }; } diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index e6a5fd5e..aafe8ddb 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -218,9 +218,13 @@ int MainWindow::writeState(QString path) { int MainWindow::openProject(QString projectPath) { auto err = closeProject(); - auto project = QSharedPointer(new Project(projectPath)); + auto project = new Project(projectPath); err |= project->open(); if (err == 0) { + if (m_project) { + delete m_project; + m_project = nullptr; + } m_project = project; m_projectExplorer->setModel(new OxFSModel(m_project->romFS())); m_importAction->setEnabled(true); @@ -231,7 +235,10 @@ int MainWindow::openProject(QString projectPath) { int MainWindow::closeProject() { auto err = 0; - m_project = QSharedPointer(nullptr); + if (m_project) { + delete m_project; + m_project = nullptr; + } if (m_projectExplorer->model()) { delete m_projectExplorer->model(); } @@ -315,8 +322,10 @@ void MainWindow::showImportWizard() { auto ws = new WizardSelect(); wizard.addPage(ws); + PluginArgs args; + args.project = m_project; for (auto p : m_plugins) { - for (auto w : p->importWizards()) { + for (auto w : p->importWizards(args)) { ws->addOption(w.name, w.make); } } diff --git a/src/nostalgia/studio/mainwindow.hpp b/src/nostalgia/studio/mainwindow.hpp index 75bd01d5..a373a631 100644 --- a/src/nostalgia/studio/mainwindow.hpp +++ b/src/nostalgia/studio/mainwindow.hpp @@ -82,7 +82,7 @@ class MainWindow: public QMainWindow { QString m_profilePath; NostalgiaStudioState m_state; QAction *m_importAction = nullptr; - QSharedPointer m_project; + Project *m_project = nullptr; QPointer m_viewMenu; QVector> m_cleanupTasks; QVector> m_dockWidgets;