diff --git a/include/core/metatile.h b/include/core/metatile.h index 1570e350..92adb82c 100644 --- a/include/core/metatile.h +++ b/include/core/metatile.h @@ -75,7 +75,7 @@ public: static int getDefaultAttributesSize(BaseGameVersion version); static void setLayout(Project*); static QString getMetatileIdString(uint16_t metatileId) { - return "0x" + QString("%1").arg(metatileId, 3, 16, QChar('0')).toUpper(); + return "0x" + QString("%1").arg(metatileId, 4, 16, QChar('0')).toUpper(); }; static QString getMetatileIdStringList(const QList metatileIds) { QStringList metatiles; diff --git a/src/project.cpp b/src/project.cpp index 3c57e280..cfd76902 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1511,13 +1511,18 @@ bool Project::readTilesetMetatileLabels() { QMap defines = parser.readCDefinesByPrefix(metatileLabelsFilename, prefixes); for (QString label : defines.keys()) { + uint32_t metatileId = static_cast(defines[label]); + if (metatileId > Block::maxValue) { + metatileId &= Block::maxValue; + logWarn(QString("Value of metatile label '%1' truncated to %2").arg(label).arg(Metatile::getMetatileIdString(metatileId))); + } QString tilesetName = findMetatileLabelsTileset(label); if (!tilesetName.isEmpty()) { - metatileLabelsMap[tilesetName][label] = defines[label]; + metatileLabelsMap[tilesetName][label] = metatileId; } else { // This #define name does not match any existing tileset. // Save it separately to be outputted later. - unusedMetatileLabels[label] = defines[label]; + unusedMetatileLabels[label] = metatileId; } } @@ -1529,7 +1534,7 @@ void Project::loadTilesetMetatileLabels(Tileset* tileset) { // Reverse map for faster lookup by metatile id for (QString labelName : metatileLabelsMap[tileset->name].keys()) { - int metatileId = metatileLabelsMap[tileset->name][labelName]; + auto metatileId = metatileLabelsMap[tileset->name][labelName]; tileset->metatileLabels[metatileId] = labelName.replace(metatileLabelPrefix, ""); } }