Fix map connections.

Since map constants can be inferred from map names, but not the other
way around, create a mapping between map constants and map names and use
that to find the connected map.
This commit is contained in:
Marcus Huderle
2018-02-12 08:42:01 -08:00
parent 0452156372
commit d7756865a9
4 changed files with 35 additions and 3 deletions

19
map.cpp
View File

@@ -4,6 +4,7 @@
#include <QDebug>
#include <QPainter>
#include <QImage>
#include <QRegularExpression>
Map::Map(QObject *parent) : QObject(parent)
{
@@ -16,6 +17,24 @@ Map::Map(QObject *parent) : QObject(parent)
paint_elevation = 3;
}
void Map::setName(QString mapName) {
name = mapName;
constantName = mapConstantFromName(mapName);
}
QString Map::mapConstantFromName(QString mapName) {
// Transform map names of the form 'GraniteCave_B1F` into map constants like 'MAP_GRANITE_CAVE_B1F'.
QString nameWithUnderscores = mapName.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2");
QString withMapAndUppercase = "MAP_" + nameWithUnderscores.toUpper();
QString constantName = withMapAndUppercase.replace(QRegularExpression("_+"), "_");
// Handle special cases.
// SSTidal needs to be SS_TIDAL, rather than SSTIDAL
constantName = constantName.replace("SSTIDAL", "SS_TIDAL");
return constantName;
}
int Map::getWidth() {
return width.toInt(nullptr, 0);
}