Split readMaxMapDataSize, move mapDimensionsValid to project

This commit is contained in:
GriffinR 2020-05-16 18:52:46 -04:00 committed by huderlem
parent 731fbce6af
commit 374020f94d
5 changed files with 22 additions and 12 deletions

View file

@ -277,7 +277,6 @@ private:
QString getDefaultMap(); QString getDefaultMap();
void setRecentMap(QString map_name); void setRecentMap(QString map_name);
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum); QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
bool mapDimensionsValid(int width, int height);
void drawMapListIcons(QAbstractItemModel *model); void drawMapListIcons(QAbstractItemModel *model);
void updateMapList(); void updateMapList();

View file

@ -149,6 +149,7 @@ public:
QStringList getVisibilities(); QStringList getVisibilities();
QMap<QString, QStringList> getTilesetLabels(); QMap<QString, QStringList> getTilesetLabels();
bool readTilesetProperties(); bool readTilesetProperties();
bool readMaxMapDataSize();
bool readRegionMapSections(); bool readRegionMapSections();
bool readItemNames(); bool readItemNames();
bool readFlagNames(); bool readFlagNames();
@ -188,8 +189,8 @@ public:
static int getDefaultMapSize(); static int getDefaultMapSize();
static int getMaxMapWidth(); static int getMaxMapWidth();
static int getMaxMapHeight(); static int getMaxMapHeight();
static int getMapDataSize(int width, int height);
int getMapDataSize(int width, int height); static bool mapDimensionsValid(int width, int height);
bool calculateDefaultMapSize(); bool calculateDefaultMapSize();
private: private:

View file

@ -701,6 +701,7 @@ bool MainWindow::loadDataStructures() {
&& project->readTrainerTypes() && project->readTrainerTypes()
&& project->readMetatileBehaviors() && project->readMetatileBehaviors()
&& project->readTilesetProperties() && project->readTilesetProperties()
&& project->readMaxMapDataSize()
&& project->readHealLocations() && project->readHealLocations()
&& project->readMiscellaneousConstants() && project->readMiscellaneousConstants()
&& project->readSpeciesIconPaths() && 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) void MainWindow::on_checkBox_smartPaths_stateChanged(int selected)
{ {
bool enabled = selected == Qt::Checked; bool enabled = selected == Qt::Checked;

View file

@ -176,7 +176,7 @@ int MainWindow::getHeight() {
void MainWindow::setDimensions(int width, int height) { void MainWindow::setDimensions(int width, int height) {
if (!this->editor || !this->editor->map) if (!this->editor || !this->editor->map)
return; return;
if (!MainWindow::mapDimensionsValid(width, height)) if (!Project::mapDimensionsValid(width, height))
return; return;
this->editor->map->setDimensions(width, height); this->editor->map->setDimensions(width, height);
this->editor->map->commit(); this->editor->map->commit();
@ -186,7 +186,7 @@ void MainWindow::setDimensions(int width, int height) {
void MainWindow::setWidth(int width) { void MainWindow::setWidth(int width) {
if (!this->editor || !this->editor->map) if (!this->editor || !this->editor->map)
return; return;
if (!MainWindow::mapDimensionsValid(width, this->editor->map->getHeight())) if (!Project::mapDimensionsValid(width, this->editor->map->getHeight()))
return; return;
this->editor->map->setDimensions(width, this->editor->map->getHeight()); this->editor->map->setDimensions(width, this->editor->map->getHeight());
this->editor->map->commit(); this->editor->map->commit();
@ -196,7 +196,7 @@ void MainWindow::setWidth(int width) {
void MainWindow::setHeight(int height) { void MainWindow::setHeight(int height) {
if (!this->editor || !this->editor->map) if (!this->editor || !this->editor->map)
return; return;
if (!MainWindow::mapDimensionsValid(this->editor->map->getWidth(), height)) if (!Project::mapDimensionsValid(this->editor->map->getWidth(), height))
return; return;
this->editor->map->setDimensions(this->editor->map->getWidth(), height); this->editor->map->setDimensions(this->editor->map->getWidth(), height);
this->editor->map->commit(); this->editor->map->commit();

View file

@ -2046,7 +2046,7 @@ QMap<QString, QStringList> Project::getTilesetLabels() {
bool Project::readTilesetProperties() { bool Project::readTilesetProperties() {
QStringList definePrefixes; QStringList definePrefixes;
definePrefixes << "NUM_" << "MAX_"; definePrefixes << "NUM_";
QString filename = "include/fieldmap.h"; QString filename = "include/fieldmap.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
QMap<QString, int> defines = parser.readCDefines(filename, definePrefixes); QMap<QString, int> 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.") logWarn(QString("Value for tileset property 'NUM_PALS_TOTAL' not found. Using default (%1) instead.")
.arg(Project::num_pals_total)); .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<QString, int> defines = parser.readCDefines(filename, definePrefixes);
auto it = defines.find("MAX_MAP_DATA_SIZE");
if (it != defines.end()) { if (it != defines.end()) {
int min = getMapDataSize(1, 1); int min = getMapDataSize(1, 1);
if (it.value() >= min) { if (it.value() >= min) {
@ -2588,6 +2597,10 @@ int Project::getMaxMapHeight()
return (getMaxMapDataSize() / (1 + 15)) - 14; 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) // Get largest possible square dimensions for a map up to maximum of 20x20 (arbitrary)
bool Project::calculateDefaultMapSize(){ bool Project::calculateDefaultMapSize(){
int max = getMaxMapDataSize(); int max = getMaxMapDataSize();