Add new Zone wizard

This commit is contained in:
2018-01-29 23:56:36 -06:00
parent eebce9924d
commit 68bb2729d7
15 changed files with 85 additions and 60 deletions

View File

@@ -23,6 +23,7 @@ target_link_libraries(
Qt5::Core
Qt5::Widgets
OxFS
OxMetalClaw
OxStd
)

View File

@@ -17,6 +17,7 @@
#include <QWizardPage>
#include "project.hpp"
#include "wizard.hpp"
namespace nostalgia {
namespace studio {
@@ -26,12 +27,6 @@ struct Context {
const Project *project = nullptr;
};
struct WizardMaker {
QString name;
std::function<QVector<QWizardPage*>()> make;
std::function<int(QWizard*)> onAccept;
};
struct EditorMaker {
virtual QWidget *make(QString path, const Context *ctx) = 0;
};

View File

@@ -79,7 +79,7 @@ FileSystem *Project::romFs() {
}
int Project::mkdir(QString path) const {
auto err = m_fs->mkdir(path.toUtf8().data());
auto err = m_fs->mkdir(path.toUtf8().data(), true);
emit updated(path);
return err;
}

View File

@@ -11,6 +11,7 @@
#include <QSharedPointer>
#include <ox/fs/filesystem.hpp>
#include <ox/mc/mc.hpp>
namespace nostalgia {
namespace studio {
@@ -41,6 +42,12 @@ class Project: public QObject {
int write(QString path, uint8_t *buff, size_t buffLen) const;
/**
* Writes a MetalClaw object to the project at the given path.
*/
template<typename T>
int writeObj(QString path, T *obj) const;
ox::FileStat stat(QString path) const;
signals:
@@ -48,5 +55,29 @@ class Project: public QObject {
};
template<typename T>
int Project::writeObj(QString path, T *obj) const {
int err = 0;
auto buffLen = 1024 * 1024 * 10;
QByteArray buff(buffLen, 0);
// write MetalClaw
size_t mcSize = 0;
err |= ox::write((uint8_t*) buff.data(), buffLen, obj, &mcSize);
if (err) {
return err;
}
// write to FS
err |= write(path, (uint8_t*) buff.data(), mcSize);
if (err) {
return err;
}
emit updated(path);
return err;
}
}
}

View File

@@ -336,9 +336,8 @@ void Wizard::setAccept(std::function<int(QWizard*)> acceptFunc) {
void Wizard::accept() {
auto page = dynamic_cast<WizardFormPage*>(currentPage());
if (page != nullptr && page->accept() == 0) {
QDialog::accept();
} else if (m_acceptFunc != nullptr && m_acceptFunc(this) == 0) {
if (page != nullptr and page->accept() == 0 and
m_acceptFunc != nullptr and m_acceptFunc(this) == 0) {
QDialog::accept();
}
}

View File

@@ -22,7 +22,11 @@
namespace nostalgia {
namespace studio {
class WizardMaker;
struct WizardMaker {
QString name;
std::function<QVector<QWizardPage*>()> make;
std::function<int(QWizard*)> onAccept;
};
class WizardSelect: public QWizardPage {
Q_OBJECT
@@ -53,6 +57,7 @@ class WizardSelect: public QWizardPage {
class WizardFormPage: public QWizardPage {
Q_OBJECT
private:
struct Field {
QString defaultValue = "";