Add new Zone wizard
This commit is contained in:
		
							
								
								
									
										4
									
								
								.vscode/c_cpp_properties.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.vscode/c_cpp_properties.json
									
									
									
									
										vendored
									
									
								
							@@ -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",
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,7 @@ target_link_libraries(
 | 
			
		||||
		Qt5::Core
 | 
			
		||||
		Qt5::Widgets
 | 
			
		||||
		OxFS
 | 
			
		||||
		OxMetalClaw
 | 
			
		||||
		OxStd
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 = "";
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -12,8 +12,6 @@ target_link_libraries(
 | 
			
		||||
		Qt5::Core
 | 
			
		||||
		Qt5::Widgets
 | 
			
		||||
		NostalgiaStudio
 | 
			
		||||
		OxFS
 | 
			
		||||
		OxStd
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
install(
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -29,10 +29,14 @@ QVector<WizardMaker> 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;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <ox/mc/mc.hpp>
 | 
			
		||||
#include <ox/std/std.hpp>
 | 
			
		||||
 | 
			
		||||
#include <nostalgia/common/common.hpp>
 | 
			
		||||
#include <nostalgia/core/core.hpp>
 | 
			
		||||
@@ -83,9 +84,12 @@ struct Region {
 | 
			
		||||
	template<typename T>
 | 
			
		||||
	friend ox::Error ioOpWrite(T*, Region*);
 | 
			
		||||
 | 
			
		||||
	enum {
 | 
			
		||||
		FIELDS = 1
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	protected:
 | 
			
		||||
		static const int FIELDS;
 | 
			
		||||
		Zone *m_zones = nullptr;
 | 
			
		||||
		ox::Vector<Zone*> m_zones;
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user