Split readMaxMapDataSize, move mapDimensionsValid to project
This commit is contained in:
parent
731fbce6af
commit
374020f94d
5 changed files with 22 additions and 12 deletions
|
@ -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();
|
||||
|
|
|
@ -149,6 +149,7 @@ public:
|
|||
QStringList getVisibilities();
|
||||
QMap<QString, QStringList> 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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -2046,7 +2046,7 @@ QMap<QString, QStringList> Project::getTilesetLabels() {
|
|||
|
||||
bool Project::readTilesetProperties() {
|
||||
QStringList definePrefixes;
|
||||
definePrefixes << "NUM_" << "MAX_";
|
||||
definePrefixes << "NUM_";
|
||||
QString filename = "include/fieldmap.h";
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
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.")
|
||||
.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()) {
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue