From 68bb2729d76e8e99cc951a8cf55437915ec3de90 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 29 Jan 2018 23:56:36 -0600 Subject: [PATCH] Add new Zone wizard --- .vscode/c_cpp_properties.json | 4 ++- src/nostalgia/studio/lib/CMakeLists.txt | 1 + src/nostalgia/studio/lib/plugin.hpp | 7 +--- src/nostalgia/studio/lib/project.cpp | 2 +- src/nostalgia/studio/lib/project.hpp | 31 ++++++++++++++++++ src/nostalgia/studio/lib/wizard.cpp | 5 ++- src/nostalgia/studio/lib/wizard.hpp | 7 +++- src/nostalgia/tools/pack.cpp | 32 +++++++++++-------- src/nostalgia/world/studio/CMakeLists.txt | 2 -- src/nostalgia/world/studio/newworldwizard.cpp | 24 -------------- src/nostalgia/world/studio/newworldwizard.hpp | 2 -- src/nostalgia/world/studio/worldeditor.cpp | 7 ++++ .../world/studio/worldstudioplugin.cpp | 12 ++++--- src/nostalgia/world/world.cpp | 1 - src/nostalgia/world/world.hpp | 8 +++-- 15 files changed, 85 insertions(+), 60 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index fbc04615..614fd0c1 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -39,7 +39,9 @@ "/usr/include/x86_64-linux-gnu/qt5/QtCore", "/usr/include/x86_64-linux-gnu/qt5", "${workspaceRoot}/deps/ox/src", - "/usr/lib/llvm-3.8/lib/clang/3.8.1/include" + "/usr/lib/llvm-3.8/lib/clang/3.8.1/include", + "${workspaceRoot}/src", + "/usr/include/x86_64-linux-gnu/qt5/QtWidgets" ], "defines": [], "intelliSenseMode": "clang-x64", diff --git a/src/nostalgia/studio/lib/CMakeLists.txt b/src/nostalgia/studio/lib/CMakeLists.txt index 6a79e508..9e96ef65 100644 --- a/src/nostalgia/studio/lib/CMakeLists.txt +++ b/src/nostalgia/studio/lib/CMakeLists.txt @@ -23,6 +23,7 @@ target_link_libraries( Qt5::Core Qt5::Widgets OxFS + OxMetalClaw OxStd ) diff --git a/src/nostalgia/studio/lib/plugin.hpp b/src/nostalgia/studio/lib/plugin.hpp index 82f6268c..50d59663 100644 --- a/src/nostalgia/studio/lib/plugin.hpp +++ b/src/nostalgia/studio/lib/plugin.hpp @@ -17,6 +17,7 @@ #include #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()> make; - std::function onAccept; -}; - struct EditorMaker { virtual QWidget *make(QString path, const Context *ctx) = 0; }; diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index 99072c94..6b30ca36 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -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; } diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index 6fd2e928..56c55745 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -11,6 +11,7 @@ #include #include +#include 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 + int writeObj(QString path, T *obj) const; + ox::FileStat stat(QString path) const; signals: @@ -48,5 +55,29 @@ class Project: public QObject { }; +template +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; +} + } } diff --git a/src/nostalgia/studio/lib/wizard.cpp b/src/nostalgia/studio/lib/wizard.cpp index af6f59fa..6d39649a 100644 --- a/src/nostalgia/studio/lib/wizard.cpp +++ b/src/nostalgia/studio/lib/wizard.cpp @@ -336,9 +336,8 @@ void Wizard::setAccept(std::function acceptFunc) { void Wizard::accept() { auto page = dynamic_cast(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(); } } diff --git a/src/nostalgia/studio/lib/wizard.hpp b/src/nostalgia/studio/lib/wizard.hpp index 088bd320..8f410fd0 100644 --- a/src/nostalgia/studio/lib/wizard.hpp +++ b/src/nostalgia/studio/lib/wizard.hpp @@ -22,7 +22,11 @@ namespace nostalgia { namespace studio { -class WizardMaker; +struct WizardMaker { + QString name; + std::function()> make; + std::function 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 = ""; diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 40969c2f..324eabaa 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -125,30 +125,36 @@ int run(ClArgs args) { fsBuff = fs->buff(); // update fsBuff pointer in case there is a new buff err |= fs->write(argInode, imgDataBuff, imgDataBuffSize); - if (argCompact) { - fs->resize(); - } + if (!err) { + if (argCompact) { + fs->resize(); + } - auto fsFile = fopen(argFsPath.toUtf8(), "wb"); - if (fsFile) { - err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1; - err |= fclose(fsFile); - if (err) { - cerr << "Could not write to file system file.\n"; + auto fsFile = fopen(argFsPath.toUtf8(), "wb"); + if (fsFile) { + err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1; + err |= fclose(fsFile); + if (err) { + cerr << "Could not write to file system file.\n"; + } + } else { + err = 2; } } else { - err = 2; + err = 3; } delete fs; } else { - err = 3; + err = 4; } } - delete[] fsBuff; + if (fsBuff) { + delete[] fsBuff; + } } else { - err = 4; + err = 5; } return err; diff --git a/src/nostalgia/world/studio/CMakeLists.txt b/src/nostalgia/world/studio/CMakeLists.txt index dcfbc011..f05db341 100644 --- a/src/nostalgia/world/studio/CMakeLists.txt +++ b/src/nostalgia/world/studio/CMakeLists.txt @@ -12,8 +12,6 @@ target_link_libraries( Qt5::Core Qt5::Widgets NostalgiaStudio - OxFS - OxStd ) install( diff --git a/src/nostalgia/world/studio/newworldwizard.cpp b/src/nostalgia/world/studio/newworldwizard.cpp index 308d7aac..e62ed19c 100644 --- a/src/nostalgia/world/studio/newworldwizard.cpp +++ b/src/nostalgia/world/studio/newworldwizard.cpp @@ -17,8 +17,6 @@ namespace world { using namespace studio; const QString NewWorldWizard::FIELD_WORLD_PATH = "World.WorldPath"; -const QString NewWorldWizard::FIELD_WIDTH = "World.Width"; -const QString NewWorldWizard::FIELD_HEIGHT = "World.Height"; NewWorldWizard::NewWorldWizard(const Context *ctx) { addLineEdit(tr("&Name:"), FIELD_WORLD_PATH, "", [this, ctx](QString worldName) { @@ -31,28 +29,6 @@ NewWorldWizard::NewWorldWizard(const Context *ctx) { } } ); - addLineEdit(tr("&Width:"), FIELD_WIDTH, "", [this, ctx](QString widthStr) { - bool ok = false; - widthStr.toInt(&ok); - if (ok) { - return 0; - } else { - this->showValidationError(tr("Invalid width: \"%1\"").arg(widthStr)); - return 1; - } - } - ); - addLineEdit(tr("&Height:"), FIELD_HEIGHT, "", [this, ctx](QString widthStr) { - bool ok = false; - widthStr.toInt(&ok); - if (ok) { - return 0; - } else { - this->showValidationError(tr("Invalid height: \"%1\"").arg(widthStr)); - return 1; - } - } - ); } } diff --git a/src/nostalgia/world/studio/newworldwizard.hpp b/src/nostalgia/world/studio/newworldwizard.hpp index 38d3c340..10de5035 100644 --- a/src/nostalgia/world/studio/newworldwizard.hpp +++ b/src/nostalgia/world/studio/newworldwizard.hpp @@ -18,8 +18,6 @@ namespace world { struct NewWorldWizard: public studio::WizardFormPage { static const QString FIELD_WORLD_PATH; - static const QString FIELD_WIDTH; - static const QString FIELD_HEIGHT; NewWorldWizard(const studio::Context *ctx); diff --git a/src/nostalgia/world/studio/worldeditor.cpp b/src/nostalgia/world/studio/worldeditor.cpp index 3730cb74..f4e950fc 100644 --- a/src/nostalgia/world/studio/worldeditor.cpp +++ b/src/nostalgia/world/studio/worldeditor.cpp @@ -1,3 +1,10 @@ +/* + * 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 "worldeditor.hpp" diff --git a/src/nostalgia/world/studio/worldstudioplugin.cpp b/src/nostalgia/world/studio/worldstudioplugin.cpp index 7fd716f2..ec9ba34d 100644 --- a/src/nostalgia/world/studio/worldstudioplugin.cpp +++ b/src/nostalgia/world/studio/worldstudioplugin.cpp @@ -29,10 +29,14 @@ QVector WorldEditorPlugin::newWizards(const Context *ctx) { return {new NewWorldWizard(ctx)}; }, [ctx](QWizard *w) { - w->field(NewWorldWizard::FIELD_WORLD_PATH).toString(); - w->field(NewWorldWizard::FIELD_WIDTH).toInt(); - w->field(NewWorldWizard::FIELD_HEIGHT).toInt(); - return 0; + qDebug() << "creating Region"; + auto path = PATH_ZONES + w->field(NewWorldWizard::FIELD_WORLD_PATH).toString(); + Region rgn; + auto err = ctx->project->mkdir(PATH_ZONES); + ctx->project->saveRomFs(); + qDebug() << "err:" << err; + err |= ctx->project->writeObj(path, &rgn); + return err; } } }; diff --git a/src/nostalgia/world/world.cpp b/src/nostalgia/world/world.cpp index f2567e1d..ac75bef5 100644 --- a/src/nostalgia/world/world.cpp +++ b/src/nostalgia/world/world.cpp @@ -15,7 +15,6 @@ using namespace common; using namespace core; const int Zone::FIELDS = 1; -const int Region::FIELDS = 0; Zone::Zone(Context *ctx, Bounds bnds, InodeId_t tileSheet) { diff --git a/src/nostalgia/world/world.hpp b/src/nostalgia/world/world.hpp index d8f963e1..e68159f9 100644 --- a/src/nostalgia/world/world.hpp +++ b/src/nostalgia/world/world.hpp @@ -9,6 +9,7 @@ #pragma once #include +#include #include #include @@ -83,9 +84,12 @@ struct Region { template friend ox::Error ioOpWrite(T*, Region*); + enum { + FIELDS = 1 + }; + protected: - static const int FIELDS; - Zone *m_zones = nullptr; + ox::Vector m_zones; public: