From ef165e29df30a797d1ad0964a160004c8465d50c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 4 Jan 2024 12:22:06 -0500 Subject: [PATCH] Stop enforcing heal locations table name --- CHANGELOG.md | 3 ++- docsrc/manual/project-files.rst | 9 +++++---- include/config.h | 1 + include/project.h | 2 +- src/config.cpp | 5 +++-- src/project.cpp | 30 ++++++++++++++++++------------ 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eac8dfd1..d692d1be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,9 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Add `metatile_behaviors`, `num_primary_palettes`, and `num_secondary_palettes` to `constants` in the API. ### Changed -- The API functions `addImage` and `createImage` now support project-relative paths. - Metatile ID strings are now padded to their current max, not the overall max. +- The name of the Heal Locations table is no longer enforced. +- The API functions `addImage` and `createImage` now support project-relative paths. ### Fixed - Fix the event group tabs sometimes showing an event from the wrong group diff --git a/docsrc/manual/project-files.rst b/docsrc/manual/project-files.rst index bc629a1f..20849ba3 100644 --- a/docsrc/manual/project-files.rst +++ b/docsrc/manual/project-files.rst @@ -86,10 +86,11 @@ In addition to these files, there are some specific symbol and macro names that ``symbol_obj_event_gfx_pointers``, ``gObjectEventGraphicsInfoPointers``, to map Object Event graphics IDs to graphics data ``symbol_pokemon_icon_table``, ``gMonIconTable``, to map species constants to icon images ``symbol_wild_encounters``, ``gWildMonHeaders``, output as the ``label`` property for the top-level wild ecounters JSON object - ``symbol_heal_locations``, ``sHealLocations``, only if ``Respawn Map/NPC`` is disabled - ``symbol_spawn_points``, ``sSpawnPoints``, only if ``Respawn Map/NPC`` is enabled - ``symbol_spawn_maps``, ``sWhiteoutRespawnHealCenterMapIdxs``, values for Heal Locations ``Respawn Map`` field - ``symbol_spawn_npcs``, ``sWhiteoutRespawnHealerNpcIds``, values for Heal Locations ``Respawn NPC`` field + ``symbol_heal_locations_type``, ``struct HealLocation``, the type for the Heal Locations table + ``symbol_heal_locations``, ``sHealLocations``, the default Heal Locations table name when ``Respawn Map/NPC`` is disabled + ``symbol_spawn_points``, ``sSpawnPoints``, the default Heal Locations table name when ``Respawn Map/NPC`` is enabled + ``symbol_spawn_maps``, ``u16 sWhiteoutRespawnHealCenterMapIdxs``, the type and table name for Heal Location ``Respawn Map`` values + ``symbol_spawn_npcs``, ``u8 sWhiteoutRespawnHealerNpcIds``, the type and table name for Heal Location ``Respawn NPC`` values ``symbol_attribute_table``, ``sMetatileAttrMasks``, optionally read to get settings on ``Tilesets`` tab ``symbol_tilesets_prefix``, ``gTileset_``, for new tileset names and to extract base tileset names ``define_obj_event_count``, ``OBJECT_EVENT_TEMPLATES_COUNT``, to limit total Object Events diff --git a/include/config.h b/include/config.h index 7ae31839..9a1f5d8d 100644 --- a/include/config.h +++ b/include/config.h @@ -189,6 +189,7 @@ enum ProjectIdentifier { symbol_obj_event_gfx_pointers, symbol_pokemon_icon_table, symbol_wild_encounters, + symbol_heal_locations_type, symbol_heal_locations, symbol_spawn_points, symbol_spawn_maps, diff --git a/include/project.h b/include/project.h index e4f6840b..c7effcfb 100644 --- a/include/project.h +++ b/include/project.h @@ -93,6 +93,7 @@ class Project : public QObject }; DataQualifiers getDataQualifiers(QString, QString); DataQualifiers healLocationDataQualifiers; + QString healLocationsTableName; QMap mapCache; Map* loadMap(QString); @@ -238,7 +239,6 @@ class Project : public QObject void saveHealLocationsData(Map *map); void saveHealLocationsConstants(); - QString getHealLocationsTableName(); void ignoreWatchedFileTemporarily(QString filepath); diff --git a/src/config.cpp b/src/config.cpp index 11bd06dc..2dba96e4 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -74,10 +74,11 @@ const QMap> ProjectConfig::defaultIde {ProjectIdentifier::symbol_obj_event_gfx_pointers, {"symbol_obj_event_gfx_pointers", "gObjectEventGraphicsInfoPointers"}}, {ProjectIdentifier::symbol_pokemon_icon_table, {"symbol_pokemon_icon_table", "gMonIconTable"}}, {ProjectIdentifier::symbol_wild_encounters, {"symbol_wild_encounters", "gWildMonHeaders"}}, + {ProjectIdentifier::symbol_heal_locations_type, {"symbol_heal_locations_type", "struct HealLocation"}}, {ProjectIdentifier::symbol_heal_locations, {"symbol_heal_locations", "sHealLocations"}}, {ProjectIdentifier::symbol_spawn_points, {"symbol_spawn_points", "sSpawnPoints"}}, - {ProjectIdentifier::symbol_spawn_maps, {"symbol_spawn_maps", "sWhiteoutRespawnHealCenterMapIdxs"}}, - {ProjectIdentifier::symbol_spawn_npcs, {"symbol_spawn_npcs", "sWhiteoutRespawnHealerNpcIds"}}, + {ProjectIdentifier::symbol_spawn_maps, {"symbol_spawn_maps", "u16 sWhiteoutRespawnHealCenterMapIdxs"}}, + {ProjectIdentifier::symbol_spawn_npcs, {"symbol_spawn_npcs", "u8 sWhiteoutRespawnHealerNpcIds"}}, {ProjectIdentifier::symbol_attribute_table, {"symbol_attribute_table", "sMetatileAttrMasks"}}, {ProjectIdentifier::symbol_tilesets_prefix, {"symbol_tilesets_prefix", "gTileset_"}}, // Defines diff --git a/src/project.cpp b/src/project.cpp index 475512ff..fa0dfa7b 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -748,12 +748,6 @@ void Project::saveHealLocations(Map *map) { this->saveHealLocationsConstants(); } -QString Project::getHealLocationsTableName() { - if (projectConfig.getHealLocationRespawnDataEnabled()) - return projectConfig.getIdentifier(ProjectIdentifier::symbol_spawn_points); - return projectConfig.getIdentifier(ProjectIdentifier::symbol_heal_locations); -} - // Saves heal location maps/coords/respawn data in root + /src/data/heal_locations.h void Project::saveHealLocationsData(Map *map) { // Update heal locations from map @@ -780,11 +774,13 @@ void Project::saveHealLocationsData(Map *map) { const QString qualifiers = QString(healLocationDataQualifiers.isStatic ? "static " : "") + QString(healLocationDataQualifiers.isConst ? "const " : ""); - QString locationTableText = QString("%1struct HealLocation %2[] =\n{\n").arg(qualifiers).arg(this->getHealLocationsTableName()); + QString locationTableText = QString("%1%2 %3[] =\n{\n").arg(qualifiers) + .arg(projectConfig.getIdentifier(ProjectIdentifier::symbol_heal_locations_type)) + .arg(this->healLocationsTableName); QString respawnMapTableText, respawnNPCTableText; if (respawnEnabled) { - respawnMapTableText = QString("\n%1u16 %2[][2] =\n{\n").arg(qualifiers).arg(projectConfig.getIdentifier(ProjectIdentifier::symbol_spawn_maps)); - respawnNPCTableText = QString("\n%1u8 %2[] =\n{\n").arg(qualifiers).arg(projectConfig.getIdentifier(ProjectIdentifier::symbol_spawn_npcs)); + respawnMapTableText = QString("\n%1%2[][2] =\n{\n").arg(qualifiers).arg(projectConfig.getIdentifier(ProjectIdentifier::symbol_spawn_maps)); + respawnNPCTableText = QString("\n%1%2[] =\n{\n").arg(qualifiers).arg(projectConfig.getIdentifier(ProjectIdentifier::symbol_spawn_npcs)); } // Populate the data tables with the heal location data @@ -2087,7 +2083,6 @@ bool Project::readHealLocationConstants() { // TODO: Simplify using the new C struct parsing functions (and indexed array parsing functions) bool Project::readHealLocations() { - this->healLocationDataQualifiers = {}; this->healLocations.clear(); if (!this->readHealLocationConstants()) @@ -2103,8 +2098,19 @@ bool Project::readHealLocations() { bool respawnEnabled = projectConfig.getHealLocationRespawnDataEnabled(); - // Get data qualifiers for the location data table - this->healLocationDataQualifiers = this->getDataQualifiers(text, this->getHealLocationsTableName()); + // Search for the name of the main Heal Locations table + const QRegularExpression tableNameExpr(QString("%1\\s+(?[A-Za-z0-9_]+)\\[").arg(projectConfig.getIdentifier(ProjectIdentifier::symbol_heal_locations_type))); + const QRegularExpressionMatch tableNameMatch = tableNameExpr.match(text); + if (tableNameMatch.hasMatch()) { + // Found table name, record it and its qualifiers for output when saving. + this->healLocationsTableName = tableNameMatch.captured("name"); + this->healLocationDataQualifiers = this->getDataQualifiers(text, this->healLocationsTableName); + } else { + // No table name found, initialize default name for output when saving. + this->healLocationsTableName = respawnEnabled ? projectConfig.getIdentifier(ProjectIdentifier::symbol_spawn_points) + : projectConfig.getIdentifier(ProjectIdentifier::symbol_heal_locations); + this->healLocationDataQualifiers = { .isStatic = true, .isConst = true }; + } // Create regex pattern for the constants (ex: "SPAWN_PALLET_TOWN" or "HEAL_LOCATION_PETALBURG_CITY") const QString spawnPrefix = projectConfig.getIdentifier(ProjectIdentifier::define_spawn_prefix);