mirror of
https://github.com/huderlem/porymap.git
synced 2026-04-24 14:57:08 -05:00
Simplify graphics file extension replacement
This commit is contained in:
parent
947142e370
commit
658835bebd
|
|
@ -142,8 +142,6 @@ In addition to these files, there are some specific symbol and macro names that
|
|||
``regex_music``, ``\b(SE|MUS)_``, "regex to populate ``Song`` dropdown for maps"
|
||||
``regex_encounter_types``, ``\bTILE_ENCOUNTER_``, "regex to populate the ``Encounter Type`` dropdown for the Tileset Editor"
|
||||
``regex_terrain_types``, ``\bTILE_TERRAIN_``, "regex to populate the ``Terrain Type`` dropdown for the Tileset Editor"
|
||||
``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"
|
||||
|
||||
|
|
|
|||
|
|
@ -271,8 +271,6 @@ enum ProjectIdentifier {
|
|||
regex_music,
|
||||
regex_encounter_types,
|
||||
regex_terrain_types,
|
||||
regex_gbapal,
|
||||
regex_bpp,
|
||||
pals_output_extension,
|
||||
tiles_output_extension,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace Util {
|
|||
QString toHexString(uint32_t value, int minLength = 0);
|
||||
QString toHtmlParagraph(const QString &text);
|
||||
Qt::Orientations getOrientation(bool xflip, bool yflip);
|
||||
QString replaceExtension(const QString &path, const QString &newExtension);
|
||||
}
|
||||
|
||||
#endif // UTILITY_H
|
||||
|
|
|
|||
|
|
@ -211,8 +211,8 @@ public:
|
|||
QPixmap getEventPixmap(Event::Group group);
|
||||
void loadEventPixmap(Event *event, bool forceLoad = false);
|
||||
|
||||
QString fixPalettePath(QString path);
|
||||
QString fixGraphicPath(QString path);
|
||||
QString fixPalettePath(const QString &path) const;
|
||||
QString fixGraphicPath(const QString &path) const;
|
||||
|
||||
static QString getScriptFileExtension(bool usePoryScript);
|
||||
QString getScriptDefaultString(bool usePoryScript, QString mapName) const;
|
||||
|
|
|
|||
|
|
@ -133,8 +133,6 @@ const QMap<ProjectIdentifier, QPair<QString, QString>> ProjectConfig::defaultIde
|
|||
{ProjectIdentifier::regex_music, {"regex_music", "\\b(SE|MUS)_"}},
|
||||
{ProjectIdentifier::regex_encounter_types, {"regex_encounter_types", "\\bTILE_ENCOUNTER_"}},
|
||||
{ProjectIdentifier::regex_terrain_types, {"regex_terrain_types", "\\bTILE_TERRAIN_"}},
|
||||
{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"}},
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <QCollator>
|
||||
#include <QRegularExpression>
|
||||
#include <QFileInfo>
|
||||
|
||||
// Sometimes we want to sort names alphabetically to make them easier to find in large combo box lists.
|
||||
// QStringList::sort (as of writing) can only sort numbers in lexical order, which has an undesirable
|
||||
|
|
@ -53,3 +54,13 @@ Qt::Orientations Util::getOrientation(bool xflip, bool yflip) {
|
|||
if (yflip) flags |= Qt::Orientation::Vertical;
|
||||
return flags;
|
||||
}
|
||||
|
||||
QString Util::replaceExtension(const QString &path, const QString &newExtension) {
|
||||
if (path.isEmpty()) return path;
|
||||
int oldExtensionLen = QFileInfo(path).completeSuffix().length();
|
||||
QString basePath = path.left(path.size() - oldExtensionLen);
|
||||
if (!basePath.endsWith(".")) {
|
||||
basePath.append(".");
|
||||
}
|
||||
return basePath + newExtension;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ int Project::num_pals_primary = 6;
|
|||
int Project::num_pals_total = 13;
|
||||
|
||||
Project::Project(QObject *parent) :
|
||||
QObject(parent),
|
||||
re_gbapalExtension(projectConfig.getIdentifier(ProjectIdentifier::regex_gbapal)),
|
||||
re_bppExtension(projectConfig.getIdentifier(ProjectIdentifier::regex_bpp))
|
||||
QObject(parent)
|
||||
{
|
||||
QObject::connect(&this->fileWatcher, &QFileSystemWatcher::fileChanged, this, &Project::recordFileChange);
|
||||
}
|
||||
|
|
@ -2917,14 +2915,12 @@ void Project::insertGlobalScriptLabels(QStringList &scriptLabels) const {
|
|||
scriptLabels.removeDuplicates();
|
||||
}
|
||||
|
||||
QString Project::fixPalettePath(QString path) {
|
||||
path.replace(this->re_gbapalExtension, ".pal");
|
||||
return path;
|
||||
QString Project::fixPalettePath(const QString &path) const {
|
||||
return Util::replaceExtension(path, QStringLiteral("pal"));
|
||||
}
|
||||
|
||||
QString Project::fixGraphicPath(QString path) {
|
||||
path.replace(this->re_bppExtension, ".png");
|
||||
return path;
|
||||
QString Project::fixGraphicPath(const QString &path) const {
|
||||
return Util::replaceExtension(path, QStringLiteral("png"));
|
||||
}
|
||||
|
||||
QString Project::getScriptFileExtension(bool usePoryScript) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user