Automatically adjust metatile ID strings

This commit is contained in:
GriffinR 2024-01-03 13:36:42 -05:00
parent 513e63193e
commit 59f0d9fe11
5 changed files with 22 additions and 13 deletions

View file

@ -9,6 +9,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
## [Unreleased] ## [Unreleased]
### Changed ### Changed
- The API functions `addImage` and `createImage` now support project-relative paths. - 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 ### Fixed
- Fix API error reporting - Fix API error reporting

View file

@ -74,15 +74,8 @@ public:
static uint32_t getMaxAttributesMask(); static uint32_t getMaxAttributesMask();
static int getDefaultAttributesSize(BaseGameVersion version); static int getDefaultAttributesSize(BaseGameVersion version);
static void setLayout(Project*); static void setLayout(Project*);
static QString getMetatileIdString(uint16_t metatileId) { static QString getMetatileIdString(uint16_t metatileId);
return "0x" + QString("%1").arg(metatileId, 4, 16, QChar('0')).toUpper(); static QString getMetatileIdStrings(const QList<uint16_t> metatileIds);
};
static QString getMetatileIdStringList(const QList<uint16_t> metatileIds) {
QStringList metatiles;
for (auto metatileId : metatileIds)
metatiles << Metatile::getMetatileIdString(metatileId);
return metatiles.join(",");
};
inline bool operator==(const Metatile &other) { inline bool operator==(const Metatile &other) {
return this->tiles == other.tiles && this->attributes == other.attributes; return this->tiles == other.tiles && this->attributes == other.attributes;
@ -94,8 +87,6 @@ public:
private: private:
QMap<Metatile::Attr, uint32_t> attributes; QMap<Metatile::Attr, uint32_t> attributes;
static bool doMasksOverlap(QList<uint32_t>);
}; };
#endif // METATILE_H #endif // METATILE_H

View file

@ -965,7 +965,7 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
map.insert("default_metatile", Metatile::getMetatileIdString(this->defaultMetatileId)); map.insert("default_metatile", Metatile::getMetatileIdString(this->defaultMetatileId));
map.insert("default_elevation", QString::number(this->defaultElevation)); map.insert("default_elevation", QString::number(this->defaultElevation));
map.insert("default_collision", QString::number(this->defaultCollision)); 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_primary_tileset", this->defaultPrimaryTileset);
map.insert("default_secondary_tileset", this->defaultSecondaryTileset); map.insert("default_secondary_tileset", this->defaultSecondaryTileset);
map.insert("prefabs_filepath", this->prefabFilepath); map.insert("prefabs_filepath", this->prefabFilepath);

View file

@ -40,6 +40,18 @@ QPoint Metatile::coordFromPixmapCoord(const QPointF &pixelCoord) {
return QPoint(x, y); 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<uint16_t> metatileIds) {
QStringList metatiles;
for (auto metatileId : metatileIds)
metatiles << Metatile::getMetatileIdString(metatileId);
return metatiles.join(",");
};
// Read and pack together this metatile's attributes. // Read and pack together this metatile's attributes.
uint32_t Metatile::getAttributes() const { uint32_t Metatile::getAttributes() const {
uint32_t data = 0; uint32_t data = 0;
@ -92,6 +104,11 @@ uint32_t Metatile::getMaxAttributesMask() {
} }
void Metatile::setLayout(Project * project) { 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 behaviorMask = projectConfig.getMetatileBehaviorMask();
uint32_t terrainTypeMask = projectConfig.getMetatileTerrainTypeMask(); uint32_t terrainTypeMask = projectConfig.getMetatileTerrainTypeMask();
uint32_t encounterTypeMask = projectConfig.getMetatileEncounterTypeMask(); uint32_t encounterTypeMask = projectConfig.getMetatileEncounterTypeMask();

View file

@ -198,7 +198,7 @@ void ProjectSettingsEditor::setBorderMetatilesUi(bool customSize) {
void ProjectSettingsEditor::setBorderMetatileIds(bool customSize, QList<uint16_t> metatileIds) { void ProjectSettingsEditor::setBorderMetatileIds(bool customSize, QList<uint16_t> metatileIds) {
if (customSize) { if (customSize) {
ui->lineEdit_BorderMetatiles->setText(Metatile::getMetatileIdStringList(metatileIds)); ui->lineEdit_BorderMetatiles->setText(Metatile::getMetatileIdStrings(metatileIds));
} else { } else {
ui->spinBox_BorderMetatile1->setValue(metatileIds.value(0, 0x0)); ui->spinBox_BorderMetatile1->setValue(metatileIds.value(0, 0x0));
ui->spinBox_BorderMetatile2->setValue(metatileIds.value(1, 0x0)); ui->spinBox_BorderMetatile2->setValue(metatileIds.value(1, 0x0));