Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop enforcing heal locations table name #578

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions docsrc/manual/project-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion include/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Project : public QObject
};
DataQualifiers getDataQualifiers(QString, QString);
DataQualifiers healLocationDataQualifiers;
QString healLocationsTableName;

QMap<QString, Map*> mapCache;
Map* loadMap(QString);
Expand Down Expand Up @@ -238,7 +239,6 @@ class Project : public QObject

void saveHealLocationsData(Map *map);
void saveHealLocationsConstants();
QString getHealLocationsTableName();

void ignoreWatchedFileTemporarily(QString filepath);

Expand Down
5 changes: 3 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ const QMap<ProjectIdentifier, QPair<QString, QString>> 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
Expand Down
30 changes: 18 additions & 12 deletions src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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+(?<name>[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);
Expand Down
Loading