From 59f0d9fe112ddc5cd0bea892fc905ca86123d268 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 3 Jan 2024 13:36:42 -0500 Subject: [PATCH] Automatically adjust metatile ID strings --- CHANGELOG.md | 1 + include/core/metatile.h | 13 ++----------- src/config.cpp | 2 +- src/core/metatile.cpp | 17 +++++++++++++++++ src/ui/projectsettingseditor.cpp | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c246f569..9565411c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ## [Unreleased] ### Changed - The API functions `addImage` and `createImage` now support project-relative paths. +- Metatile ID strings are now padded to their current max, not the overall max. ### Fixed - Fix API error reporting diff --git a/include/core/metatile.h b/include/core/metatile.h index 92adb82c..0bb55af9 100644 --- a/include/core/metatile.h +++ b/include/core/metatile.h @@ -74,15 +74,8 @@ public: static uint32_t getMaxAttributesMask(); static int getDefaultAttributesSize(BaseGameVersion version); static void setLayout(Project*); - static QString getMetatileIdString(uint16_t metatileId) { - return "0x" + QString("%1").arg(metatileId, 4, 16, QChar('0')).toUpper(); - }; - static QString getMetatileIdStringList(const QList metatileIds) { - QStringList metatiles; - for (auto metatileId : metatileIds) - metatiles << Metatile::getMetatileIdString(metatileId); - return metatiles.join(","); - }; + static QString getMetatileIdString(uint16_t metatileId); + static QString getMetatileIdStrings(const QList metatileIds); inline bool operator==(const Metatile &other) { return this->tiles == other.tiles && this->attributes == other.attributes; @@ -94,8 +87,6 @@ public: private: QMap attributes; - - static bool doMasksOverlap(QList); }; #endif // METATILE_H diff --git a/src/config.cpp b/src/config.cpp index 61a6fc21..11bd06dc 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -965,7 +965,7 @@ QMap ProjectConfig::getKeyValueMap() { map.insert("default_metatile", Metatile::getMetatileIdString(this->defaultMetatileId)); map.insert("default_elevation", QString::number(this->defaultElevation)); map.insert("default_collision", QString::number(this->defaultCollision)); - map.insert("new_map_border_metatiles", Metatile::getMetatileIdStringList(this->newMapBorderMetatileIds)); + map.insert("new_map_border_metatiles", Metatile::getMetatileIdStrings(this->newMapBorderMetatileIds)); map.insert("default_primary_tileset", this->defaultPrimaryTileset); map.insert("default_secondary_tileset", this->defaultSecondaryTileset); map.insert("prefabs_filepath", this->prefabFilepath); diff --git a/src/core/metatile.cpp b/src/core/metatile.cpp index 565dd8f7..1b4a74c5 100644 --- a/src/core/metatile.cpp +++ b/src/core/metatile.cpp @@ -40,6 +40,18 @@ QPoint Metatile::coordFromPixmapCoord(const QPointF &pixelCoord) { return QPoint(x, y); } +static int numMetatileIdChars = 4; +QString Metatile::getMetatileIdString(uint16_t metatileId) { + return "0x" + QString("%1").arg(metatileId, numMetatileIdChars, 16, QChar('0')).toUpper(); +}; + +QString Metatile::getMetatileIdStrings(const QList metatileIds) { + QStringList metatiles; + for (auto metatileId : metatileIds) + metatiles << Metatile::getMetatileIdString(metatileId); + return metatiles.join(","); +}; + // Read and pack together this metatile's attributes. uint32_t Metatile::getAttributes() const { uint32_t data = 0; @@ -92,6 +104,11 @@ uint32_t Metatile::getMaxAttributesMask() { } void Metatile::setLayout(Project * project) { + // Calculate the number of hex characters needed to display a metatile ID. + numMetatileIdChars = 0; + for (uint16_t i = Block::getMaxMetatileId(); i > 1; i /= 0xF) + numMetatileIdChars++; + uint32_t behaviorMask = projectConfig.getMetatileBehaviorMask(); uint32_t terrainTypeMask = projectConfig.getMetatileTerrainTypeMask(); uint32_t encounterTypeMask = projectConfig.getMetatileEncounterTypeMask(); diff --git a/src/ui/projectsettingseditor.cpp b/src/ui/projectsettingseditor.cpp index 44d4b80b..950dd87b 100644 --- a/src/ui/projectsettingseditor.cpp +++ b/src/ui/projectsettingseditor.cpp @@ -198,7 +198,7 @@ void ProjectSettingsEditor::setBorderMetatilesUi(bool customSize) { void ProjectSettingsEditor::setBorderMetatileIds(bool customSize, QList metatileIds) { if (customSize) { - ui->lineEdit_BorderMetatiles->setText(Metatile::getMetatileIdStringList(metatileIds)); + ui->lineEdit_BorderMetatiles->setText(Metatile::getMetatileIdStrings(metatileIds)); } else { ui->spinBox_BorderMetatile1->setValue(metatileIds.value(0, 0x0)); ui->spinBox_BorderMetatile2->setValue(metatileIds.value(1, 0x0));