diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ef66ad5..2fb188cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ else() set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(NOSTALGIA_DIST_BIN bin) set(NOSTALGIA_DIST_LIB lib) - set(NOSTALGIA_DIST_PLUGIN lib/nostalgia/plugins) + set(NOSTALGIA_DIST_PLUGIN lib/nostalgia/modules) set(NOSTALGIA_DIST_RESOURCES share) endif() diff --git a/src/nostalgia/core/studio/CMakeLists.txt b/src/nostalgia/core/studio/CMakeLists.txt index 8e06f5b9..81ed0da0 100644 --- a/src/nostalgia/core/studio/CMakeLists.txt +++ b/src/nostalgia/core/studio/CMakeLists.txt @@ -3,13 +3,13 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) add_library( - NostalgiaCore-Studio SHARED + NostalgiaCore-Studio OBJECT imgconv.cpp import_tilesheet_wizard.cpp + module.cpp new_tilesheet_wizard.cpp newpalettewizard.cpp paletteeditor.cpp - plugin.cpp tilesheeteditor.cpp util.cpp rsrc.qrc diff --git a/src/nostalgia/core/studio/plugin.cpp b/src/nostalgia/core/studio/module.cpp similarity index 82% rename from src/nostalgia/core/studio/plugin.cpp rename to src/nostalgia/core/studio/module.cpp index 9deb9a90..72cc178a 100644 --- a/src/nostalgia/core/studio/plugin.cpp +++ b/src/nostalgia/core/studio/module.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -12,11 +12,11 @@ #include "paletteeditor.hpp" #include "tilesheeteditor.hpp" -#include "plugin.hpp" +#include "module.hpp" namespace nostalgia::core { -QVector Plugin::newWizards(const studio::Context *ctx) { +QVector Module::newWizards(const studio::Context *ctx) { return { { tr("Palette"), @@ -37,7 +37,7 @@ QVector Plugin::newWizards(const studio::Context *ctx) { }; } -QVector Plugin::importWizards(const studio::Context *ctx) { +QVector Module::importWizards(const studio::Context *ctx) { return { { tr("Tile Sheet"), @@ -51,7 +51,7 @@ QVector Plugin::importWizards(const studio::Context *ctx) { }; } -QVector Plugin::editors(const studio::Context *ctx) { +QVector Module::editors(const studio::Context *ctx) { return { { {"ng"}, diff --git a/src/nostalgia/core/studio/plugin.hpp b/src/nostalgia/core/studio/module.hpp similarity index 76% rename from src/nostalgia/core/studio/plugin.hpp rename to src/nostalgia/core/studio/module.hpp index 32a77773..f016ca87 100644 --- a/src/nostalgia/core/studio/plugin.hpp +++ b/src/nostalgia/core/studio/module.hpp @@ -14,10 +14,10 @@ namespace nostalgia::core { -class Plugin: public QObject, studio::Plugin { +class Module: public QObject, public studio::Module { Q_OBJECT - Q_PLUGIN_METADATA(IID "net.drinkingtea.nostalgia.core.studio.Plugin" FILE "core-studio.json") - Q_INTERFACES(nostalgia::studio::Plugin) + Q_PLUGIN_METADATA(IID "net.drinkingtea.nostalgia.core.studio.Module" FILE "core-studio.json") + Q_INTERFACES(nostalgia::studio::Module) public: QVector newWizards(const studio::Context *ctx) override; diff --git a/src/nostalgia/studio/CMakeLists.txt b/src/nostalgia/studio/CMakeLists.txt index 20d6f929..e7149d13 100644 --- a/src/nostalgia/studio/CMakeLists.txt +++ b/src/nostalgia/studio/CMakeLists.txt @@ -15,6 +15,7 @@ add_executable( target_link_libraries( nostalgia-studio QDarkStyle + NostalgiaCore-Studio NostalgiaStudio NostalgiaPack ) diff --git a/src/nostalgia/studio/builtinmodules.hpp b/src/nostalgia/studio/builtinmodules.hpp new file mode 100644 index 00000000..7b26ae85 --- /dev/null +++ b/src/nostalgia/studio/builtinmodules.hpp @@ -0,0 +1,22 @@ +/* + * Copyright 2016 - 2020 gary@drinkingtea.net + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include + +namespace nostalgia::studio { + +[[maybe_unused]] // GCC warns about the existence of this "unused" constexpr list in a header file... +constexpr auto BuiltinModules = { + [] { + return new core::Module(); + }, +}; + +} diff --git a/src/nostalgia/studio/lib/CMakeLists.txt b/src/nostalgia/studio/lib/CMakeLists.txt index 850ad522..541a90d9 100644 --- a/src/nostalgia/studio/lib/CMakeLists.txt +++ b/src/nostalgia/studio/lib/CMakeLists.txt @@ -5,7 +5,7 @@ add_library( NostalgiaStudio SHARED editor.cpp wizard.cpp - plugin.cpp + module.cpp project.cpp ) @@ -26,7 +26,7 @@ install( FILES editor.hpp wizard.hpp - plugin.hpp + module.hpp project.hpp ${CMAKE_CURRENT_BINARY_DIR}/nostalgiastudio_export.h DESTINATION diff --git a/src/nostalgia/studio/lib/plugin.cpp b/src/nostalgia/studio/lib/module.cpp similarity index 53% rename from src/nostalgia/studio/lib/plugin.cpp rename to src/nostalgia/studio/lib/module.cpp index 9abe71bc..b7023005 100644 --- a/src/nostalgia/studio/lib/plugin.cpp +++ b/src/nostalgia/studio/lib/module.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -7,23 +7,23 @@ */ #include "context.hpp" -#include "plugin.hpp" +#include "module.hpp" namespace nostalgia::studio { -QVector Plugin::newWizards(const Context*) { +QVector Module::newWizards(const Context*) { return {}; } -QVector Plugin::importWizards(const Context*) { +QVector Module::importWizards(const Context*) { return {}; } -QWidget *Plugin::makeEditor(QString, const Context*) { +QWidget *Module::makeEditor(QString, const Context*) { return nullptr; } -QVector Plugin::editors(const Context*) { +QVector Module::editors(const Context*) { return {}; } diff --git a/src/nostalgia/studio/lib/plugin.hpp b/src/nostalgia/studio/lib/module.hpp similarity index 76% rename from src/nostalgia/studio/lib/plugin.hpp rename to src/nostalgia/studio/lib/module.hpp index 66c6e055..fa338fb7 100644 --- a/src/nostalgia/studio/lib/plugin.hpp +++ b/src/nostalgia/studio/lib/module.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -22,10 +22,10 @@ struct EditorMaker { std::function make; }; -class Plugin { +class Module { public: - virtual ~Plugin() = default; + virtual ~Module() = default; virtual QVector newWizards(const class Context *ctx); @@ -39,6 +39,6 @@ class Plugin { } -#define PluginInterface_iid "net.drinkingtea.nostalgia.studio.Plugin" +#define PluginInterface_iid "net.drinkingtea.nostalgia.studio.Module" -Q_DECLARE_INTERFACE(nostalgia::studio::Plugin, PluginInterface_iid) +Q_DECLARE_INTERFACE(nostalgia::studio::Module, PluginInterface_iid) diff --git a/src/nostalgia/studio/lib/wizard.cpp b/src/nostalgia/studio/lib/wizard.cpp index 867948fa..54cd887b 100644 --- a/src/nostalgia/studio/lib/wizard.cpp +++ b/src/nostalgia/studio/lib/wizard.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -17,7 +17,7 @@ #include "context.hpp" #include "project.hpp" -#include "plugin.hpp" +#include "module.hpp" #include "wizard.hpp" namespace nostalgia::studio { diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index daa9c27a..5f6d80be 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -70,7 +70,7 @@ MainWindow::MainWindow(QString profilePath) { setupProjectExplorer(); statusBar(); // setup status bar - loadPlugins(); + loadModules(); readState(); } @@ -79,43 +79,50 @@ MainWindow::~MainWindow() { closeProject(); } -void MainWindow::loadPlugins() { - for (auto dir : m_profile.pluginsPath) { +void MainWindow::loadModules() { + for (auto p : BuiltinModules) { + loadModule(p()); + } + for (auto dir : m_profile.modulesPath) { QFileInfo dirInfo(m_profilePath); dir = dirInfo.absolutePath() + "/" + dir; if (dirInfo.exists()) { - qDebug() << "Checking plugin directory:" << dir; - loadPluginDir(dir); + qDebug() << "Checking module directory:" << dir; + loadModuleDir(dir); } } } -void MainWindow::loadPluginDir(QString dir) { - for (auto pluginPath : QDir(dir).entryList()) { - pluginPath = dir + '/' + pluginPath; - if (QLibrary::isLibrary(pluginPath)) { - loadPlugin(pluginPath); +void MainWindow::loadModuleDir(QString dir) { + for (auto modulePath : QDir(dir).entryList()) { + modulePath = dir + '/' + modulePath; + if (QLibrary::isLibrary(modulePath)) { + loadModule(modulePath); } } } -void MainWindow::loadPlugin(QString pluginPath) { - qDebug() << "Loading plugin:" << pluginPath; - QPluginLoader loader(pluginPath); - auto plugin = qobject_cast(loader.instance()); - if (plugin) { - m_plugins.push_back(plugin); - auto editorMakers = plugin->editors(&m_ctx); - for (const auto &em : editorMakers) { - for (const auto &ext : em.fileTypes) { - m_editorMakers[ext] = em; - } - } +void MainWindow::loadModule(QString modulePath) { + qDebug() << "Loading module:" << modulePath; + QPluginLoader loader(modulePath); + auto module = qobject_cast(loader.instance()); + if (module) { + loadModule(module); } else { qInfo() << loader.errorString(); } } +void MainWindow::loadModule(Module *module) { + m_modules.push_back(module); + auto editorMakers = module->editors(&m_ctx); + for (const auto &em : editorMakers) { + for (const auto &ext : em.fileTypes) { + m_editorMakers[ext] = em; + } + } +} + void MainWindow::setupMenu() { auto menu = menuBar(); auto fileMenu = menu->addMenu(tr("&File")); @@ -492,8 +499,8 @@ void MainWindow::showNewWizard() { } ); - // add plugin options - for (auto p : m_plugins) { + // add module options + for (auto p : m_modules) { for (auto w : p->newWizards(&m_ctx)) { ws->addOption(w); } @@ -590,7 +597,7 @@ void MainWindow::showImportWizard() { auto ws = new WizardSelect(); wizard.addPage(ws); - for (auto p : m_plugins) { + for (auto p : m_modules) { for (auto w : p->importWizards(&m_ctx)) { ws->addOption(w); } diff --git a/src/nostalgia/studio/mainwindow.hpp b/src/nostalgia/studio/mainwindow.hpp index d56e9699..16725976 100644 --- a/src/nostalgia/studio/mainwindow.hpp +++ b/src/nostalgia/studio/mainwindow.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -25,9 +25,10 @@ #include #include "lib/context.hpp" -#include "lib/plugin.hpp" +#include "lib/module.hpp" #include "lib/project.hpp" +#include "builtinmodules.hpp" #include "oxfstreeview.hpp" namespace nostalgia::studio { @@ -47,7 +48,7 @@ ox::Error model(T *io, NostalgiaStudioState *obj) { struct NostalgiaStudioProfile { QString appName; QString orgName; - QVector pluginsPath; + QVector modulesPath; }; template @@ -56,7 +57,7 @@ ox::Error model(T *io, NostalgiaStudioProfile *obj) { oxReturnError(io->setTypeInfo("NostalgiaStudioProfile", 3)); oxReturnError(io->field("app_name", &obj->appName)); oxReturnError(io->field("org_name", &obj->orgName)); - oxReturnError(io->field("plugins_path", &obj->pluginsPath)); + oxReturnError(io->field("modules_path", &obj->modulesPath)); return err; } @@ -82,7 +83,7 @@ class MainWindow: public QMainWindow { QPointer m_viewMenu; QVector> m_dockWidgets; QTreeView *m_projectExplorer = nullptr; - QVector m_plugins; + QVector m_modules; QHash m_editorMakers; QPointer m_oxfsView = nullptr; QTabWidget *m_tabs = nullptr; @@ -95,11 +96,13 @@ class MainWindow: public QMainWindow { virtual ~MainWindow(); private: - void loadPlugins(); + void loadModules(); - void loadPluginDir(QString path); + void loadModuleDir(QString path); - void loadPlugin(QString path); + void loadModule(QString path); + + void loadModule(Module *module); void setupMenu(); diff --git a/src/nostalgia/studio/nostalgia-studio-dev.json b/src/nostalgia/studio/nostalgia-studio-dev.json index c0a67ea6..642ad33f 100644 --- a/src/nostalgia/studio/nostalgia-studio-dev.json +++ b/src/nostalgia/studio/nostalgia-studio-dev.json @@ -1,8 +1,8 @@ { "app_name": "Nostalgia Studio", "org_name": "Drinking Tea", - "plugins_path": [ - "../lib/nostalgia/plugins", + "modules_path": [ + "../lib/nostalgia/modules", "../Plugins", "../../../out/build/x64-Debug", "../../../out/build/x64-Release" diff --git a/src/nostalgia/studio/nostalgia-studio.json b/src/nostalgia/studio/nostalgia-studio.json index c258dfbe..a7b7aa04 100644 --- a/src/nostalgia/studio/nostalgia-studio.json +++ b/src/nostalgia/studio/nostalgia-studio.json @@ -1,8 +1,8 @@ { "app_name": "Nostalgia Studio", "org_name": "Drinking Tea", - "plugins_path": [ - "../lib/nostalgia/plugins", + "modules_path": [ + "../lib/nostalgia/modules", "../Plugins" ] } diff --git a/src/nostalgia/studio/studio.hpp b/src/nostalgia/studio/studio.hpp index 150d1473..25e876ba 100644 --- a/src/nostalgia/studio/studio.hpp +++ b/src/nostalgia/studio/studio.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -10,6 +10,6 @@ #include "lib/context.hpp" #include "lib/editor.hpp" -#include "lib/plugin.hpp" +#include "lib/module.hpp" #include "lib/project.hpp" #include "lib/wizard.hpp" diff --git a/src/nostalgia/world/studio/CMakeLists.txt b/src/nostalgia/world/studio/CMakeLists.txt index 01a7fa2c..2630a26f 100644 --- a/src/nostalgia/world/studio/CMakeLists.txt +++ b/src/nostalgia/world/studio/CMakeLists.txt @@ -1,6 +1,6 @@ add_library( - NostalgiaWorld-Studio SHARED + NostalgiaWorld-Studio OBJECT consts.cpp newworldwizard.cpp worldstudioplugin.cpp diff --git a/src/nostalgia/world/studio/worldstudioplugin.cpp b/src/nostalgia/world/studio/worldstudioplugin.cpp index ce265e2b..ed022f99 100644 --- a/src/nostalgia/world/studio/worldstudioplugin.cpp +++ b/src/nostalgia/world/studio/worldstudioplugin.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/src/nostalgia/world/studio/worldstudioplugin.hpp b/src/nostalgia/world/studio/worldstudioplugin.hpp index d1eb7d44..8b6238cc 100644 --- a/src/nostalgia/world/studio/worldstudioplugin.hpp +++ b/src/nostalgia/world/studio/worldstudioplugin.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2020 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -14,10 +14,10 @@ namespace nostalgia::world { -class WorldEditorPlugin: public QObject, public studio::Plugin { +class WorldEditorPlugin: public QObject, public studio::Module { Q_OBJECT - Q_PLUGIN_METADATA(IID "net.drinkingtea.nostalgia.world.studio.Plugin" FILE "world-studio.json") - Q_INTERFACES(nostalgia::studio::Plugin) + Q_PLUGIN_METADATA(IID "net.drinkingtea.nostalgia.world.studio.Module" FILE "world-studio.json") + Q_INTERFACES(nostalgia::studio::Module) public: QVector newWizards(const studio::Context *ctx) override;