diff --git a/include/mainwindow.h b/include/mainwindow.h index 1bf1c54c..c575a6ec 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -277,7 +277,6 @@ private: QString getDefaultMap(); void setRecentMap(QString map_name); QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum); - bool mapDimensionsValid(int width, int height); void drawMapListIcons(QAbstractItemModel *model); void updateMapList(); diff --git a/include/project.h b/include/project.h index 298e1351..c8f722d2 100644 --- a/include/project.h +++ b/include/project.h @@ -149,6 +149,7 @@ public: QStringList getVisibilities(); QMap getTilesetLabels(); bool readTilesetProperties(); + bool readMaxMapDataSize(); bool readRegionMapSections(); bool readItemNames(); bool readFlagNames(); @@ -188,8 +189,8 @@ public: static int getDefaultMapSize(); static int getMaxMapWidth(); static int getMaxMapHeight(); - - int getMapDataSize(int width, int height); + static int getMapDataSize(int width, int height); + static bool mapDimensionsValid(int width, int height); bool calculateDefaultMapSize(); private: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d33b8309..e0104933 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -701,6 +701,7 @@ bool MainWindow::loadDataStructures() { && project->readTrainerTypes() && project->readMetatileBehaviors() && project->readTilesetProperties() + && project->readMaxMapDataSize() && project->readHealLocations() && project->readMiscellaneousConstants() && project->readSpeciesIconPaths() @@ -2351,10 +2352,6 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked() } } -bool MainWindow::mapDimensionsValid(int width, int height) { - return editor->project->getMapDataSize(width, height) <= editor->project->getMaxMapDataSize(); -} - void MainWindow::on_checkBox_smartPaths_stateChanged(int selected) { bool enabled = selected == Qt::Checked; diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index 7f6cc24c..1df8afb9 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -176,7 +176,7 @@ int MainWindow::getHeight() { void MainWindow::setDimensions(int width, int height) { if (!this->editor || !this->editor->map) return; - if (!MainWindow::mapDimensionsValid(width, height)) + if (!Project::mapDimensionsValid(width, height)) return; this->editor->map->setDimensions(width, height); this->editor->map->commit(); @@ -186,7 +186,7 @@ void MainWindow::setDimensions(int width, int height) { void MainWindow::setWidth(int width) { if (!this->editor || !this->editor->map) return; - if (!MainWindow::mapDimensionsValid(width, this->editor->map->getHeight())) + if (!Project::mapDimensionsValid(width, this->editor->map->getHeight())) return; this->editor->map->setDimensions(width, this->editor->map->getHeight()); this->editor->map->commit(); @@ -196,7 +196,7 @@ void MainWindow::setWidth(int width) { void MainWindow::setHeight(int height) { if (!this->editor || !this->editor->map) return; - if (!MainWindow::mapDimensionsValid(this->editor->map->getWidth(), height)) + if (!Project::mapDimensionsValid(this->editor->map->getWidth(), height)) return; this->editor->map->setDimensions(this->editor->map->getWidth(), height); this->editor->map->commit(); diff --git a/src/project.cpp b/src/project.cpp index fecc2a05..c5c1504b 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2046,7 +2046,7 @@ QMap Project::getTilesetLabels() { bool Project::readTilesetProperties() { QStringList definePrefixes; - definePrefixes << "NUM_" << "MAX_"; + definePrefixes << "NUM_"; QString filename = "include/fieldmap.h"; fileWatcher.addPath(root + "/" + filename); QMap defines = parser.readCDefines(filename, definePrefixes); @@ -2099,7 +2099,16 @@ bool Project::readTilesetProperties() { logWarn(QString("Value for tileset property 'NUM_PALS_TOTAL' not found. Using default (%1) instead.") .arg(Project::num_pals_total)); } - it = defines.find("MAX_MAP_DATA_SIZE"); + return true; +} + +bool Project::readMaxMapDataSize() { + QStringList definePrefixes; + definePrefixes << "MAX_"; + QString filename = "include/fieldmap.h"; // already in fileWatcher from readTilesetProperties + QMap defines = parser.readCDefines(filename, definePrefixes); + + auto it = defines.find("MAX_MAP_DATA_SIZE"); if (it != defines.end()) { int min = getMapDataSize(1, 1); if (it.value() >= min) { @@ -2588,6 +2597,10 @@ int Project::getMaxMapHeight() return (getMaxMapDataSize() / (1 + 15)) - 14; } +bool Project::mapDimensionsValid(int width, int height) { + return getMapDataSize(width, height) <= getMaxMapDataSize(); +} + // Get largest possible square dimensions for a map up to maximum of 20x20 (arbitrary) bool Project::calculateDefaultMapSize(){ int max = getMaxMapDataSize();