Convert remaing pointers in Project to values

This commit is contained in:
BigBahss 2021-02-15 11:33:30 -05:00 committed by huderlem
parent 820b514f26
commit 9a9143500f
5 changed files with 116 additions and 148 deletions

View file

@ -49,17 +49,17 @@ public:
QMap<QString, QString> mapSecToMapHoverName;
QMap<QString, int> mapSectionNameToValue;
QMap<int, QString> mapSectionValueToName;
QStringList *itemNames = nullptr;
QStringList *flagNames = nullptr;
QStringList *varNames = nullptr;
QStringList *movementTypes = nullptr;
QStringList *mapTypes = nullptr;
QStringList *mapBattleScenes = nullptr;
QStringList *weatherNames = nullptr;
QStringList *coordEventWeatherNames = nullptr;
QStringList *secretBaseIds = nullptr;
QStringList *bgEventFacingDirections = nullptr;
QStringList *trainerTypes = nullptr;
QStringList itemNames;
QStringList flagNames;
QStringList varNames;
QStringList movementTypes;
QStringList mapTypes;
QStringList mapBattleScenes;
QStringList weatherNames;
QStringList coordEventWeatherNames;
QStringList secretBaseIds;
QStringList bgEventFacingDirections;
QStringList trainerTypes;
QMap<QString, int> metatileBehaviorMap;
QMap<int, QString> metatileBehaviorMapInverse;
QMap<QString, QString> facingDirections;
@ -82,11 +82,11 @@ public:
DataQualifiers getDataQualifiers(QString, QString);
QMap<QString, DataQualifiers> dataQualifiers;
QMap<QString, Map*> *mapCache;
QMap<QString, Map*> mapCache;
Map* loadMap(QString);
Map* getMap(QString);
QMap<QString, Tileset*> *tilesetCache = nullptr;
QMap<QString, Tileset*> tilesetCache;
Tileset* loadTileset(QString, Tileset *tileset = nullptr);
Tileset* getTileset(QString, bool forceLoad = false);
QMap<QString, QStringList> tilesetLabels;

View file

@ -71,7 +71,7 @@ Event* Event::createNewObjectEvent(Project *project)
event->put("event_group_type", "object_event_group");
event->put("event_type", EventType::Object);
event->put("sprite", project->getEventObjGfxConstants().keys().first());
event->put("movement_type", project->movementTypes->first());
event->put("movement_type", project->movementTypes.first());
if (projectConfig.getObjectEventInConnectionEnabled()) {
event->put("in_connection", false);
}
@ -80,7 +80,7 @@ Event* Event::createNewObjectEvent(Project *project)
event->put("script_label", "NULL");
event->put("event_flag", "0");
event->put("replacement", "0");
event->put("trainer_type", project->trainerTypes->value(0, "0"));
event->put("trainer_type", project->trainerTypes.value(0, "0"));
event->put("sight_radius_tree_id", 0);
event->put("elevation", 3);
return event;
@ -118,7 +118,7 @@ Event* Event::createNewTriggerEvent(Project *project)
event->put("event_group_type", "coord_event_group");
event->put("event_type", EventType::Trigger);
event->put("script_label", "NULL");
event->put("script_var", project->varNames->first());
event->put("script_var", project->varNames.first());
event->put("script_var_value", "0");
event->put("elevation", 0);
return event;
@ -129,7 +129,7 @@ Event* Event::createNewWeatherTriggerEvent(Project *project)
Event *event = new Event;
event->put("event_group_type", "coord_event_group");
event->put("event_type", EventType::WeatherTrigger);
event->put("weather", project->coordEventWeatherNames->first());
event->put("weather", project->coordEventWeatherNames.first());
event->put("elevation", 0);
return event;
}
@ -139,7 +139,7 @@ Event* Event::createNewSignEvent(Project *project)
Event *event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::Sign);
event->put("player_facing_direction", project->bgEventFacingDirections->first());
event->put("player_facing_direction", project->bgEventFacingDirections.first());
event->put("script_label", "NULL");
event->put("elevation", 0);
return event;
@ -150,8 +150,8 @@ Event* Event::createNewHiddenItemEvent(Project *project)
Event *event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::HiddenItem);
event->put("item", project->itemNames->first());
event->put("flag", project->flagNames->first());
event->put("item", project->itemNames.first());
event->put("flag", project->flagNames.first());
event->put("elevation", 3);
if (projectConfig.getHiddenItemQuantityEnabled()) {
event->put("quantity", 1);
@ -167,7 +167,7 @@ Event* Event::createNewSecretBaseEvent(Project *project)
Event *event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::SecretBase);
event->put("secret_base_id", project->secretBaseIds->first());
event->put("secret_base_id", project->secretBaseIds.first());
event->put("elevation", 0);
return event;
}

View file

@ -910,11 +910,11 @@ bool MainWindow::loadProjectCombos() {
ui->comboBox_SecondaryTileset->clear();
ui->comboBox_SecondaryTileset->addItems(tilesets.value("secondary"));
ui->comboBox_Weather->clear();
ui->comboBox_Weather->addItems(*project->weatherNames);
ui->comboBox_Weather->addItems(project->weatherNames);
ui->comboBox_BattleScene->clear();
ui->comboBox_BattleScene->addItems(*project->mapBattleScenes);
ui->comboBox_BattleScene->addItems(project->mapBattleScenes);
ui->comboBox_Type->clear();
ui->comboBox_Type->addItems(*project->mapTypes);
ui->comboBox_Type->addItems(project->mapTypes);
return true;
}
@ -1347,10 +1347,10 @@ void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
QVariant data = index.data(Qt::UserRole);
if (!data.isNull()) {
QString map_name = data.toString();
if (editor->project && editor->project->mapCache->contains(map_name)) {
if (editor->project && editor->project->mapCache.contains(map_name)) {
QStandardItem *map = mapListModel->itemFromIndex(mapListIndexes.value(map_name));
map->setIcon(*mapIcon);
if (editor->project->mapCache->value(map_name)->hasUnsavedChanges()) {
if (editor->project->mapCache.value(map_name)->hasUnsavedChanges()) {
map->setIcon(*mapEditedIcon);
projectHasUnsavedChanges = true;
}
@ -1837,10 +1837,10 @@ void MainWindow::updateSelectedObjects() {
} else if (key == "destination_warp") {
combo->setToolTip("The warp id on the destination map.");
} else if (key == "item") {
if (!editor->project->itemNames->contains(value)) {
if (!editor->project->itemNames.contains(value)) {
combo->addItem(value);
}
combo->addItems(*editor->project->itemNames);
combo->addItems(editor->project->itemNames);
combo->setCurrentIndex(combo->findText(value));
} else if (key == "quantity") {
spin->setToolTip("The number of items received when the hidden item is picked up.");
@ -1849,27 +1849,27 @@ void MainWindow::updateSelectedObjects() {
} else if (key == "underfoot") {
check->setToolTip("If checked, hidden item can only be picked up using the Itemfinder");
} else if (key == "flag" || key == "event_flag") {
if (!editor->project->flagNames->contains(value)) {
if (!editor->project->flagNames.contains(value)) {
combo->addItem(value);
}
combo->addItems(*editor->project->flagNames);
combo->addItems(editor->project->flagNames);
combo->setCurrentIndex(combo->findText(value));
if (key == "flag")
combo->setToolTip("The flag which is set when the hidden item is picked up.");
else if (key == "event_flag")
combo->setToolTip("The flag which hides the object when set.");
} else if (key == "script_var") {
if (!editor->project->varNames->contains(value)) {
if (!editor->project->varNames.contains(value)) {
combo->addItem(value);
}
combo->addItems(*editor->project->varNames);
combo->addItems(editor->project->varNames);
combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The variable by which the script is triggered.\n"
"The script is triggered when this variable's value matches 'Var Value'.");
} else if (key == "script_var_value") {
combo->setToolTip("The variable's value which triggers the script.");
} else if (key == "movement_type") {
if (!editor->project->movementTypes->contains(value)) {
if (!editor->project->movementTypes.contains(value)) {
combo->addItem(value);
}
connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
@ -1877,31 +1877,31 @@ void MainWindow::updateSelectedObjects() {
item->event->setFrameFromMovement(editor->project->facingDirections.value(value));
item->updatePixmap();
});
combo->addItems(*editor->project->movementTypes);
combo->addItems(editor->project->movementTypes);
combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The object's natural movement behavior when\n"
"the player is not interacting with it.");
} else if (key == "weather") {
if (!editor->project->coordEventWeatherNames->contains(value)) {
if (!editor->project->coordEventWeatherNames.contains(value)) {
combo->addItem(value);
}
combo->addItems(*editor->project->coordEventWeatherNames);
combo->addItems(editor->project->coordEventWeatherNames);
combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The weather that starts when the player steps on this spot.");
} else if (key == "secret_base_id") {
if (!editor->project->secretBaseIds->contains(value)) {
if (!editor->project->secretBaseIds.contains(value)) {
combo->addItem(value);
}
combo->addItems(*editor->project->secretBaseIds);
combo->addItems(editor->project->secretBaseIds);
combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The secret base id which is inside this secret\n"
"base entrance. Secret base ids are meant to be\n"
"unique to each and every secret base entrance.");
} else if (key == "player_facing_direction") {
if (!editor->project->bgEventFacingDirections->contains(value)) {
if (!editor->project->bgEventFacingDirections.contains(value)) {
combo->addItem(value);
}
combo->addItems(*editor->project->bgEventFacingDirections);
combo->addItems(editor->project->bgEventFacingDirections);
combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The direction which the player must be facing\n"
"to be able to interact with this event.");
@ -1919,7 +1919,7 @@ void MainWindow::updateSelectedObjects() {
combo->addItems(editor->map->eventScriptLabels());
combo->setToolTip("The script which is executed with this event.");
} else if (key == "trainer_type") {
combo->addItems(*editor->project->trainerTypes);
combo->addItems(editor->project->trainerTypes);
combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The trainer type of this object event.\n"
"If it is not a trainer, use NONE. SEE ALL DIRECTIONS\n"

View file

@ -38,42 +38,13 @@ int Project::max_object_events = 64;
Project::Project(QWidget *parent) : parent(parent)
{
itemNames = new QStringList;
flagNames = new QStringList;
varNames = new QStringList;
movementTypes = new QStringList;
mapTypes = new QStringList;
mapBattleScenes = new QStringList;
weatherNames = new QStringList;
coordEventWeatherNames = new QStringList;
secretBaseIds = new QStringList;
bgEventFacingDirections = new QStringList;
trainerTypes = new QStringList;
mapCache = new QMap<QString, Map*>;
tilesetCache = new QMap<QString, Tileset*>;
initSignals();
}
Project::~Project()
{
delete this->itemNames;
delete this->flagNames;
delete this->varNames;
delete this->weatherNames;
delete this->coordEventWeatherNames;
delete this->secretBaseIds;
delete this->movementTypes;
delete this->bgEventFacingDirections;
delete this->mapBattleScenes;
delete this->trainerTypes;
delete this->mapTypes;
clearMapCache();
delete this->mapCache;
clearTilesetCache();
delete this->tilesetCache;
}
void Project::initSignals() {
@ -128,24 +99,24 @@ QString Project::getProjectTitle() {
}
void Project::clearMapCache() {
for (QString mapName : mapCache->keys()) {
Map *map = mapCache->take(mapName);
for (QString mapName : mapCache.keys()) {
Map *map = mapCache.take(mapName);
if (map) delete map;
}
emit mapCacheCleared();
}
void Project::clearTilesetCache() {
for (QString tilesetName : tilesetCache->keys()) {
Tileset *tileset = tilesetCache->take(tilesetName);
for (QString tilesetName : tilesetCache.keys()) {
Tileset *tileset = tilesetCache.take(tilesetName);
if (tileset) delete tileset;
}
}
Map* Project::loadMap(QString map_name) {
Map *map;
if (mapCache->contains(map_name)) {
map = mapCache->value(map_name);
if (mapCache.contains(map_name)) {
map = mapCache.value(map_name);
// TODO: uncomment when undo/redo history is fully implemented for all actions.
if (true/*map->hasUnsavedChanges()*/) {
return map;
@ -158,7 +129,7 @@ Map* Project::loadMap(QString map_name) {
if (!(loadMapData(map) && loadMapLayout(map)))
return nullptr;
mapCache->insert(map_name, map);
mapCache.insert(map_name, map);
return map;
}
@ -418,8 +389,8 @@ bool Project::loadMapData(Map* map) {
}
QString Project::readMapLayoutId(QString map_name) {
if (mapCache->contains(map_name)) {
return mapCache->value(map_name)->layoutId;
if (mapCache.contains(map_name)) {
return mapCache.value(map_name)->layoutId;
}
QString mapFilepath = QString("%1/data/maps/%2/map.json").arg(root).arg(map_name);
@ -434,8 +405,8 @@ QString Project::readMapLayoutId(QString map_name) {
}
QString Project::readMapLocation(QString map_name) {
if (mapCache->contains(map_name)) {
return mapCache->value(map_name)->location;
if (mapCache.contains(map_name)) {
return mapCache.value(map_name)->location;
}
QString mapFilepath = QString("%1/data/maps/%2/map.json").arg(root).arg(map_name);
@ -453,8 +424,8 @@ void Project::setNewMapHeader(Map* map, int mapIndex) {
map->layoutId = QString("%1").arg(mapIndex);
map->location = mapSectionValueToName.value(0);
map->requiresFlash = "FALSE";
map->weather = weatherNames->value(0, "WEATHER_NONE");
map->type = mapTypes->value(0, "MAP_TYPE_NONE");
map->weather = weatherNames.value(0, "WEATHER_NONE");
map->type = mapTypes.value(0, "MAP_TYPE_NONE");
map->song = defaultSong;
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby) {
map->show_location = "TRUE";
@ -468,7 +439,7 @@ void Project::setNewMapHeader(Map* map, int mapIndex) {
map->floorNumber = 0;
}
map->battle_scene = mapBattleScenes->value(0, "MAP_BATTLE_SCENE_NORMAL");
map->battle_scene = mapBattleScenes.value(0, "MAP_BATTLE_SCENE_NORMAL");
}
bool Project::loadMapLayout(Map* map) {
@ -1161,7 +1132,7 @@ Tileset* Project::loadTileset(QString label, Tileset *tileset) {
loadTilesetAssets(tileset);
tilesetCache->insert(label, tileset);
tilesetCache.insert(label, tileset);
return tileset;
}
@ -1252,10 +1223,10 @@ void Project::writeBlockdata(QString path, const Blockdata &blockdata) {
}
void Project::saveAllMaps() {
QList<QString> keys = mapCache->keys();
QList<QString> keys = mapCache.keys();
for (int i = 0; i < keys.length(); i++) {
QString key = keys.value(i);
Map* map = mapCache->value(key);
Map* map = mapCache.value(key);
saveMap(map);
}
}
@ -1701,8 +1672,8 @@ Blockdata Project::readBlockdata(QString path) {
}
Map* Project::getMap(QString map_name) {
if (mapCache->contains(map_name)) {
return mapCache->value(map_name);
if (mapCache.contains(map_name)) {
return mapCache.value(map_name);
} else {
Map *map = loadMap(map_name);
return map;
@ -1711,12 +1682,12 @@ Map* Project::getMap(QString map_name) {
Tileset* Project::getTileset(QString label, bool forceLoad) {
Tileset *existingTileset = nullptr;
if (tilesetCache->contains(label)) {
existingTileset = tilesetCache->value(label);
if (tilesetCache.contains(label)) {
existingTileset = tilesetCache.value(label);
}
if (existingTileset && !forceLoad) {
return tilesetCache->value(label);
return tilesetCache.value(label);
} else {
Tileset *tileset = loadTileset(label, existingTileset);
return tileset;
@ -1886,7 +1857,7 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
setNewMapBorder(map);
setNewMapEvents(map);
setNewMapConnections(map);
mapCache->insert(mapName, map);
mapCache.insert(mapName, map);
return map;
}
@ -2142,12 +2113,12 @@ bool Project::readHealLocations() {
}
bool Project::readItemNames() {
itemNames->clear();
QStringList prefixes = (QStringList() << "\\bITEM_(?!(B_)?USE_)"); // Exclude ITEM_USE_ and ITEM_B_USE_ constants
itemNames.clear();
QStringList prefixes("\\bITEM_(?!(B_)?USE_)"); // Exclude ITEM_USE_ and ITEM_B_USE_ constants
QString filename = "include/constants/items.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, itemNames);
if (itemNames->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &itemNames);
if (itemNames.isEmpty()) {
logError(QString("Failed to read item constants from %1").arg(filename));
return false;
}
@ -2161,12 +2132,12 @@ bool Project::readFlagNames() {
fileWatcher.addPath(root + "/" + opponentsFilename);
QMap<QString, int> maxTrainers = parser.readCDefines(opponentsFilename, QStringList() << "\\bMAX_");
// Parse flags
flagNames->clear();
QStringList prefixes = (QStringList() << "\\bFLAG_");
flagNames.clear();
QStringList prefixes("\\bFLAG_");
QString flagsFilename = "include/constants/flags.h";
fileWatcher.addPath(root + "/" + flagsFilename);
parser.readCDefinesSorted(flagsFilename, prefixes, flagNames, maxTrainers);
if (flagNames->isEmpty()) {
parser.readCDefinesSorted(flagsFilename, prefixes, &flagNames, maxTrainers);
if (flagNames.isEmpty()) {
logError(QString("Failed to read flag constants from %1").arg(flagsFilename));
return false;
}
@ -2174,12 +2145,12 @@ bool Project::readFlagNames() {
}
bool Project::readVarNames() {
varNames->clear();
QStringList prefixes = (QStringList() << "\\bVAR_");
varNames.clear();
QStringList prefixes("\\bVAR_");
QString filename = "include/constants/vars.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, varNames);
if (varNames->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &varNames);
if (varNames.isEmpty()) {
logError(QString("Failed to read var constants from %1").arg(filename));
return false;
}
@ -2187,12 +2158,12 @@ bool Project::readVarNames() {
}
bool Project::readMovementTypes() {
movementTypes->clear();
QStringList prefixes = (QStringList() << "\\bMOVEMENT_TYPE_");
movementTypes.clear();
QStringList prefixes("\\bMOVEMENT_TYPE_");
QString filename = "include/constants/event_object_movement.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, movementTypes);
if (movementTypes->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &movementTypes);
if (movementTypes.isEmpty()) {
logError(QString("Failed to read movement type constants from %1").arg(filename));
return false;
}
@ -2211,12 +2182,12 @@ bool Project::readInitialFacingDirections() {
}
bool Project::readMapTypes() {
mapTypes->clear();
QStringList prefixes = (QStringList() << "\\bMAP_TYPE_");
mapTypes.clear();
QStringList prefixes("\\bMAP_TYPE_");
QString filename = "include/constants/map_types.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, mapTypes);
if (mapTypes->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &mapTypes);
if (mapTypes.isEmpty()) {
logError(QString("Failed to read map type constants from %1").arg(filename));
return false;
}
@ -2224,12 +2195,12 @@ bool Project::readMapTypes() {
}
bool Project::readMapBattleScenes() {
mapBattleScenes->clear();
QStringList prefixes = (QStringList() << "\\bMAP_BATTLE_SCENE_");
mapBattleScenes.clear();
QStringList prefixes("\\bMAP_BATTLE_SCENE_");
QString filename = "include/constants/map_types.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted("include/constants/map_types.h", prefixes, mapBattleScenes);
if (mapBattleScenes->isEmpty()) {
parser.readCDefinesSorted("include/constants/map_types.h", prefixes, &mapBattleScenes);
if (mapBattleScenes.isEmpty()) {
logError(QString("Failed to read map battle scene constants from %1").arg(filename));
return false;
}
@ -2237,12 +2208,12 @@ bool Project::readMapBattleScenes() {
}
bool Project::readWeatherNames() {
weatherNames->clear();
QStringList prefixes = (QStringList() << "\\bWEATHER_");
weatherNames.clear();
QStringList prefixes("\\bWEATHER_");
QString filename = "include/constants/weather.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, weatherNames);
if (weatherNames->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &weatherNames);
if (weatherNames.isEmpty()) {
logError(QString("Failed to read weather constants from %1").arg(filename));
return false;
}
@ -2252,12 +2223,12 @@ bool Project::readWeatherNames() {
bool Project::readCoordEventWeatherNames() {
if (!projectConfig.getEventWeatherTriggerEnabled()) return true;
coordEventWeatherNames->clear();
QStringList prefixes = (QStringList() << "\\bCOORD_EVENT_WEATHER_");
coordEventWeatherNames.clear();
QStringList prefixes("\\bCOORD_EVENT_WEATHER_");
QString filename = "include/constants/weather.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, coordEventWeatherNames);
if (coordEventWeatherNames->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &coordEventWeatherNames);
if (coordEventWeatherNames.isEmpty()) {
logError(QString("Failed to read coord event weather constants from %1").arg(filename));
return false;
}
@ -2267,12 +2238,12 @@ bool Project::readCoordEventWeatherNames() {
bool Project::readSecretBaseIds() {
if (!projectConfig.getEventSecretBaseEnabled()) return true;
secretBaseIds->clear();
QStringList prefixes = (QStringList() << "\\bSECRET_BASE_[A-Za-z0-9_]*_[0-9]+");
secretBaseIds.clear();
QStringList prefixes("\\bSECRET_BASE_[A-Za-z0-9_]*_[0-9]+");
QString filename = "include/constants/secret_bases.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, secretBaseIds);
if (secretBaseIds->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &secretBaseIds);
if (secretBaseIds.isEmpty()) {
logError(QString("Failed to read secret base id constants from %1").arg(filename));
return false;
}
@ -2280,12 +2251,12 @@ bool Project::readSecretBaseIds() {
}
bool Project::readBgEventFacingDirections() {
bgEventFacingDirections->clear();
QStringList prefixes = (QStringList() << "\\bBG_EVENT_PLAYER_FACING_");
bgEventFacingDirections.clear();
QStringList prefixes("\\bBG_EVENT_PLAYER_FACING_");
QString filename = "include/constants/event_bg.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, bgEventFacingDirections);
if (bgEventFacingDirections->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &bgEventFacingDirections);
if (bgEventFacingDirections.isEmpty()) {
logError(QString("Failed to read bg event facing direction constants from %1").arg(filename));
return false;
}
@ -2293,12 +2264,12 @@ bool Project::readBgEventFacingDirections() {
}
bool Project::readTrainerTypes() {
trainerTypes->clear();
QStringList prefixes = (QStringList() << "\\bTRAINER_TYPE_");
trainerTypes.clear();
QStringList prefixes("\\bTRAINER_TYPE_");
QString filename = "include/constants/trainer_types.h";
fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, trainerTypes);
if (trainerTypes->isEmpty()) {
parser.readCDefinesSorted(filename, prefixes, &trainerTypes);
if (trainerTypes.isEmpty()) {
logError(QString("Failed to read trainer type constants from %1").arg(filename));
return false;
}
@ -2309,7 +2280,7 @@ bool Project::readMetatileBehaviors() {
this->metatileBehaviorMap.clear();
this->metatileBehaviorMapInverse.clear();
QStringList prefixes = (QStringList() << "\\bMB_");
QStringList prefixes("\\bMB_");
QString filename = "include/constants/metatile_behaviors.h";
fileWatcher.addPath(root + "/" + filename);
this->metatileBehaviorMap = parser.readCDefines(filename, prefixes);
@ -2325,8 +2296,7 @@ bool Project::readMetatileBehaviors() {
}
QStringList Project::getSongNames() {
QStringList songDefinePrefixes;
songDefinePrefixes << "\\bSE_" << "\\bMUS_";
QStringList songDefinePrefixes{ "\\bSE_", "\\bMUS_" };
QString filename = "include/constants/songs.h";
fileWatcher.addPath(root + "/" + filename);
QMap<QString, int> songDefines = parser.readCDefines(filename, songDefinePrefixes);
@ -2337,8 +2307,7 @@ QStringList Project::getSongNames() {
}
QMap<QString, int> Project::getEventObjGfxConstants() {
QStringList eventObjGfxPrefixes;
eventObjGfxPrefixes << "\\bOBJ_EVENT_GFX_";
QStringList eventObjGfxPrefixes("\\bOBJ_EVENT_GFX_");
QString filename = "include/constants/event_objects.h";
fileWatcher.addPath(root + "/" + filename);
@ -2352,15 +2321,14 @@ bool Project::readMiscellaneousConstants() {
if (projectConfig.getEncounterJsonActive()) {
QString filename = "include/constants/pokemon.h";
fileWatcher.addPath(root + "/" + filename);
QMap<QString, int> pokemonDefines = parser.readCDefines(filename, QStringList() << "MIN_" << "MAX_");
QMap<QString, int> pokemonDefines = parser.readCDefines(filename, { "MIN_", "MAX_" });
miscConstants.insert("max_level_define", pokemonDefines.value("MAX_LEVEL") > pokemonDefines.value("MIN_LEVEL") ? pokemonDefines.value("MAX_LEVEL") : 100);
miscConstants.insert("min_level_define", pokemonDefines.value("MIN_LEVEL") < pokemonDefines.value("MAX_LEVEL") ? pokemonDefines.value("MIN_LEVEL") : 1);
}
QString filename = "include/constants/global.h";
fileWatcher.addPath(root + "/" + filename);
QStringList definePrefixes;
definePrefixes << "\\bOBJECT_";
QStringList definePrefixes("\\bOBJECT_");
QMap<QString, int> defines = parser.readCDefines(filename, definePrefixes);
auto it = defines.find("OBJECT_EVENT_TEMPLATES_COUNT");

View file

@ -110,7 +110,7 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT);
}
ui->comboBox_NewMap_Type->addItems(*project->mapTypes);
ui->comboBox_NewMap_Type->addItems(project->mapTypes);
ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values());
if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setCurrentText(mapSec);
ui->checkBox_NewMap_Show_Location->setChecked(true);
@ -197,9 +197,9 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
newMap->location = this->ui->comboBox_NewMap_Location->currentText();
newMap->song = this->project->defaultSong;
newMap->requiresFlash = "0";
newMap->weather = this->project->weatherNames->value(0, "WEATHER_NONE");
newMap->weather = this->project->weatherNames.value(0, "WEATHER_NONE");
newMap->show_location = this->ui->checkBox_NewMap_Show_Location->isChecked() ? "1" : "0";
newMap->battle_scene = this->project->mapBattleScenes->value(0, "MAP_BATTLE_SCENE_NORMAL");
newMap->battle_scene = this->project->mapBattleScenes.value(0, "MAP_BATTLE_SCENE_NORMAL");
if (this->existingLayout) {
layout = this->project->mapLayouts.value(this->layoutId);