Add default tileset config options

This commit is contained in:
GriffinR 2022-10-23 19:28:55 -04:00
parent 35da77ca94
commit f8a92c071c
5 changed files with 51 additions and 35 deletions

View file

@ -209,6 +209,7 @@ public:
this->newMapMetatileId = 1;
this->newMapElevation = 3;
this->newMapBorderMetatileIds = DEFAULT_BORDER_RSE;
this->defaultPrimaryTileset = "gTileset_General";
this->prefabFilepath = QString();
this->prefabImportPrompted = false;
this->tilesetsHaveCallback = true;
@ -251,6 +252,8 @@ public:
int getNewMapElevation();
void setNewMapBorderMetatileIds(QList<int> metatileIds);
QList<int> getNewMapBorderMetatileIds();
QString getDefaultPrimaryTileset();
QString getDefaultSecondaryTileset();
void setFilePath(ProjectFilePath pathId, QString path);
QString getFilePath(ProjectFilePath pathId);
void setPrefabFilepath(QString filepath);
@ -285,6 +288,8 @@ private:
int newMapMetatileId;
int newMapElevation;
QList<int> newMapBorderMetatileIds;
QString defaultPrimaryTileset;
QString defaultSecondaryTileset;
QStringList readKeys;
QString prefabFilepath;
bool prefabImportPrompted;

View file

@ -211,6 +211,9 @@ public:
QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels);
QStringList getGlobalScriptLabels();
QString getDefaultPrimaryTilesetLabel();
QString getDefaultSecondaryTilesetLabel();
static int getNumTilesPrimary();
static int getNumTilesTotal();
static int getNumMetatilesPrimary();
@ -230,7 +233,6 @@ private:
void updateMapLayout(Map*);
void setNewMapHeader(Map* map, int mapIndex);
void setNewMapLayout(Map* map);
void setNewMapBlockdata(Map* map);
void setNewMapBorder(Map *map);
void setNewMapEvents(Map *map);

View file

@ -545,6 +545,10 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
// Set any metatiles not provided to 0
this->newMapBorderMetatileIds.append(0);
}
} else if (key == "default_primary_tileset") {
this->defaultPrimaryTileset = value;
} else if (key == "default_secondary_tileset") {
this->defaultSecondaryTileset = value;
#ifdef CONFIG_BACKWARDS_COMPATABILITY
} else if (key == "recent_map") {
userConfig.setRecentMap(value);
@ -594,6 +598,7 @@ void ProjectConfig::setUnreadKeys() {
if (!readKeys.contains("enable_floor_number")) this->enableFloorNumber = isPokefirered;
if (!readKeys.contains("create_map_text_file")) this->createMapTextFile = (this->baseGameVersion != BaseGameVersion::pokeemerald);
if (!readKeys.contains("new_map_border_metatiles")) this->newMapBorderMetatileIds = isPokefirered ? DEFAULT_BORDER_FRLG : DEFAULT_BORDER_RSE;
if (!readKeys.contains("default_secondary_tileset")) this->defaultSecondaryTileset = isPokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg";
}
QMap<QString, QString> ProjectConfig::getKeyValueMap() {
@ -616,6 +621,8 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
for (auto metatile : this->newMapBorderMetatileIds)
metatiles << QString::number(metatile);
map.insert("new_map_border_metatiles", metatiles.join(","));
map.insert("default_primary_tileset", this->defaultPrimaryTileset);
map.insert("default_secondary_tileset", this->defaultSecondaryTileset);
map.insert("prefabs_filepath", this->prefabFilepath);
map.insert("prefabs_import_prompted", QString::number(this->prefabImportPrompted));
for (auto it = this->filePaths.constKeyValueBegin(); it != this->filePaths.constKeyValueEnd(); ++it) {
@ -652,17 +659,7 @@ void ProjectConfig::onNewConfigFileCreated() {
this->baseGameVersion = static_cast<BaseGameVersion>(baseGameVersionComboBox->currentData().toInt());
}
}
bool isPokefirered = this->baseGameVersion == BaseGameVersion::pokefirered;
this->useCustomBorderSize = isPokefirered;
this->enableEventWeatherTrigger = !isPokefirered;
this->enableEventSecretBase = !isPokefirered;
this->enableHiddenItemQuantity = isPokefirered;
this->enableHiddenItemRequiresItemfinder = isPokefirered;
this->enableHealLocationRespawnData = isPokefirered;
this->enableEventCloneObject = isPokefirered;
this->enableFloorNumber = isPokefirered;
this->createMapTextFile = (this->baseGameVersion != BaseGameVersion::pokeemerald);
this->newMapBorderMetatileIds = isPokefirered ? DEFAULT_BORDER_FRLG : DEFAULT_BORDER_RSE;
this->setUnreadKeys(); // Initialize version-specific options
}
void ProjectConfig::setProjectDir(QString projectDir) {
@ -835,6 +832,14 @@ QList<int> ProjectConfig::getNewMapBorderMetatileIds() {
return this->newMapBorderMetatileIds;
}
QString ProjectConfig::getDefaultPrimaryTileset() {
return this->defaultPrimaryTileset;
}
QString ProjectConfig::getDefaultSecondaryTileset() {
return this->defaultSecondaryTileset;
}
void ProjectConfig::setPrefabFilepath(QString filepath) {
this->prefabFilepath = filepath;
this->save();

View file

@ -591,26 +591,6 @@ void Project::ignoreWatchedFileTemporarily(QString filepath) {
modifiedFileTimestamps.insert(filepath, QDateTime::currentMSecsSinceEpoch() + 5000);
}
void Project::setNewMapLayout(Map* map) {
MapLayout *layout = new MapLayout();
layout->id = MapLayout::layoutConstantFromName(map->name);
layout->name = QString("%1_Layout").arg(map->name);
layout->width = getDefaultMapSize();
layout->height = getDefaultMapSize();
layout->border_width = DEFAULT_BORDER_WIDTH;
layout->border_height = DEFAULT_BORDER_HEIGHT;
layout->border_path = QString("%2%1/border.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders));
layout->blockdata_path = QString("%2%1/map.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders));
layout->tileset_primary_label = this->primaryTilesetLabels.value(0, "gTileset_General");
layout->tileset_secondary_label = this->secondaryTilesetLabels.value(0, projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg");
map->layout = layout;
map->layoutId = layout->id;
// Insert new entry into the global map layouts.
mapLayouts.insert(layout->id, layout);
mapLayoutsTable.append(layout->id);
}
void Project::saveMapGroups() {
QString mapGroupsFilepath = QString("%1/%2").arg(root).arg(projectConfig.getFilePath(ProjectFilePath::json_map_groups));
QFile mapGroupsFile(mapGroupsFilepath);
@ -1046,7 +1026,7 @@ void Project::saveTilesetPalettes(Tileset *tileset) {
bool Project::loadLayoutTilesets(MapLayout *layout) {
layout->tileset_primary = getTileset(layout->tileset_primary_label);
if (!layout->tileset_primary) {
QString defaultTileset = primaryTilesetLabels.value(0, "gTileset_General");
QString defaultTileset = this->getDefaultPrimaryTilesetLabel();
logWarn(QString("Map layout %1 has invalid primary tileset '%2'. Using default '%3'").arg(layout->id).arg(layout->tileset_primary_label).arg(defaultTileset));
layout->tileset_primary_label = defaultTileset;
layout->tileset_primary = getTileset(layout->tileset_primary_label);
@ -1058,7 +1038,7 @@ bool Project::loadLayoutTilesets(MapLayout *layout) {
layout->tileset_secondary = getTileset(layout->tileset_secondary_label);
if (!layout->tileset_secondary) {
QString defaultTileset = secondaryTilesetLabels.value(0, projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg");
QString defaultTileset = this->getDefaultSecondaryTilesetLabel();
logWarn(QString("Map layout %1 has invalid secondary tileset '%2'. Using default '%3'").arg(layout->id).arg(layout->tileset_secondary_label).arg(defaultTileset));
layout->tileset_secondary_label = defaultTileset;
layout->tileset_secondary = getTileset(layout->tileset_secondary_label);
@ -1850,8 +1830,28 @@ Project::DataQualifiers Project::getDataQualifiers(QString text, QString label)
return qualifiers;
}
QString Project::getDefaultPrimaryTilesetLabel() {
QString defaultLabel = projectConfig.getDefaultPrimaryTileset();
if (!this->primaryTilesetLabels.contains(defaultLabel)) {
QString firstLabel = this->primaryTilesetLabels.first();
logWarn(QString("Unable to find default primary tileset '%1', using '%2' instead.").arg(defaultLabel).arg(firstLabel));
defaultLabel = firstLabel;
}
return defaultLabel;
}
QString Project::getDefaultSecondaryTilesetLabel() {
QString defaultLabel = projectConfig.getDefaultSecondaryTileset();
if (!this->secondaryTilesetLabels.contains(defaultLabel)) {
QString firstLabel = this->secondaryTilesetLabels.first();
logWarn(QString("Unable to find default secondary tileset '%1', using '%2' instead.").arg(defaultLabel).arg(firstLabel));
defaultLabel = firstLabel;
}
return defaultLabel;
}
void Project::insertTilesetLabel(QString label, bool isSecondary) {
if (isSecondary)
if (!isSecondary)
this->primaryTilesetLabels.append(label);
else
this->secondaryTilesetLabels.append(label);

View file

@ -132,6 +132,10 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
ui->spinBox_NewMap_Height->setValue(project->getDefaultMapSize());
ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH);
ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT);
int primaryIdx = ui->comboBox_NewMap_Primary_Tileset->findText(project->getDefaultPrimaryTilesetLabel());
int secondaryIdx = ui->comboBox_NewMap_Secondary_Tileset->findText(project->getDefaultSecondaryTilesetLabel());
ui->comboBox_NewMap_Primary_Tileset->setCurrentIndex(primaryIdx);
ui->comboBox_NewMap_Secondary_Tileset->setCurrentIndex(secondaryIdx);
}
ui->comboBox_NewMap_Type->addItems(project->mapTypes);