Skip to content

Commit

Permalink
Add setting to disable/enable map text file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards authored and huderlem committed Feb 19, 2021
1 parent 80c5f74 commit 02af128
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions docsrc/manual/settings-and-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ determined by this file.
``enable_heal_location_respawn_data``, 1 if ``pokefirered``, project, yes, Adds ``Respawn Map`` and ``Respawn NPC`` to Heal Location events
``enable_object_event_in_connection``, 1 if ``pokefirered``, project, yes, Adds ``In Connection`` to Object events
``enable_floor_number``, 1 if ``pokefirered``, project, yes, Adds ``Floor Number`` to map headers
``create_map_text_file``, 1 if not ``pokeemerald``, project, yes, A ``text.inc`` or ``text.pory`` file will be created for any new map
``enable_triple_layer_metatiles``, 0, project, yes, Enables triple-layer metatiles (See https://github.com/pret/pokeemerald/wiki/Triple-layer-metatiles)
``custom_scripts``, , project, yes, A list of script files to load into the scripting engine

Expand Down
4 changes: 4 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class ProjectConfig: public KeyValueConfigBase
this->enableHealLocationRespawnData = false;
this->enableObjectEventInConnection = false;
this->enableFloorNumber = false;
this->createMapTextFile = false;
this->enableTripleLayerMetatiles = false;
this->customScripts.clear();
this->readKeys.clear();
Expand Down Expand Up @@ -172,6 +173,8 @@ class ProjectConfig: public KeyValueConfigBase
bool getObjectEventInConnectionEnabled();
void setFloorNumberEnabled(bool enable);
bool getFloorNumberEnabled();
void setCreateMapTextFileEnabled(bool enable);
bool getCreateMapTextFileEnabled();
void setTripleLayerMetatilesEnabled(bool enable);
bool getTripleLayerMetatilesEnabled();
void setCustomScripts(QList<QString> scripts);
Expand All @@ -196,6 +199,7 @@ class ProjectConfig: public KeyValueConfigBase
bool enableHealLocationRespawnData;
bool enableObjectEventInConnection;
bool enableFloorNumber;
bool createMapTextFile;
bool enableTripleLayerMetatiles;
QList<QString> customScripts;
QStringList readKeys;
Expand Down
18 changes: 18 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
if (!ok) {
logWarn(QString("Invalid config value for enable_floor_number: '%1'. Must be 0 or 1.").arg(value));
}
} else if (key == "create_map_text_file") {
bool ok;
this->createMapTextFile = value.toInt(&ok);
if (!ok) {
logWarn(QString("Invalid config value for create_map_text_file: '%1'. Must be 0 or 1.").arg(value));
}
} else if (key == "enable_triple_layer_metatiles") {
bool ok;
this->enableTripleLayerMetatiles = value.toInt(&ok);
Expand Down Expand Up @@ -535,6 +541,7 @@ void ProjectConfig::setUnreadKeys() {
if (!readKeys.contains("enable_heal_location_respawn_data")) this->enableHealLocationRespawnData = isPokefirered;
if (!readKeys.contains("enable_object_event_in_connection")) this->enableObjectEventInConnection = isPokefirered;
if (!readKeys.contains("enable_floor_number")) this->enableFloorNumber = isPokefirered;
if (!readKeys.contains("create_map_text_file")) this->createMapTextFile = (this->baseGameVersion != BaseGameVersion::pokeemerald);
}

QMap<QString, QString> ProjectConfig::getKeyValueMap() {
Expand All @@ -551,6 +558,7 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
map.insert("enable_heal_location_respawn_data", QString::number(this->enableHealLocationRespawnData));
map.insert("enable_object_event_in_connection", QString::number(this->enableObjectEventInConnection));
map.insert("enable_floor_number", QString::number(this->enableFloorNumber));
map.insert("create_map_text_file", QString::number(this->createMapTextFile));
map.insert("enable_triple_layer_metatiles", QString::number(this->enableTripleLayerMetatiles));
map.insert("custom_scripts", this->customScripts.join(","));
return map;
Expand Down Expand Up @@ -591,6 +599,7 @@ void ProjectConfig::onNewConfigFileCreated() {
this->enableHealLocationRespawnData = isPokefirered;
this->enableObjectEventInConnection = isPokefirered;
this->enableFloorNumber = isPokefirered;
this->createMapTextFile = (this->baseGameVersion != BaseGameVersion::pokeemerald);
this->useEncounterJson = true;
this->usePoryScript = false;
this->enableTripleLayerMetatiles = false;
Expand Down Expand Up @@ -713,6 +722,15 @@ bool ProjectConfig::getFloorNumberEnabled() {
return this->enableFloorNumber;
}

void ProjectConfig::setCreateMapTextFileEnabled(bool enable) {
this->createMapTextFile = enable;
this->save();
}

bool ProjectConfig::getCreateMapTextFileEnabled() {
return this->createMapTextFile;
}

void ProjectConfig::setTripleLayerMetatilesEnabled(bool enable) {
this->enableTripleLayerMetatiles = enable;
this->save();
Expand Down
5 changes: 3 additions & 2 deletions src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,14 +1242,15 @@ void Project::saveMap(Map *map) {
QString text = this->getScriptDefaultString(projectConfig.getUsePoryScript(), map->name);
saveTextFile(root + "/data/maps/" + map->name + "/scripts" + this->getScriptFileExtension(projectConfig.getUsePoryScript()), text);

if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby || projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) {
bool usesTextFile = projectConfig.getCreateMapTextFileEnabled();
if (usesTextFile) {
// Create file data/maps/<map_name>/text.inc
saveTextFile(root + "/data/maps/" + map->name + "/text" + this->getScriptFileExtension(projectConfig.getUsePoryScript()), "\n");
}

// Simply append to data/event_scripts.s.
text = QString("\n\t.include \"data/maps/%1/scripts.inc\"\n").arg(map->name);
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby || projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) {
if (usesTextFile) {
text += QString("\t.include \"data/maps/%1/text.inc\"\n").arg(map->name);
}
appendTextFile(root + "/data/event_scripts.s", text);
Expand Down

0 comments on commit 02af128

Please sign in to comment.