Add utility.cpp, fix bug when map/layout name is just underscores

This commit is contained in:
GriffinR
2025-02-22 14:54:44 -05:00
parent 67c3a4befd
commit 1b510b6a6e
13 changed files with 82 additions and 57 deletions

View File

@@ -2,7 +2,7 @@
#include "map.h"
#include "imageproviders.h"
#include "scripting.h"
#include "utility.h"
#include "editcommands.h"
#include <QTime>
@@ -56,14 +56,9 @@ void Map::setLayout(Layout *layout) {
}
}
QString Map::mapConstantFromName(QString mapName, bool includePrefix) {
// Transform map names of the form 'GraniteCave_B1F` into map constants like 'MAP_GRANITE_CAVE_B1F'.
static const QRegularExpression caseChange("([a-z])([A-Z])");
QString nameWithUnderscores = mapName.replace(caseChange, "\\1_\\2");
const QString prefix = includePrefix ? projectConfig.getIdentifier(ProjectIdentifier::define_map_prefix) : "";
QString withMapAndUppercase = prefix + nameWithUnderscores.toUpper();
static const QRegularExpression underscores("_+");
return withMapAndUppercase.replace(underscores, "_");
// We don't enforce this for existing maps, but for creating new maps we need to formulaically generate a new MAP_NAME ID.
QString Map::mapConstantFromName(const QString &name) {
return projectConfig.getIdentifier(ProjectIdentifier::define_map_prefix) + Util::toDefineCase(name);
}
int Map::getWidth() const {