Add plugin system

This commit is contained in:
2017-05-17 00:10:16 -05:00
parent db8ad57828
commit fb52ca6518
15 changed files with 368 additions and 65 deletions

View File

@@ -23,6 +23,10 @@ add_library(
core.cpp
)
if(WOMBAT_BUILD_TYPE STREQUAL "Native")
add_subdirectory(studio)
endif()
install(
FILES
core.hpp

View File

@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 2.8.11)
if(WOMBAT_BUILD_TYPE STREQUAL "Native")
add_library(
NostalgiaCore-Studio
SHARED
import_tilesheet_wizard.cpp
plugin.cpp
)
endif()
target_link_libraries(
NostalgiaCore-Studio
Qt5::Core
Qt5::Widgets
NostalgiaStudio
OxFS
OxStd
)
install(TARGETS NostalgiaCore-Studio
LIBRARY DESTINATION lib/nostalgia)

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2016-2017 gtalent2@gmail.com
*
* 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/.
*/
#include <QFile>
#include "import_tilesheet_wizard.hpp"
namespace nostalgia {
namespace core {
const QString ImportTilesheetWizardPage::TILESHEET_NAME = "projectName";
const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath";
const QString ImportTilesheetWizardPage::BPP = "bpp";
ImportTilesheetWizardPage::ImportTilesheetWizardPage() {
addLineEdit(tr("&Tile Sheet Name:"), TILESHEET_NAME + "*", "", [this](QString) {
auto importPath = field(IMPORT_PATH).toString();
if (QFile(importPath).exists()) {
return 0;
} else {
this->showValidationError(tr("Invalid image file: %1").arg(importPath));
return 1;
}
}
);
auto fileTypes = "(*.png);;(*.bmp);;(*.jpg);;(*.jpeg)";
addPathBrowse(tr("Tile Sheet &Path:"), IMPORT_PATH + "*", "",
QFileDialog::ExistingFile, fileTypes);
addComboBox(tr("Bits Per Pixe&l:"), BPP, {"4", "8"});
}
int ImportTilesheetWizardPage::accept() {
auto tilesheetName = field(TILESHEET_NAME).toString();
auto importPath = field(IMPORT_PATH).toString();
if (QFile(importPath).exists()) {
return 0;
} else {
return 1;
}
}
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2016-2017 gtalent2@gmail.com
*
* 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 <nostalgia/studio/studio.hpp>
namespace nostalgia {
namespace core {
class ImportTilesheetWizardPage: public studio::WizardFormPage {
private:
static const QString TILESHEET_NAME;
static const QString IMPORT_PATH;
static const QString BPP;
public:
ImportTilesheetWizardPage();
int accept();
};
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2016-2017 gtalent2@gmail.com
*
* 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/.
*/
#include <nostalgia/studio/studio.hpp>
#include "import_tilesheet_wizard.hpp"
#include "plugin.hpp"
using namespace nostalgia::studio;
namespace nostalgia {
namespace core {
Plugin::Plugin() {
addImportWizard(
tr("Tile Sheet"),
[]() {
QVector<QWizardPage*> pgs;
pgs.push_back(new ImportTilesheetWizardPage());
return pgs;
}
);
}
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2016-2017 gtalent2@gmail.com
*
* 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 <QPluginLoader>
#include <nostalgia/studio/studio.hpp>
namespace nostalgia {
namespace core {
class Plugin: public QObject, studio::Plugin {
Q_OBJECT
Q_PLUGIN_METADATA(IID "net.drinkingtea.nostalgia.studio.Plugin")
Q_INTERFACES(nostalgia::studio::Plugin)
public:
Plugin();
};
}
}