Add missing project file path usage
This commit is contained in:
parent
4f5d98b81a
commit
fa76e22508
7 changed files with 35 additions and 26 deletions
|
@ -144,6 +144,7 @@ enum ProjectFilePath {
|
|||
data_map_folders,
|
||||
data_scripts_folders,
|
||||
data_layouts_folders,
|
||||
data_tilesets_folders,
|
||||
data_event_scripts,
|
||||
json_map_groups,
|
||||
json_layouts,
|
||||
|
|
|
@ -20,6 +20,7 @@ const QMap<ProjectFilePath, std::pair<QString, QString>> defaultPaths = {
|
|||
{ProjectFilePath::data_map_folders, { "data_map_folders", "data/maps/"}},
|
||||
{ProjectFilePath::data_scripts_folders, { "data_scripts_folders", "data/scripts/"}},
|
||||
{ProjectFilePath::data_layouts_folders, { "data_layouts_folders", "data/layouts/"}},
|
||||
{ProjectFilePath::data_tilesets_folders, { "data_tilesets_folders", "data/tilesets/"}},
|
||||
{ProjectFilePath::data_event_scripts, { "data_event_scripts", "data/event_scripts.s"}},
|
||||
{ProjectFilePath::json_map_groups, { "json_map_groups", "data/maps/map_groups.json"}},
|
||||
{ProjectFilePath::json_layouts, { "json_layouts", "data/layouts/layouts.json"}},
|
||||
|
|
|
@ -161,6 +161,7 @@ bool Tileset::appendToHeaders(QString headerFile, QString friendlyName){
|
|||
|
||||
bool Tileset::appendToGraphics(QString graphicsFile, QString friendlyName, bool primary) {
|
||||
QString primaryString = primary ? "primary" : "secondary";
|
||||
QString basePath = projectConfig.getFilePath(ProjectFilePath::data_tilesets_folders);
|
||||
QFile file(graphicsFile);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||||
logError(QString("Could not write to file \"%1\"").arg(graphicsFile));
|
||||
|
@ -170,12 +171,12 @@ bool Tileset::appendToGraphics(QString graphicsFile, QString friendlyName, bool
|
|||
dataString.append(QString("gTilesetPalettes_%1::\n").arg(friendlyName));
|
||||
for(int i = 0; i < Project::getNumPalettesTotal(); ++i) {
|
||||
QString paletteString = QString("%1.gbapal").arg(i, 2, 10, QLatin1Char('0'));
|
||||
dataString.append(QString("\t.incbin \"data/tilesets/%1/%2/palettes/%3\"\n").arg(primaryString, friendlyName.toLower(), paletteString));
|
||||
dataString.append(QString("\t.incbin \"%1%2/%3/palettes/%4\"\n").arg(basePath, primaryString, friendlyName.toLower(), paletteString));
|
||||
|
||||
}
|
||||
dataString.append("\n\t.align 2\n");
|
||||
dataString.append(QString("gTilesetTiles_%1::\n").arg(friendlyName));
|
||||
dataString.append(QString("\t.incbin \"data/tilesets/%1/%2/tiles.4bpp.lz\"\n").arg(primaryString, friendlyName.toLower()));
|
||||
dataString.append(QString("\t.incbin \"%1%2/%3/tiles.4bpp.lz\"\n").arg(basePath, primaryString, friendlyName.toLower()));
|
||||
file.write(dataString.toUtf8());
|
||||
file.flush();
|
||||
file.close();
|
||||
|
@ -184,6 +185,7 @@ bool Tileset::appendToGraphics(QString graphicsFile, QString friendlyName, bool
|
|||
|
||||
bool Tileset::appendToMetatiles(QString metatileFile, QString friendlyName, bool primary) {
|
||||
QString primaryString = primary ? "primary" : "secondary";
|
||||
QString basePath = projectConfig.getFilePath(ProjectFilePath::data_tilesets_folders);
|
||||
QFile file(metatileFile);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||||
logError(QString("Could not write to file \"%1\"").arg(metatileFile));
|
||||
|
@ -191,10 +193,10 @@ bool Tileset::appendToMetatiles(QString metatileFile, QString friendlyName, bool
|
|||
}
|
||||
QString dataString = "\n\t.align 1\n";
|
||||
dataString.append(QString("gMetatiles_%1::\n").arg(friendlyName));
|
||||
dataString.append(QString("\t.incbin \"data/tilesets/%1/%2/metatiles.bin\"\n").arg(primaryString, friendlyName.toLower()));
|
||||
dataString.append(QString("\t.incbin \"%1%2/%3/metatiles.bin\"\n").arg(basePath, primaryString, friendlyName.toLower()));
|
||||
dataString.append(QString("\n\t.align 1\n"));
|
||||
dataString.append(QString("gMetatileAttributes_%1::\n").arg(friendlyName));
|
||||
dataString.append(QString("\t.incbin \"data/tilesets/%1/%2/metatile_attributes.bin\"\n").arg(primaryString, friendlyName.toLower()));
|
||||
dataString.append(QString("\t.incbin \"%1%2/%3/metatile_attributes.bin\"\n").arg(basePath, primaryString, friendlyName.toLower()));
|
||||
file.write(dataString.toUtf8());
|
||||
file.flush();
|
||||
file.close();
|
||||
|
|
|
@ -1342,9 +1342,9 @@ void MainWindow::on_actionNew_Tileset_triggered() {
|
|||
|
||||
//append to tileset specific files
|
||||
|
||||
newSet.appendToHeaders(editor->project->root + "/data/tilesets/headers.inc", createTilesetDialog->friendlyName);
|
||||
newSet.appendToGraphics(editor->project->root + "/data/tilesets/graphics.inc", createTilesetDialog->friendlyName, !createTilesetDialog->isSecondary);
|
||||
newSet.appendToMetatiles(editor->project->root + "/data/tilesets/metatiles.inc", createTilesetDialog->friendlyName, !createTilesetDialog->isSecondary);
|
||||
newSet.appendToHeaders(editor->project->root + "/" + projectConfig.getFilePath(ProjectFilePath::tilesets_headers), createTilesetDialog->friendlyName);
|
||||
newSet.appendToGraphics(editor->project->root + "/" + projectConfig.getFilePath(ProjectFilePath::tilesets_graphics), createTilesetDialog->friendlyName, !createTilesetDialog->isSecondary);
|
||||
newSet.appendToMetatiles(editor->project->root + "/" + projectConfig.getFilePath(ProjectFilePath::tilesets_metatiles), createTilesetDialog->friendlyName, !createTilesetDialog->isSecondary);
|
||||
if(!createTilesetDialog->isSecondary) {
|
||||
this->ui->comboBox_PrimaryTileset->addItem(createTilesetDialog->fullSymbolName);
|
||||
} else {
|
||||
|
|
|
@ -627,7 +627,7 @@ bool Project::readMapLayouts() {
|
|||
}
|
||||
|
||||
void Project::saveMapLayouts() {
|
||||
QString layoutsFilepath = QString("%1/%2").arg(root).arg(projectConfig.getFilePath(ProjectFilePath::json_layouts));
|
||||
QString layoutsFilepath = root + "/" + projectConfig.getFilePath(ProjectFilePath::json_layouts);
|
||||
QFile layoutsFile(layoutsFilepath);
|
||||
if (!layoutsFile.open(QIODevice::WriteOnly)) {
|
||||
logError(QString("Error: Could not open %1 for writing").arg(layoutsFilepath));
|
||||
|
@ -821,7 +821,8 @@ void Project::saveWildMonData() {
|
|||
void Project::saveMapConstantsHeader() {
|
||||
QString text = QString("#ifndef GUARD_CONSTANTS_MAP_GROUPS_H\n");
|
||||
text += QString("#define GUARD_CONSTANTS_MAP_GROUPS_H\n");
|
||||
text += QString("\n//\n// DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/map_groups.json\n//\n\n");
|
||||
text += QString("\n//\n// DO NOT MODIFY THIS FILE! It is auto-generated from %1\n//\n\n")
|
||||
.arg(projectConfig.getFilePath(ProjectFilePath::json_map_groups));
|
||||
|
||||
int groupNum = 0;
|
||||
for (QStringList mapNames : groupedMapNames) {
|
||||
|
@ -1132,7 +1133,7 @@ bool Project::loadLayoutTilesets(MapLayout *layout) {
|
|||
}
|
||||
|
||||
Tileset* Project::loadTileset(QString label, Tileset *tileset) {
|
||||
const QStringList values = parser.getLabelValues(parser.parseAsm("data/tilesets/headers.inc"), label);
|
||||
const QStringList values = parser.getLabelValues(parser.parseAsm(projectConfig.getFilePath(ProjectFilePath::tilesets_headers)), label);
|
||||
if (values.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1250,7 +1251,8 @@ void Project::saveAllMaps() {
|
|||
|
||||
void Project::saveMap(Map *map) {
|
||||
// Create/Modify a few collateral files for brand new maps.
|
||||
QString mapDataDir = QString(root + "/data/maps/%1").arg(map->name);
|
||||
QString basePath = projectConfig.getFilePath(ProjectFilePath::data_map_folders);
|
||||
QString mapDataDir = root + "/" + basePath + map->name;
|
||||
if (!map->isPersistedToFile) {
|
||||
if (!QDir::root().mkdir(mapDataDir)) {
|
||||
logError(QString("Error: failed to create directory for new map: '%1'").arg(mapDataDir));
|
||||
|
@ -1258,30 +1260,30 @@ void Project::saveMap(Map *map) {
|
|||
|
||||
// Create file data/maps/<map_name>/scripts.inc
|
||||
QString text = this->getScriptDefaultString(projectConfig.getUsePoryScript(), map->name);
|
||||
saveTextFile(root + "/data/maps/" + map->name + "/scripts" + this->getScriptFileExtension(projectConfig.getUsePoryScript()), text);
|
||||
saveTextFile(mapDataDir + "/scripts" + this->getScriptFileExtension(projectConfig.getUsePoryScript()), text);
|
||||
|
||||
bool usesTextFile = projectConfig.getCreateMapTextFileEnabled();
|
||||
if (usesTextFile) {
|
||||
// Create file data/maps/<map_name>/text.inc
|
||||
saveTextFile(root + "/data/maps/" + map->name + "/text" + this->getScriptFileExtension(projectConfig.getUsePoryScript()), "\n");
|
||||
saveTextFile(mapDataDir + "/text" + this->getScriptFileExtension(projectConfig.getUsePoryScript()), "\n");
|
||||
}
|
||||
|
||||
// Simply append to data/event_scripts.s.
|
||||
text = QString("\n\t.include \"data/maps/%1/scripts.inc\"\n").arg(map->name);
|
||||
text = QString("\n\t.include \"%1%2/scripts.inc\"\n").arg(basePath, map->name);
|
||||
if (usesTextFile) {
|
||||
text += QString("\t.include \"data/maps/%1/text.inc\"\n").arg(map->name);
|
||||
text += QString("\t.include \"%1%2/text.inc\"\n").arg(basePath, map->name);
|
||||
}
|
||||
appendTextFile(root + "/data/event_scripts.s", text);
|
||||
appendTextFile(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_event_scripts), text);
|
||||
|
||||
if (map->needsLayoutDir) {
|
||||
QString newLayoutDir = QString(root + "/data/layouts/%1").arg(map->name);
|
||||
QString newLayoutDir = QString(root + "/%1%2").arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders), map->name);
|
||||
if (!QDir::root().mkdir(newLayoutDir)) {
|
||||
logError(QString("Error: failed to create directory for new layout: '%1'").arg(newLayoutDir));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString layoutsFilepath = QString("%1/data/layouts/layouts.json").arg(root);
|
||||
QString layoutsFilepath = root + "/" + projectConfig.getFilePath(ProjectFilePath::json_layouts);
|
||||
QJsonDocument layoutsDoc;
|
||||
if (!parser.tryParseJsonFile(&layoutsDoc, layoutsFilepath)) {
|
||||
logError(QString("Failed to read map layouts from %1").arg(layoutsFilepath));
|
||||
|
@ -1475,9 +1477,10 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
|||
}
|
||||
QRegularExpression re("([a-z])([A-Z0-9])");
|
||||
QString tilesetName = tileset->name;
|
||||
QString dir_path = root + "/data/tilesets/" + category + '/' + tilesetName.replace("gTileset_", "").replace(re, "\\1_\\2").toLower();
|
||||
QString basePath = root + "/" + projectConfig.getFilePath(ProjectFilePath::data_tilesets_folders) + category + "/";
|
||||
QString dir_path = basePath + tilesetName.replace("gTileset_", "").replace(re, "\\1_\\2").toLower();
|
||||
|
||||
const QList<QStringList> graphics = parser.parseAsm("data/tilesets/graphics.inc");
|
||||
const QList<QStringList> graphics = parser.parseAsm(projectConfig.getFilePath(ProjectFilePath::tilesets_graphics));
|
||||
const QStringList tiles_values = parser.getLabelValues(graphics, tileset->tiles_label);
|
||||
const QStringList palettes_values = parser.getLabelValues(graphics, tileset->palettes_label);
|
||||
|
||||
|
@ -1502,7 +1505,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
|||
}
|
||||
}
|
||||
|
||||
const QList<QStringList> metatiles_macros = parser.parseAsm("data/tilesets/metatiles.inc");
|
||||
const QList<QStringList> metatiles_macros = parser.parseAsm(projectConfig.getFilePath(ProjectFilePath::tilesets_metatiles));
|
||||
const QStringList metatiles_values = parser.getLabelValues(metatiles_macros, tileset->metatiles_label);
|
||||
if (!metatiles_values.isEmpty()) {
|
||||
tileset->metatiles_path = root + '/' + metatiles_values.value(0).section('"', 1, 1);
|
||||
|
@ -1802,7 +1805,7 @@ bool Project::readMapGroups() {
|
|||
mapNamesToMapConstants.clear();
|
||||
mapGroups.clear();
|
||||
|
||||
QString mapGroupsFilepath = QString("%1/data/maps/map_groups.json").arg(root);
|
||||
QString mapGroupsFilepath = root + "/" + projectConfig.getFilePath(ProjectFilePath::json_map_groups);
|
||||
fileWatcher.addPath(mapGroupsFilepath);
|
||||
QJsonDocument mapGroupsDoc;
|
||||
if (!parser.tryParseJsonFile(&mapGroupsDoc, mapGroupsFilepath)) {
|
||||
|
@ -1912,7 +1915,7 @@ QMap<QString, QStringList> Project::getTilesetLabels() {
|
|||
allTilesets.insert("secondary", secondaryTilesets);
|
||||
QList<QString> tilesetLabelsOrdered;
|
||||
|
||||
QString filename = "data/tilesets/headers.inc";
|
||||
QString filename = projectConfig.getFilePath(ProjectFilePath::tilesets_headers);
|
||||
QString headers_text = parser.readTextFile(root + "/" + filename);
|
||||
if (headers_text.isEmpty()) {
|
||||
logError(QString("Failed to read tileset labels from %1.").arg(filename));
|
||||
|
|
|
@ -291,8 +291,9 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
|
|||
}
|
||||
layout->tileset_primary_label = this->ui->comboBox_NewMap_Primary_Tileset->currentText();
|
||||
layout->tileset_secondary_label = this->ui->comboBox_NewMap_Secondary_Tileset->currentText();
|
||||
layout->border_path = QString("data/layouts/%1/border.bin").arg(newMapName);
|
||||
layout->blockdata_path = QString("data/layouts/%1/map.bin").arg(newMapName);
|
||||
QString basePath = projectConfig.getFilePath(ProjectFilePath::data_layouts_folders);
|
||||
layout->border_path = QString("%1%2/border.bin").arg(basePath, newMapName);
|
||||
layout->blockdata_path = QString("%1%2/map.bin").arg(basePath, newMapName);
|
||||
}
|
||||
|
||||
if (this->importedMap) {
|
||||
|
|
|
@ -35,6 +35,7 @@ void NewTilesetDialog::NameOrSecondaryChanged() {
|
|||
this->friendlyName = this->ui->nameLineEdit->text();
|
||||
this->fullSymbolName = "gTileset_" + this->friendlyName;
|
||||
this->ui->symbolNameLineEdit->setText(this->fullSymbolName);
|
||||
this->path = QString("/data/tilesets/") + (this->isSecondary ? "secondary/" : "primary/") + this->friendlyName.toLower();
|
||||
QString basePath = "/" + projectConfig.getFilePath(ProjectFilePath::data_tilesets_folders);
|
||||
this->path = basePath + (this->isSecondary ? "secondary/" : "primary/") + this->friendlyName.toLower();
|
||||
this->ui->pathLineEdit->setText(this->path);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue