From c543cc08999e7d2bb0d5b925b5b4349c7c273e7b Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 21 Dec 2023 23:33:36 -0500 Subject: [PATCH] Store warp behaviors as values, add version defaults --- include/config.h | 9 +-- include/project.h | 1 - src/config.cpp | 94 ++++++++++++++++++++------------ src/editor.cpp | 2 +- src/project.cpp | 10 ---- src/ui/projectsettingseditor.cpp | 31 ++++++++++- 6 files changed, 92 insertions(+), 55 deletions(-) diff --git a/include/config.h b/include/config.h index bc847b35..16dc29f0 100644 --- a/include/config.h +++ b/include/config.h @@ -315,7 +315,6 @@ public: this->blockMetatileIdMask = 0x03FF; this->blockCollisionMask = 0x0C00; this->blockElevationMask = 0xF000; - this->warpBehaviors = defaultWarpBehaviors; this->identifiers.clear(); this->readKeys.clear(); } @@ -413,8 +412,8 @@ public: int getCollisionSheetWidth(); void setCollisionSheetHeight(int height); int getCollisionSheetHeight(); - void setWarpBehaviors(const QStringList &behaviors); - QStringList getWarpBehaviors(); + void setWarpBehaviors(const QSet &behaviors); + QSet getWarpBehaviors(); protected: virtual QString getConfigFilepath() override; @@ -423,8 +422,6 @@ protected: virtual void onNewConfigFileCreated() override; virtual void setUnreadKeys() override; private: - static const QStringList defaultWarpBehaviors; - BaseGameVersion baseGameVersion; QString projectDir; QMap identifiers; @@ -465,7 +462,7 @@ private: QString collisionSheetPath; int collisionSheetWidth; int collisionSheetHeight; - QStringList warpBehaviors; + QSet warpBehaviors; }; extern ProjectConfig projectConfig; diff --git a/include/project.h b/include/project.h index bf756b13..cf9fcd73 100644 --- a/include/project.h +++ b/include/project.h @@ -79,7 +79,6 @@ public: QMap unusedMetatileLabels; QMap metatileBehaviorMap; QMap metatileBehaviorMapInverse; - QSet warpBehaviorValues; QMap facingDirections; ParseUtil parser; QFileSystemWatcher fileWatcher; diff --git a/src/config.cpp b/src/config.cpp index f9e64987..088fa8b3 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -16,35 +16,55 @@ #include #include -const QStringList ProjectConfig::defaultWarpBehaviors = { - "MB_NORTH_ARROW_WARP", - "MB_SOUTH_ARROW_WARP", - "MB_WEST_ARROW_WARP", - "MB_EAST_ARROW_WARP", - "MB_STAIRS_OUTSIDE_ABANDONED_SHIP", - "MB_WATER_SOUTH_ARROW_WARP", - "MB_SHOAL_CAVE_ENTRANCE", - "MB_SECRET_BASE_SPOT_RED_CAVE_OPEN", - "MB_SECRET_BASE_SPOT_BROWN_CAVE_OPEN", - "MB_SECRET_BASE_SPOT_YELLOW_CAVE_OPEN", - "MB_SECRET_BASE_SPOT_BLUE_CAVE_OPEN", - "MB_SECRET_BASE_SPOT_TREE_LEFT_OPEN", - "MB_SECRET_BASE_SPOT_TREE_RIGHT_OPEN", - "MB_SECRET_BASE_SPOT_SHRUB_OPEN", - "MB_ANIMATED_DOOR", - "MB_NON_ANIMATED_DOOR", - "MB_PETALBURG_GYM_DOOR", - "MB_WATER_DOOR", - "MB_LADDER", - "MB_UP_ESCALATOR", - "MB_DOWN_ESCALATOR", - "MB_DEEP_SOUTH_WARP", - "MB_LAVARIDGE_GYM_B1F_WARP", - "MB_LAVARIDGE_GYM_1F_WARP", - "MB_AQUA_HIDEOUT_WARP", - "MB_MT_PYRE_HOLE", - "MB_MOSSDEEP_GYM_WARP", - "MB_BRIDGE_OVER_OCEAN", +const QSet defaultWarpBehaviors_RSE = { + 0x0E, // MB_MOSSDEEP_GYM_WARP + 0x0F, // MB_MT_PYRE_HOLE + 0x1B, // MB_STAIRS_OUTSIDE_ABANDONED_SHIP + 0x1C, // MB_SHOAL_CAVE_ENTRANCE + 0x29, // MB_LAVARIDGE_GYM_B1F_WARP + 0x60, // MB_NON_ANIMATED_DOOR + 0x61, // MB_LADDER + 0x62, // MB_EAST_ARROW_WARP + 0x63, // MB_WEST_ARROW_WARP + 0x64, // MB_NORTH_ARROW_WARP + 0x65, // MB_SOUTH_ARROW_WARP + 0x67, // MB_AQUA_HIDEOUT_WARP + 0x68, // MB_LAVARIDGE_GYM_1F_WARP + 0x69, // MB_ANIMATED_DOOR + 0x6A, // MB_UP_ESCALATOR + 0x6B, // MB_DOWN_ESCALATOR + 0x6C, // MB_WATER_DOOR + 0x6D, // MB_WATER_SOUTH_ARROW_WARP + 0x6E, // MB_DEEP_SOUTH_WARP + 0x70, // MB_UNION_ROOM_WARP + 0x8D, // MB_PETALBURG_GYM_DOOR + 0x91, // MB_SECRET_BASE_SPOT_RED_CAVE_OPEN + 0x93, // MB_SECRET_BASE_SPOT_BROWN_CAVE_OPEN + 0x95, // MB_SECRET_BASE_SPOT_YELLOW_CAVE_OPEN + 0x97, // MB_SECRET_BASE_SPOT_TREE_LEFT_OPEN + 0x99, // MB_SECRET_BASE_SPOT_SHRUB_OPEN + 0x9B, // MB_SECRET_BASE_SPOT_BLUE_CAVE_OPEN + 0x9D, // MB_SECRET_BASE_SPOT_TREE_RIGHT_OPEN +}; + +const QSet defaultWarpBehaviors_FRLG = { + 0x60, // MB_CAVE_DOOR + 0x61, // MB_LADDER + 0x62, // MB_EAST_ARROW_WARP + 0x63, // MB_WEST_ARROW_WARP + 0x64, // MB_NORTH_ARROW_WARP + 0x65, // MB_SOUTH_ARROW_WARP + 0x66, // MB_FALL_WARP + 0x67, // MB_REGULAR_WARP + 0x68, // MB_LAVARIDGE_1F_WARP + 0x69, // MB_WARP_DOOR + 0x6A, // MB_UP_ESCALATOR + 0x6B, // MB_DOWN_ESCALATOR + 0x6C, // MB_UP_RIGHT_STAIR_WARP + 0x6D, // MB_UP_LEFT_STAIR_WARP + 0x6E, // MB_DOWN_RIGHT_STAIR_WARP + 0x6F, // MB_DOWN_LEFT_STAIR_WARP + 0x71, // MB_UNION_ROOM_WARP }; // TODO: symbol_wild_encounters should ultimately be removed from the table below. We can determine this name when we read the project. @@ -876,9 +896,11 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) { } else if (key == "collision_sheet_height") { this->collisionSheetHeight = getConfigUint32(key, value, 1, Block::maxValue); } else if (key == "warp_behaviors") { + this->warpBehaviors.clear(); value.remove(" "); - this->warpBehaviors = value.split(",", Qt::SkipEmptyParts); - this->warpBehaviors.removeDuplicates(); + QStringList behaviorList = value.split(",", Qt::SkipEmptyParts); + for (auto s : behaviorList) + this->warpBehaviors.insert(getConfigUint32(key, s)); } else { logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key)); } @@ -912,6 +934,7 @@ void ProjectConfig::setUnreadKeys() { if (!readKeys.contains("metatile_encounter_type_mask")) this->metatileEncounterTypeMask = Metatile::getDefaultAttributesMask(this->baseGameVersion, Metatile::Attr::EncounterType); if (!readKeys.contains("metatile_layer_type_mask")) this->metatileLayerTypeMask = Metatile::getDefaultAttributesMask(this->baseGameVersion, Metatile::Attr::LayerType); if (!readKeys.contains("enable_map_allow_flags")) this->enableMapAllowFlags = (this->baseGameVersion != BaseGameVersion::pokeruby); + if (!readKeys.contains("warp_behaviors")) this->warpBehaviors = isPokefirered ? defaultWarpBehaviors_FRLG : defaultWarpBehaviors_RSE; } QMap ProjectConfig::getKeyValueMap() { @@ -965,7 +988,10 @@ QMap ProjectConfig::getKeyValueMap() { map.insert("collision_sheet_path", this->collisionSheetPath); map.insert("collision_sheet_width", QString::number(this->collisionSheetWidth)); map.insert("collision_sheet_height", QString::number(this->collisionSheetHeight)); - map.insert("warp_behaviors", this->warpBehaviors.join(",")); + QStringList warpBehaviorStrs; + for (auto value : this->warpBehaviors) + warpBehaviorStrs.append("0x" + QString("%1").arg(value, 2, 16, QChar('0')).toUpper()); + map.insert("warp_behaviors", warpBehaviorStrs.join(",")); return map; } @@ -1419,12 +1445,12 @@ int ProjectConfig::getCollisionSheetHeight() { return this->collisionSheetHeight; } -void ProjectConfig::setWarpBehaviors(const QStringList &behaviors) { +void ProjectConfig::setWarpBehaviors(const QSet &behaviors) { this->warpBehaviors = behaviors; this->save(); } -QStringList ProjectConfig::getWarpBehaviors() { +QSet ProjectConfig::getWarpBehaviors() { return this->warpBehaviors; } diff --git a/src/editor.cpp b/src/editor.cpp index d136da51..4c61b5b2 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -2003,7 +2003,7 @@ void Editor::updateWarpEventWarning(Event *event) { metatile = Tileset::getMetatile(block.metatileId(), map->layout->tileset_primary, map->layout->tileset_secondary); } // metatile may be null if the warp is in the map border. Display the warning in this case - bool validWarpBehavior = metatile && project->warpBehaviorValues.contains(metatile->behavior()); + bool validWarpBehavior = metatile && projectConfig.getWarpBehaviors().contains(metatile->behavior()); warpEvent->setWarningEnabled(!validWarpBehavior); } diff --git a/src/project.cpp b/src/project.cpp index 5a90ffdf..d3db3d86 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2287,7 +2287,6 @@ bool Project::readTrainerTypes() { bool Project::readMetatileBehaviors() { this->metatileBehaviorMap.clear(); this->metatileBehaviorMapInverse.clear(); - this->warpBehaviorValues.clear(); const QStringList prefixes = {projectConfig.getIdentifier(ProjectIdentifier::regex_behaviors)}; QString filename = projectConfig.getFilePath(ProjectFilePath::constants_metatile_behaviors); @@ -2307,15 +2306,6 @@ bool Project::readMetatileBehaviors() { this->metatileBehaviorMapInverse.insert(value, i.key()); } - // Construct warp behavior value list for the warp metatile behavior warning - const QStringList warpBehaviorNames = projectConfig.getWarpBehaviors(); - for (auto name : warpBehaviorNames) { - if (this->metatileBehaviorMap.contains(name)) { - int value = this->metatileBehaviorMap.value(name); - this->warpBehaviorValues.insert(static_cast(value)); - } - } - return true; } diff --git a/src/ui/projectsettingseditor.cpp b/src/ui/projectsettingseditor.cpp index 1895038e..493d019b 100644 --- a/src/ui/projectsettingseditor.cpp +++ b/src/ui/projectsettingseditor.cpp @@ -302,14 +302,25 @@ QStringList ProjectSettingsEditor::getWarpBehaviorsList() { } void ProjectSettingsEditor::setWarpBehaviorsList(QStringList list) { + list.removeDuplicates(); + list.sort(); ui->textEdit_WarpBehaviors->setText(list.join("\n")); } void ProjectSettingsEditor::updateWarpBehaviorsList(bool adding) { - const QString input = ui->comboBox_WarpBehaviors->currentText(); + QString input = ui->comboBox_WarpBehaviors->currentText(); if (input.isEmpty()) return; + // Check if input was a value string for a named behavior + bool ok; + uint32_t value = input.toUInt(&ok, 0); + if (ok && project->metatileBehaviorMapInverse.contains(value)) + input = project->metatileBehaviorMapInverse.value(value); + + if (!project->metatileBehaviorMap.contains(input)) + return; + QStringList list = this->getWarpBehaviorsList(); int pos = list.indexOf(input); @@ -472,7 +483,15 @@ void ProjectSettingsEditor::refresh() { lineEdit->setText(projectConfig.getCustomFilePath(lineEdit->objectName())); for (auto lineEdit : ui->scrollAreaContents_Identifiers->findChildren()) lineEdit->setText(projectConfig.getCustomIdentifier(lineEdit->objectName())); - this->setWarpBehaviorsList(projectConfig.getWarpBehaviors()); + + // Set warp behaviors + auto behaviorValues = projectConfig.getWarpBehaviors(); + QStringList behaviorNames; + for (auto value : behaviorValues) { + if (project->metatileBehaviorMapInverse.contains(value)) + behaviorNames.append(project->metatileBehaviorMapInverse.value(value)); + } + this->setWarpBehaviorsList(behaviorNames); this->refreshing = false; // Allow signals } @@ -534,7 +553,13 @@ void ProjectSettingsEditor::save() { projectConfig.setFilePath(lineEdit->objectName(), lineEdit->text()); for (auto lineEdit : ui->scrollAreaContents_Identifiers->findChildren()) projectConfig.setIdentifier(lineEdit->objectName(), lineEdit->text()); - projectConfig.setWarpBehaviors(this->getWarpBehaviorsList()); + + // Save warp behaviors + QStringList behaviorNames = this->getWarpBehaviorsList(); + QSet behaviorValues; + for (auto name : behaviorNames) + behaviorValues.insert(project->metatileBehaviorMap.value(name)); + projectConfig.setWarpBehaviors(behaviorValues); // Save border metatile IDs projectConfig.setNewMapBorderMetatileIds(this->getBorderMetatileIds(ui->checkBox_EnableCustomBorderSize->isChecked()));