From f9bb6196e2137e4d32cdce7b4b47afc960b521f2 Mon Sep 17 00:00:00 2001 From: garak Date: Fri, 6 Jan 2023 23:15:41 -0500 Subject: [PATCH] do less work reading C defines while loading tileset labels --- include/project.h | 2 ++ src/mainwindow.cpp | 1 + src/project.cpp | 27 ++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/project.h b/include/project.h index fd246c3f..05029df3 100644 --- a/include/project.h +++ b/include/project.h @@ -76,6 +76,7 @@ public: QStringList bgEventFacingDirections; QStringList trainerTypes; QStringList globalScriptLabels; + QMap> metatileLabelsMap; QMap metatileBehaviorMap; QMap metatileBehaviorMapInverse; QMap facingDirections; @@ -175,6 +176,7 @@ public: void appendTilesetLabel(QString label, QString isSecondaryStr); bool readTilesetLabels(); bool readTilesetProperties(); + bool readTilesetMetatileLabels(); bool readMaxMapDataSize(); bool readRegionMapSections(); bool readItemNames(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 47b17db9..16d8a114 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -908,6 +908,7 @@ bool MainWindow::loadDataStructures() { && project->readMetatileBehaviors() && project->readTilesetProperties() && project->readTilesetLabels() + && project->readTilesetMetatileLabels() && project->readMaxMapDataSize() && project->readHealLocations() && project->readMiscellaneousConstants() diff --git a/src/project.cpp b/src/project.cpp index 0b678db1..9785f615 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1508,14 +1508,31 @@ void Project::loadTilesetMetatiles(Tileset* tileset) { } } -void Project::loadTilesetMetatileLabels(Tileset* tileset) { - QString tilesetPrefix = QString("METATILE_%1_").arg(QString(tileset->name).replace("gTileset_", "")); +bool Project::readTilesetMetatileLabels() { + metatileLabelsMap.clear(); + QString metatileLabelsFilename = projectConfig.getFilePath(ProjectFilePath::constants_metatile_labels); fileWatcher.addPath(root + "/" + metatileLabelsFilename); - QMap labels = parser.readCDefines(metatileLabelsFilename, QStringList() << tilesetPrefix); - for (QString labelName : labels.keys()) { - int metatileId = labels[labelName]; + QMap labels = parser.readCDefines(metatileLabelsFilename, QStringList() << "METATILE_"); + + for (QString label : this->tilesetLabelsOrdered) { + QString tilesetName = QString(label).replace("gTileset_", ""); + for (QString key : labels.keys()) { + if (key.contains(tilesetName)) { + metatileLabelsMap[label][key] = labels[key]; + } + } + } + + return true; +} + +void Project::loadTilesetMetatileLabels(Tileset* tileset) { + QString tilesetPrefix = QString("METATILE_%1_").arg(QString(tileset->name).replace("gTileset_", "")); + + for (QString labelName : metatileLabelsMap[tileset->name].keys()) { + int metatileId = metatileLabelsMap[tileset->name][labelName]; // subtract Project::num_tiles_primary from secondary metatiles int offset = tileset->is_secondary ? Project::num_tiles_primary : 0; Metatile *metatile = Tileset::getMetatile(metatileId - offset, tileset, nullptr);