From 7ab7f09fe396fb66e853ad2a452b3f028af44491 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 6 Mar 2025 01:44:37 -0500 Subject: [PATCH] Expose file extension regex to config --- docsrc/manual/project-files.rst | 4 ++++ include/config.h | 4 ++++ include/project.h | 3 +++ src/config.cpp | 5 +++++ src/core/tileset.cpp | 7 ++++--- src/project.cpp | 12 +++++------- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/docsrc/manual/project-files.rst b/docsrc/manual/project-files.rst index d4c47950..4917be1d 100644 --- a/docsrc/manual/project-files.rst +++ b/docsrc/manual/project-files.rst @@ -131,3 +131,7 @@ In addition to these files, there are some specific symbol and macro names that ``regex_sign_facing_directions``, ``\bBG_EVENT_PLAYER_FACING_``, regex to find sign facing direction macro names ``regex_trainer_types``, ``\bTRAINER_TYPE_``, regex to find trainer type macro names ``regex_music``, ``\b(SE|MUS)_``, regex to find music macro names + ``regex_gbapal``, ``\.gbapal(\.[\w]+)?$``, regex to get the expected file extension for ``.pal`` data files + ``regex_bpp``, ``\.[\d]+bpp(\.[\w]+)?$``, regex to get the expected file extension for ``.png`` data files + ``pals_output_extension``, ``.gbapal``, the file extension to output for a new tileset's palette data files + ``tiles_output_extension``, ``.4bpp.lz``, the file extension to output for a new tileset's tiles image data file diff --git a/include/config.h b/include/config.h index b800fe1b..1df1b4ef 100644 --- a/include/config.h +++ b/include/config.h @@ -242,6 +242,10 @@ enum ProjectIdentifier { regex_sign_facing_directions, regex_trainer_types, regex_music, + regex_gbapal, + regex_bpp, + pals_output_extension, + tiles_output_extension, }; enum ProjectFilePath { diff --git a/include/project.h b/include/project.h index 5330b792..f7a4b5cc 100644 --- a/include/project.h +++ b/include/project.h @@ -258,6 +258,9 @@ private: QMap facingDirections; QMap speciesToIconPath; + const QRegularExpression re_gbapalExtension; + const QRegularExpression re_bppExtension; + struct EventGraphics { QString filepath; diff --git a/src/config.cpp b/src/config.cpp index 232d7e66..1847cfcf 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -125,6 +125,11 @@ const QMap> ProjectConfig::defaultIde {ProjectIdentifier::regex_sign_facing_directions, {"regex_sign_facing_directions", "\\bBG_EVENT_PLAYER_FACING_"}}, {ProjectIdentifier::regex_trainer_types, {"regex_trainer_types", "\\bTRAINER_TYPE_"}}, {ProjectIdentifier::regex_music, {"regex_music", "\\b(SE|MUS)_"}}, + {ProjectIdentifier::regex_gbapal, {"regex_gbapal", "\\.gbapal(\\.[\\w]+)?$"}}, + {ProjectIdentifier::regex_bpp, {"regex_bpp", "\\.[\\d]+bpp(\\.[\\w]+)?$"}}, + // Other + {ProjectIdentifier::pals_output_extension, {"pals_output_extension", ".gbapal"}}, + {ProjectIdentifier::tiles_output_extension, {"tiles_output_extension", ".4bpp.lz"}}, }; const QMap> ProjectConfig::defaultPaths = { diff --git a/src/core/tileset.cpp b/src/core/tileset.cpp index da5fcf54..f6ce6a2e 100644 --- a/src/core/tileset.cpp +++ b/src/core/tileset.cpp @@ -304,8 +304,9 @@ bool Tileset::appendToGraphics(QString root, QString friendlyName, bool usingAsm } const QString tilesetDir = this->getExpectedDir(); - const QString tilesPath = tilesetDir + "/tiles.4bpp.lz"; + const QString tilesPath = QString("%1/tiles%2").arg(tilesetDir).arg(projectConfig.getIdentifier(ProjectIdentifier::tiles_output_extension)); const QString palettesPath = tilesetDir + "/palettes/"; + const QString palettesExt = projectConfig.getIdentifier(ProjectIdentifier::pals_output_extension); QString dataString = "\n"; if (usingAsm) { @@ -313,7 +314,7 @@ bool Tileset::appendToGraphics(QString root, QString friendlyName, bool usingAsm dataString.append("\t.align 2\n"); dataString.append(QString("gTilesetPalettes_%1::\n").arg(friendlyName)); for (int i = 0; i < Project::getNumPalettesTotal(); i++) - dataString.append(QString("\t.incbin \"%1%2.gbapal\"\n").arg(palettesPath).arg(i, 2, 10, QLatin1Char('0'))); + dataString.append(QString("\t.incbin \"%1%2%3\"\n").arg(palettesPath).arg(i, 2, 10, QLatin1Char('0')).arg(palettesExt)); dataString.append("\n\t.align 2\n"); dataString.append(QString("gTilesetTiles_%1::\n").arg(friendlyName)); dataString.append(QString("\t.incbin \"%1\"\n").arg(tilesPath)); @@ -321,7 +322,7 @@ bool Tileset::appendToGraphics(QString root, QString friendlyName, bool usingAsm // Append to C file dataString.append(QString("const u16 gTilesetPalettes_%1[][16] =\n{\n").arg(friendlyName)); for (int i = 0; i < Project::getNumPalettesTotal(); i++) - dataString.append(QString(" INCBIN_U16(\"%1%2.gbapal\"),\n").arg(palettesPath).arg(i, 2, 10, QLatin1Char('0'))); + dataString.append(QString(" INCBIN_U16(\"%1%2%3\"),\n").arg(palettesPath).arg(i, 2, 10, QLatin1Char('0')).arg(palettesExt)); dataString.append("};\n"); dataString.append(QString("\nconst u32 gTilesetTiles_%1[] = INCBIN_U32(\"%2\");\n").arg(friendlyName, tilesPath)); } diff --git a/src/project.cpp b/src/project.cpp index 7ed80174..c1a0cd07 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -33,7 +33,9 @@ int Project::max_map_data_size = 10240; // 0x2800 int Project::default_map_dimension = 20; Project::Project(QObject *parent) : - QObject(parent) + QObject(parent), + re_gbapalExtension(projectConfig.getIdentifier(ProjectIdentifier::regex_gbapal)), + re_bppExtension(projectConfig.getIdentifier(ProjectIdentifier::regex_bpp)) { QObject::connect(&this->fileWatcher, &QFileSystemWatcher::fileChanged, this, &Project::recordFileChange); } @@ -2654,16 +2656,12 @@ void Project::insertGlobalScriptLabels(QStringList &scriptLabels) const { } QString Project::fixPalettePath(QString path) { - static const QRegularExpression re_gbapal("\\.gbapal$"); - path = path.replace(re_gbapal, ".pal"); + path.replace(this->re_gbapalExtension, ".pal"); return path; } QString Project::fixGraphicPath(QString path) { - static const QRegularExpression re_lz("\\.lz$"); - path = path.replace(re_lz, ""); - static const QRegularExpression re_bpp("\\.[1248]bpp$"); - path = path.replace(re_bpp, ".png"); + path.replace(this->re_bppExtension, ".png"); return path; }