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/QtCore",
 | 
				
			||||||
                "/usr/include/x86_64-linux-gnu/qt5",
 | 
					                "/usr/include/x86_64-linux-gnu/qt5",
 | 
				
			||||||
                "${workspaceRoot}/deps/ox/src",
 | 
					                "${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": [],
 | 
					            "defines": [],
 | 
				
			||||||
            "intelliSenseMode": "clang-x64",
 | 
					            "intelliSenseMode": "clang-x64",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,7 @@ target_link_libraries(
 | 
				
			|||||||
		Qt5::Core
 | 
							Qt5::Core
 | 
				
			||||||
		Qt5::Widgets
 | 
							Qt5::Widgets
 | 
				
			||||||
		OxFS
 | 
							OxFS
 | 
				
			||||||
 | 
							OxMetalClaw
 | 
				
			||||||
		OxStd
 | 
							OxStd
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@
 | 
				
			|||||||
#include <QWizardPage>
 | 
					#include <QWizardPage>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "project.hpp"
 | 
					#include "project.hpp"
 | 
				
			||||||
 | 
					#include "wizard.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace nostalgia {
 | 
					namespace nostalgia {
 | 
				
			||||||
namespace studio {
 | 
					namespace studio {
 | 
				
			||||||
@@ -26,12 +27,6 @@ struct Context {
 | 
				
			|||||||
	const Project *project = nullptr;
 | 
						const Project *project = nullptr;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct WizardMaker {
 | 
					 | 
				
			||||||
	QString name;
 | 
					 | 
				
			||||||
	std::function<QVector<QWizardPage*>()> make;
 | 
					 | 
				
			||||||
	std::function<int(QWizard*)> onAccept;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct EditorMaker {
 | 
					struct EditorMaker {
 | 
				
			||||||
	virtual QWidget *make(QString path, const Context *ctx) = 0;
 | 
						virtual QWidget *make(QString path, const Context *ctx) = 0;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,7 +79,7 @@ FileSystem *Project::romFs() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Project::mkdir(QString path) const {
 | 
					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);
 | 
						emit updated(path);
 | 
				
			||||||
	return err;
 | 
						return err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,7 @@
 | 
				
			|||||||
#include <QSharedPointer>
 | 
					#include <QSharedPointer>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <ox/fs/filesystem.hpp>
 | 
					#include <ox/fs/filesystem.hpp>
 | 
				
			||||||
 | 
					#include <ox/mc/mc.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace nostalgia {
 | 
					namespace nostalgia {
 | 
				
			||||||
namespace studio {
 | 
					namespace studio {
 | 
				
			||||||
@@ -41,6 +42,12 @@ class Project: public QObject {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		int write(QString path, uint8_t *buff, size_t buffLen) const;
 | 
							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;
 | 
							ox::FileStat stat(QString path) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	signals:
 | 
						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() {
 | 
					void Wizard::accept() {
 | 
				
			||||||
	auto page = dynamic_cast<WizardFormPage*>(currentPage());
 | 
						auto page = dynamic_cast<WizardFormPage*>(currentPage());
 | 
				
			||||||
	if (page != nullptr && page->accept() == 0) {
 | 
						if (page != nullptr and page->accept() == 0 and
 | 
				
			||||||
		QDialog::accept();
 | 
						    m_acceptFunc != nullptr and m_acceptFunc(this) == 0) {
 | 
				
			||||||
	} else if (m_acceptFunc != nullptr && m_acceptFunc(this) == 0) {
 | 
					 | 
				
			||||||
		QDialog::accept();
 | 
							QDialog::accept();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,11 @@
 | 
				
			|||||||
namespace nostalgia {
 | 
					namespace nostalgia {
 | 
				
			||||||
namespace studio {
 | 
					namespace studio {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WizardMaker;
 | 
					struct WizardMaker {
 | 
				
			||||||
 | 
						QString name;
 | 
				
			||||||
 | 
						std::function<QVector<QWizardPage*>()> make;
 | 
				
			||||||
 | 
						std::function<int(QWizard*)> onAccept;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WizardSelect: public QWizardPage {
 | 
					class WizardSelect: public QWizardPage {
 | 
				
			||||||
	Q_OBJECT
 | 
						Q_OBJECT
 | 
				
			||||||
@@ -53,6 +57,7 @@ class WizardSelect: public QWizardPage {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class WizardFormPage: public QWizardPage {
 | 
					class WizardFormPage: public QWizardPage {
 | 
				
			||||||
	Q_OBJECT
 | 
						Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		struct Field {
 | 
							struct Field {
 | 
				
			||||||
			QString defaultValue = "";
 | 
								QString defaultValue = "";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -125,30 +125,36 @@ int run(ClArgs args) {
 | 
				
			|||||||
				fsBuff = fs->buff(); // update fsBuff pointer in case there is a new buff
 | 
									fsBuff = fs->buff(); // update fsBuff pointer in case there is a new buff
 | 
				
			||||||
				err |= fs->write(argInode, imgDataBuff, imgDataBuffSize);
 | 
									err |= fs->write(argInode, imgDataBuff, imgDataBuffSize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (argCompact) {
 | 
									if (!err) {
 | 
				
			||||||
					fs->resize();
 | 
										if (argCompact) {
 | 
				
			||||||
				}
 | 
											fs->resize();
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				auto fsFile = fopen(argFsPath.toUtf8(), "wb");
 | 
										auto fsFile = fopen(argFsPath.toUtf8(), "wb");
 | 
				
			||||||
				if (fsFile) {
 | 
										if (fsFile) {
 | 
				
			||||||
					err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1;
 | 
											err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1;
 | 
				
			||||||
					err |= fclose(fsFile);
 | 
											err |= fclose(fsFile);
 | 
				
			||||||
					if (err) {
 | 
											if (err) {
 | 
				
			||||||
						cerr << "Could not write to file system file.\n";
 | 
												cerr << "Could not write to file system file.\n";
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										} else {
 | 
				
			||||||
 | 
											err = 2;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					err = 2;
 | 
										err = 3;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				delete fs;
 | 
									delete fs;
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				err = 3;
 | 
									err = 4;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delete[] fsBuff;
 | 
							if (fsBuff) {
 | 
				
			||||||
 | 
								delete[] fsBuff;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		err = 4;
 | 
							err = 5;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return err;
 | 
						return err;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,8 +12,6 @@ target_link_libraries(
 | 
				
			|||||||
		Qt5::Core
 | 
							Qt5::Core
 | 
				
			||||||
		Qt5::Widgets
 | 
							Qt5::Widgets
 | 
				
			||||||
		NostalgiaStudio
 | 
							NostalgiaStudio
 | 
				
			||||||
		OxFS
 | 
					 | 
				
			||||||
		OxStd
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install(
 | 
					install(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,8 +17,6 @@ namespace world {
 | 
				
			|||||||
using namespace studio;
 | 
					using namespace studio;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const QString NewWorldWizard::FIELD_WORLD_PATH = "World.WorldPath";
 | 
					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) {
 | 
					NewWorldWizard::NewWorldWizard(const Context *ctx) {
 | 
				
			||||||
	addLineEdit(tr("&Name:"), FIELD_WORLD_PATH, "", [this, ctx](QString worldName) {
 | 
						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 {
 | 
					struct NewWorldWizard: public studio::WizardFormPage {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static const QString FIELD_WORLD_PATH;
 | 
						static const QString FIELD_WORLD_PATH;
 | 
				
			||||||
	static const QString FIELD_WIDTH;
 | 
					 | 
				
			||||||
	static const QString FIELD_HEIGHT;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	NewWorldWizard(const studio::Context *ctx);
 | 
						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"
 | 
					#include "worldeditor.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,10 +29,14 @@ QVector<WizardMaker> WorldEditorPlugin::newWizards(const Context *ctx) {
 | 
				
			|||||||
				return {new NewWorldWizard(ctx)};
 | 
									return {new NewWorldWizard(ctx)};
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			[ctx](QWizard *w) {
 | 
								[ctx](QWizard *w) {
 | 
				
			||||||
				w->field(NewWorldWizard::FIELD_WORLD_PATH).toString();
 | 
									qDebug() << "creating Region";
 | 
				
			||||||
				w->field(NewWorldWizard::FIELD_WIDTH).toInt();
 | 
									auto path = PATH_ZONES + w->field(NewWorldWizard::FIELD_WORLD_PATH).toString();
 | 
				
			||||||
				w->field(NewWorldWizard::FIELD_HEIGHT).toInt();
 | 
									Region rgn;
 | 
				
			||||||
				return 0;
 | 
									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;
 | 
					using namespace core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const int Zone::FIELDS = 1;
 | 
					const int Zone::FIELDS = 1;
 | 
				
			||||||
const int Region::FIELDS = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Zone::Zone(Context *ctx, Bounds bnds, InodeId_t tileSheet) {
 | 
					Zone::Zone(Context *ctx, Bounds bnds, InodeId_t tileSheet) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <ox/mc/mc.hpp>
 | 
					#include <ox/mc/mc.hpp>
 | 
				
			||||||
 | 
					#include <ox/std/std.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <nostalgia/common/common.hpp>
 | 
					#include <nostalgia/common/common.hpp>
 | 
				
			||||||
#include <nostalgia/core/core.hpp>
 | 
					#include <nostalgia/core/core.hpp>
 | 
				
			||||||
@@ -83,9 +84,12 @@ struct Region {
 | 
				
			|||||||
	template<typename T>
 | 
						template<typename T>
 | 
				
			||||||
	friend ox::Error ioOpWrite(T*, Region*);
 | 
						friend ox::Error ioOpWrite(T*, Region*);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						enum {
 | 
				
			||||||
 | 
							FIELDS = 1
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected:
 | 
						protected:
 | 
				
			||||||
		static const int FIELDS;
 | 
							ox::Vector<Zone*> m_zones;
 | 
				
			||||||
		Zone *m_zones = nullptr;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user