mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-13 20:36:19 -05:00
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:
19
map.cpp
19
map.cpp
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user