Add truncation warning for metatile labels

This commit is contained in:
GriffinR 2023-12-19 12:29:16 -05:00
parent cd1c3fef94
commit e0c6621abc
2 changed files with 9 additions and 4 deletions

View file

@ -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<uint16_t> metatileIds) {
QStringList metatiles;

View file

@ -1511,13 +1511,18 @@ bool Project::readTilesetMetatileLabels() {
QMap<QString, int> defines = parser.readCDefinesByPrefix(metatileLabelsFilename, prefixes);
for (QString label : defines.keys()) {
uint32_t metatileId = static_cast<uint32_t>(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, "");
}
}