Expose file extension regex to config

This commit is contained in:
GriffinR 2025-03-06 01:44:37 -05:00
parent d43252506f
commit 7ab7f09fe3
6 changed files with 25 additions and 10 deletions

View File

@ -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

View File

@ -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 {

View File

@ -258,6 +258,9 @@ private:
QMap<QString, QString> facingDirections;
QMap<QString, QString> speciesToIconPath;
const QRegularExpression re_gbapalExtension;
const QRegularExpression re_bppExtension;
struct EventGraphics
{
QString filepath;

View File

@ -125,6 +125,11 @@ const QMap<ProjectIdentifier, QPair<QString, QString>> 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<ProjectFilePath, QPair<QString, QString>> ProjectConfig::defaultPaths = {

View File

@ -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));
}

View File

@ -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;
}