Make TileSheet import write tilesheets to ROM FS

This commit is contained in:
Gary Talent 2017-05-22 01:37:34 -05:00
parent bc69e67a5b
commit 38a3113ab6
6 changed files with 44 additions and 13 deletions

View File

@ -46,8 +46,23 @@ int ImportTilesheetWizardPage::accept() {
}
}
int ImportTilesheetWizardPage::importImage(QFile &src, QString tilesetName) {
return 1;
int ImportTilesheetWizardPage::importImage(QFile &srcFile, QString tilesheetName) {
auto buffSize = srcFile.size();
uint8_t buff[buffSize];
if (srcFile.exists()) {
srcFile.open(QIODevice::ReadOnly);
if (srcFile.read((char*) buff, buffSize) > 0) {
int err = 0;
m_project->mkdir("/TileSheets");
err |= m_project->write("/TileSheets/" + tilesheetName, buff, buffSize);
err |= m_project->saveRomFs();
return err;
} else {
return 1;
}
} else {
return 2;
}
}
}

View File

@ -26,7 +26,7 @@ class ImportTilesheetWizardPage: public studio::WizardFormPage {
int accept();
private:
int importImage(QFile &src, QString dest);
int importImage(QFile &srcFile, QString dest);
};
}

View File

@ -41,7 +41,7 @@ void Project::create() {
file.close();
}
int Project::open() {
int Project::openRomFs() {
QFile file(m_path + ROM_FILE);
auto buffSize = file.size();
auto buff = new uint8_t[buffSize];
@ -58,16 +58,26 @@ int Project::open() {
}
}
void Project::save() {
int Project::saveRomFs() {
int err = 0;
QFile file(m_path + ROM_FILE);
file.open(QIODevice::WriteOnly);
file.write((const char*) m_fs->buff(), m_fs->size());
err |= file.open(QIODevice::WriteOnly) == false;
err |= file.write((const char*) m_fs->buff(), m_fs->size()) == -1;
file.close();
return err;
}
FileSystem *Project::romFS() {
FileSystem *Project::romFs() {
return m_fs;
}
int Project::mkdir(QString path) {
return m_fs->mkdir(path.toUtf8().data());
}
int Project::write(QString path, uint8_t *buff, size_t buffLen) {
return m_fs->write(path.toUtf8().data(), buff, buffLen);
}
}
}

View File

@ -31,11 +31,15 @@ class Project: public QObject {
void create();
int open();
int openRomFs();
void save();
int saveRomFs();
ox::FileSystem *romFS();
ox::FileSystem *romFs();
int mkdir(QString path);
int write(QString path, uint8_t *buff, size_t buffLen);
};
}

View File

@ -333,6 +333,8 @@ void Wizard::accept() {
auto page = dynamic_cast<WizardFormPage*>(currentPage());
if (page == nullptr || page->accept() == 0) {
QDialog::accept();
} else if(m_acceptFunc != nullptr && m_acceptFunc() == 0) {
QDialog::accept();
}
}

View File

@ -219,14 +219,14 @@ int MainWindow::writeState(QString path) {
int MainWindow::openProject(QString projectPath) {
auto err = closeProject();
auto project = new Project(projectPath);
err |= project->open();
err |= project->openRomFs();
if (err == 0) {
if (m_project) {
delete m_project;
m_project = nullptr;
}
m_project = project;
m_projectExplorer->setModel(new OxFSModel(m_project->romFS()));
m_projectExplorer->setModel(new OxFSModel(m_project->romFs()));
m_importAction->setEnabled(true);
m_state.projectPath = projectPath;
}