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, QString> mapSecToMapHoverName;
QMap<QString, int> mapSectionNameToValue; QMap<QString, int> mapSectionNameToValue;
QMap<int, QString> mapSectionValueToName; QMap<int, QString> mapSectionValueToName;
QStringList *itemNames = nullptr; QStringList itemNames;
QStringList *flagNames = nullptr; QStringList flagNames;
QStringList *varNames = nullptr; QStringList varNames;
QStringList *movementTypes = nullptr; QStringList movementTypes;
QStringList *mapTypes = nullptr; QStringList mapTypes;
QStringList *mapBattleScenes = nullptr; QStringList mapBattleScenes;
QStringList *weatherNames = nullptr; QStringList weatherNames;
QStringList *coordEventWeatherNames = nullptr; QStringList coordEventWeatherNames;
QStringList *secretBaseIds = nullptr; QStringList secretBaseIds;
QStringList *bgEventFacingDirections = nullptr; QStringList bgEventFacingDirections;
QStringList *trainerTypes = nullptr; QStringList trainerTypes;
QMap<QString, int> metatileBehaviorMap; QMap<QString, int> metatileBehaviorMap;
QMap<int, QString> metatileBehaviorMapInverse; QMap<int, QString> metatileBehaviorMapInverse;
QMap<QString, QString> facingDirections; QMap<QString, QString> facingDirections;
@ -82,11 +82,11 @@ public:
DataQualifiers getDataQualifiers(QString, QString); DataQualifiers getDataQualifiers(QString, QString);
QMap<QString, DataQualifiers> dataQualifiers; QMap<QString, DataQualifiers> dataQualifiers;
QMap<QString, Map*> *mapCache; QMap<QString, Map*> mapCache;
Map* loadMap(QString); Map* loadMap(QString);
Map* getMap(QString); Map* getMap(QString);
QMap<QString, Tileset*> *tilesetCache = nullptr; QMap<QString, Tileset*> tilesetCache;
Tileset* loadTileset(QString, Tileset *tileset = nullptr); Tileset* loadTileset(QString, Tileset *tileset = nullptr);
Tileset* getTileset(QString, bool forceLoad = false); Tileset* getTileset(QString, bool forceLoad = false);
QMap<QString, QStringList> tilesetLabels; 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_group_type", "object_event_group");
event->put("event_type", EventType::Object); event->put("event_type", EventType::Object);
event->put("sprite", project->getEventObjGfxConstants().keys().first()); event->put("sprite", project->getEventObjGfxConstants().keys().first());
event->put("movement_type", project->movementTypes->first()); event->put("movement_type", project->movementTypes.first());
if (projectConfig.getObjectEventInConnectionEnabled()) { if (projectConfig.getObjectEventInConnectionEnabled()) {
event->put("in_connection", false); event->put("in_connection", false);
} }
@ -80,7 +80,7 @@ Event* Event::createNewObjectEvent(Project *project)
event->put("script_label", "NULL"); event->put("script_label", "NULL");
event->put("event_flag", "0"); event->put("event_flag", "0");
event->put("replacement", "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("sight_radius_tree_id", 0);
event->put("elevation", 3); event->put("elevation", 3);
return event; return event;
@ -118,7 +118,7 @@ Event* Event::createNewTriggerEvent(Project *project)
event->put("event_group_type", "coord_event_group"); event->put("event_group_type", "coord_event_group");
event->put("event_type", EventType::Trigger); event->put("event_type", EventType::Trigger);
event->put("script_label", "NULL"); 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("script_var_value", "0");
event->put("elevation", 0); event->put("elevation", 0);
return event; return event;
@ -129,7 +129,7 @@ Event* Event::createNewWeatherTriggerEvent(Project *project)
Event *event = new Event; Event *event = new Event;
event->put("event_group_type", "coord_event_group"); event->put("event_group_type", "coord_event_group");
event->put("event_type", EventType::WeatherTrigger); event->put("event_type", EventType::WeatherTrigger);
event->put("weather", project->coordEventWeatherNames->first()); event->put("weather", project->coordEventWeatherNames.first());
event->put("elevation", 0); event->put("elevation", 0);
return event; return event;
} }
@ -139,7 +139,7 @@ Event* Event::createNewSignEvent(Project *project)
Event *event = new Event; Event *event = new Event;
event->put("event_group_type", "bg_event_group"); event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::Sign); 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("script_label", "NULL");
event->put("elevation", 0); event->put("elevation", 0);
return event; return event;
@ -150,8 +150,8 @@ Event* Event::createNewHiddenItemEvent(Project *project)
Event *event = new Event; Event *event = new Event;
event->put("event_group_type", "bg_event_group"); event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::HiddenItem); event->put("event_type", EventType::HiddenItem);
event->put("item", project->itemNames->first()); event->put("item", project->itemNames.first());
event->put("flag", project->flagNames->first()); event->put("flag", project->flagNames.first());
event->put("elevation", 3); event->put("elevation", 3);
if (projectConfig.getHiddenItemQuantityEnabled()) { if (projectConfig.getHiddenItemQuantityEnabled()) {
event->put("quantity", 1); event->put("quantity", 1);
@ -167,7 +167,7 @@ Event* Event::createNewSecretBaseEvent(Project *project)
Event *event = new Event; Event *event = new Event;
event->put("event_group_type", "bg_event_group"); event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::SecretBase); 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); event->put("elevation", 0);
return event; return event;
} }

View file

@ -910,11 +910,11 @@ bool MainWindow::loadProjectCombos() {
ui->comboBox_SecondaryTileset->clear(); ui->comboBox_SecondaryTileset->clear();
ui->comboBox_SecondaryTileset->addItems(tilesets.value("secondary")); ui->comboBox_SecondaryTileset->addItems(tilesets.value("secondary"));
ui->comboBox_Weather->clear(); ui->comboBox_Weather->clear();
ui->comboBox_Weather->addItems(*project->weatherNames); ui->comboBox_Weather->addItems(project->weatherNames);
ui->comboBox_BattleScene->clear(); ui->comboBox_BattleScene->clear();
ui->comboBox_BattleScene->addItems(*project->mapBattleScenes); ui->comboBox_BattleScene->addItems(project->mapBattleScenes);
ui->comboBox_Type->clear(); ui->comboBox_Type->clear();
ui->comboBox_Type->addItems(*project->mapTypes); ui->comboBox_Type->addItems(project->mapTypes);
return true; return true;
} }
@ -1347,10 +1347,10 @@ void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
QVariant data = index.data(Qt::UserRole); QVariant data = index.data(Qt::UserRole);
if (!data.isNull()) { if (!data.isNull()) {
QString map_name = data.toString(); 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)); QStandardItem *map = mapListModel->itemFromIndex(mapListIndexes.value(map_name));
map->setIcon(*mapIcon); map->setIcon(*mapIcon);
if (editor->project->mapCache->value(map_name)->hasUnsavedChanges()) { if (editor->project->mapCache.value(map_name)->hasUnsavedChanges()) {
map->setIcon(*mapEditedIcon); map->setIcon(*mapEditedIcon);
projectHasUnsavedChanges = true; projectHasUnsavedChanges = true;
} }
@ -1837,10 +1837,10 @@ void MainWindow::updateSelectedObjects() {
} else if (key == "destination_warp") { } else if (key == "destination_warp") {
combo->setToolTip("The warp id on the destination map."); combo->setToolTip("The warp id on the destination map.");
} else if (key == "item") { } else if (key == "item") {
if (!editor->project->itemNames->contains(value)) { if (!editor->project->itemNames.contains(value)) {
combo->addItem(value); combo->addItem(value);
} }
combo->addItems(*editor->project->itemNames); combo->addItems(editor->project->itemNames);
combo->setCurrentIndex(combo->findText(value)); combo->setCurrentIndex(combo->findText(value));
} else if (key == "quantity") { } else if (key == "quantity") {
spin->setToolTip("The number of items received when the hidden item is picked up."); 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") { } else if (key == "underfoot") {
check->setToolTip("If checked, hidden item can only be picked up using the Itemfinder"); check->setToolTip("If checked, hidden item can only be picked up using the Itemfinder");
} else if (key == "flag" || key == "event_flag") { } else if (key == "flag" || key == "event_flag") {
if (!editor->project->flagNames->contains(value)) { if (!editor->project->flagNames.contains(value)) {
combo->addItem(value); combo->addItem(value);
} }
combo->addItems(*editor->project->flagNames); combo->addItems(editor->project->flagNames);
combo->setCurrentIndex(combo->findText(value)); combo->setCurrentIndex(combo->findText(value));
if (key == "flag") if (key == "flag")
combo->setToolTip("The flag which is set when the hidden item is picked up."); combo->setToolTip("The flag which is set when the hidden item is picked up.");
else if (key == "event_flag") else if (key == "event_flag")
combo->setToolTip("The flag which hides the object when set."); combo->setToolTip("The flag which hides the object when set.");
} else if (key == "script_var") { } else if (key == "script_var") {
if (!editor->project->varNames->contains(value)) { if (!editor->project->varNames.contains(value)) {
combo->addItem(value); combo->addItem(value);
} }
combo->addItems(*editor->project->varNames); combo->addItems(editor->project->varNames);
combo->setCurrentIndex(combo->findText(value)); combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The variable by which the script is triggered.\n" combo->setToolTip("The variable by which the script is triggered.\n"
"The script is triggered when this variable's value matches 'Var Value'."); "The script is triggered when this variable's value matches 'Var Value'.");
} else if (key == "script_var_value") { } else if (key == "script_var_value") {
combo->setToolTip("The variable's value which triggers the script."); combo->setToolTip("The variable's value which triggers the script.");
} else if (key == "movement_type") { } else if (key == "movement_type") {
if (!editor->project->movementTypes->contains(value)) { if (!editor->project->movementTypes.contains(value)) {
combo->addItem(value); combo->addItem(value);
} }
connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged), 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->event->setFrameFromMovement(editor->project->facingDirections.value(value));
item->updatePixmap(); item->updatePixmap();
}); });
combo->addItems(*editor->project->movementTypes); combo->addItems(editor->project->movementTypes);
combo->setCurrentIndex(combo->findText(value)); combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The object's natural movement behavior when\n" combo->setToolTip("The object's natural movement behavior when\n"
"the player is not interacting with it."); "the player is not interacting with it.");
} else if (key == "weather") { } else if (key == "weather") {
if (!editor->project->coordEventWeatherNames->contains(value)) { if (!editor->project->coordEventWeatherNames.contains(value)) {
combo->addItem(value); combo->addItem(value);
} }
combo->addItems(*editor->project->coordEventWeatherNames); combo->addItems(editor->project->coordEventWeatherNames);
combo->setCurrentIndex(combo->findText(value)); combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The weather that starts when the player steps on this spot."); combo->setToolTip("The weather that starts when the player steps on this spot.");
} else if (key == "secret_base_id") { } else if (key == "secret_base_id") {
if (!editor->project->secretBaseIds->contains(value)) { if (!editor->project->secretBaseIds.contains(value)) {
combo->addItem(value); combo->addItem(value);
} }
combo->addItems(*editor->project->secretBaseIds); combo->addItems(editor->project->secretBaseIds);
combo->setCurrentIndex(combo->findText(value)); combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The secret base id which is inside this secret\n" combo->setToolTip("The secret base id which is inside this secret\n"
"base entrance. Secret base ids are meant to be\n" "base entrance. Secret base ids are meant to be\n"
"unique to each and every secret base entrance."); "unique to each and every secret base entrance.");
} else if (key == "player_facing_direction") { } else if (key == "player_facing_direction") {
if (!editor->project->bgEventFacingDirections->contains(value)) { if (!editor->project->bgEventFacingDirections.contains(value)) {
combo->addItem(value); combo->addItem(value);
} }
combo->addItems(*editor->project->bgEventFacingDirections); combo->addItems(editor->project->bgEventFacingDirections);
combo->setCurrentIndex(combo->findText(value)); combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The direction which the player must be facing\n" combo->setToolTip("The direction which the player must be facing\n"
"to be able to interact with this event."); "to be able to interact with this event.");
@ -1919,7 +1919,7 @@ void MainWindow::updateSelectedObjects() {
combo->addItems(editor->map->eventScriptLabels()); combo->addItems(editor->map->eventScriptLabels());
combo->setToolTip("The script which is executed with this event."); combo->setToolTip("The script which is executed with this event.");
} else if (key == "trainer_type") { } else if (key == "trainer_type") {
combo->addItems(*editor->project->trainerTypes); combo->addItems(editor->project->trainerTypes);
combo->setCurrentIndex(combo->findText(value)); combo->setCurrentIndex(combo->findText(value));
combo->setToolTip("The trainer type of this object event.\n" combo->setToolTip("The trainer type of this object event.\n"
"If it is not a trainer, use NONE. SEE ALL DIRECTIONS\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) 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(); initSignals();
} }
Project::~Project() 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(); clearMapCache();
delete this->mapCache;
clearTilesetCache(); clearTilesetCache();
delete this->tilesetCache;
} }
void Project::initSignals() { void Project::initSignals() {
@ -128,24 +99,24 @@ QString Project::getProjectTitle() {
} }
void Project::clearMapCache() { void Project::clearMapCache() {
for (QString mapName : mapCache->keys()) { for (QString mapName : mapCache.keys()) {
Map *map = mapCache->take(mapName); Map *map = mapCache.take(mapName);
if (map) delete map; if (map) delete map;
} }
emit mapCacheCleared(); emit mapCacheCleared();
} }
void Project::clearTilesetCache() { void Project::clearTilesetCache() {
for (QString tilesetName : tilesetCache->keys()) { for (QString tilesetName : tilesetCache.keys()) {
Tileset *tileset = tilesetCache->take(tilesetName); Tileset *tileset = tilesetCache.take(tilesetName);
if (tileset) delete tileset; if (tileset) delete tileset;
} }
} }
Map* Project::loadMap(QString map_name) { Map* Project::loadMap(QString map_name) {
Map *map; Map *map;
if (mapCache->contains(map_name)) { if (mapCache.contains(map_name)) {
map = mapCache->value(map_name); map = mapCache.value(map_name);
// TODO: uncomment when undo/redo history is fully implemented for all actions. // TODO: uncomment when undo/redo history is fully implemented for all actions.
if (true/*map->hasUnsavedChanges()*/) { if (true/*map->hasUnsavedChanges()*/) {
return map; return map;
@ -158,7 +129,7 @@ Map* Project::loadMap(QString map_name) {
if (!(loadMapData(map) && loadMapLayout(map))) if (!(loadMapData(map) && loadMapLayout(map)))
return nullptr; return nullptr;
mapCache->insert(map_name, map); mapCache.insert(map_name, map);
return map; return map;
} }
@ -418,8 +389,8 @@ bool Project::loadMapData(Map* map) {
} }
QString Project::readMapLayoutId(QString map_name) { QString Project::readMapLayoutId(QString map_name) {
if (mapCache->contains(map_name)) { if (mapCache.contains(map_name)) {
return mapCache->value(map_name)->layoutId; return mapCache.value(map_name)->layoutId;
} }
QString mapFilepath = QString("%1/data/maps/%2/map.json").arg(root).arg(map_name); 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) { QString Project::readMapLocation(QString map_name) {
if (mapCache->contains(map_name)) { if (mapCache.contains(map_name)) {
return mapCache->value(map_name)->location; return mapCache.value(map_name)->location;
} }
QString mapFilepath = QString("%1/data/maps/%2/map.json").arg(root).arg(map_name); 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->layoutId = QString("%1").arg(mapIndex);
map->location = mapSectionValueToName.value(0); map->location = mapSectionValueToName.value(0);
map->requiresFlash = "FALSE"; map->requiresFlash = "FALSE";
map->weather = weatherNames->value(0, "WEATHER_NONE"); map->weather = weatherNames.value(0, "WEATHER_NONE");
map->type = mapTypes->value(0, "MAP_TYPE_NONE"); map->type = mapTypes.value(0, "MAP_TYPE_NONE");
map->song = defaultSong; map->song = defaultSong;
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby) { if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby) {
map->show_location = "TRUE"; map->show_location = "TRUE";
@ -468,7 +439,7 @@ void Project::setNewMapHeader(Map* map, int mapIndex) {
map->floorNumber = 0; 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) { bool Project::loadMapLayout(Map* map) {
@ -1161,7 +1132,7 @@ Tileset* Project::loadTileset(QString label, Tileset *tileset) {
loadTilesetAssets(tileset); loadTilesetAssets(tileset);
tilesetCache->insert(label, tileset); tilesetCache.insert(label, tileset);
return tileset; return tileset;
} }
@ -1252,10 +1223,10 @@ void Project::writeBlockdata(QString path, const Blockdata &blockdata) {
} }
void Project::saveAllMaps() { void Project::saveAllMaps() {
QList<QString> keys = mapCache->keys(); QList<QString> keys = mapCache.keys();
for (int i = 0; i < keys.length(); i++) { for (int i = 0; i < keys.length(); i++) {
QString key = keys.value(i); QString key = keys.value(i);
Map* map = mapCache->value(key); Map* map = mapCache.value(key);
saveMap(map); saveMap(map);
} }
} }
@ -1701,8 +1672,8 @@ Blockdata Project::readBlockdata(QString path) {
} }
Map* Project::getMap(QString map_name) { Map* Project::getMap(QString map_name) {
if (mapCache->contains(map_name)) { if (mapCache.contains(map_name)) {
return mapCache->value(map_name); return mapCache.value(map_name);
} else { } else {
Map *map = loadMap(map_name); Map *map = loadMap(map_name);
return map; return map;
@ -1711,12 +1682,12 @@ Map* Project::getMap(QString map_name) {
Tileset* Project::getTileset(QString label, bool forceLoad) { Tileset* Project::getTileset(QString label, bool forceLoad) {
Tileset *existingTileset = nullptr; Tileset *existingTileset = nullptr;
if (tilesetCache->contains(label)) { if (tilesetCache.contains(label)) {
existingTileset = tilesetCache->value(label); existingTileset = tilesetCache.value(label);
} }
if (existingTileset && !forceLoad) { if (existingTileset && !forceLoad) {
return tilesetCache->value(label); return tilesetCache.value(label);
} else { } else {
Tileset *tileset = loadTileset(label, existingTileset); Tileset *tileset = loadTileset(label, existingTileset);
return tileset; return tileset;
@ -1886,7 +1857,7 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
setNewMapBorder(map); setNewMapBorder(map);
setNewMapEvents(map); setNewMapEvents(map);
setNewMapConnections(map); setNewMapConnections(map);
mapCache->insert(mapName, map); mapCache.insert(mapName, map);
return map; return map;
} }
@ -2142,12 +2113,12 @@ bool Project::readHealLocations() {
} }
bool Project::readItemNames() { bool Project::readItemNames() {
itemNames->clear(); itemNames.clear();
QStringList prefixes = (QStringList() << "\\bITEM_(?!(B_)?USE_)"); // Exclude ITEM_USE_ and ITEM_B_USE_ constants QStringList prefixes("\\bITEM_(?!(B_)?USE_)"); // Exclude ITEM_USE_ and ITEM_B_USE_ constants
QString filename = "include/constants/items.h"; QString filename = "include/constants/items.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, itemNames); parser.readCDefinesSorted(filename, prefixes, &itemNames);
if (itemNames->isEmpty()) { if (itemNames.isEmpty()) {
logError(QString("Failed to read item constants from %1").arg(filename)); logError(QString("Failed to read item constants from %1").arg(filename));
return false; return false;
} }
@ -2161,12 +2132,12 @@ bool Project::readFlagNames() {
fileWatcher.addPath(root + "/" + opponentsFilename); fileWatcher.addPath(root + "/" + opponentsFilename);
QMap<QString, int> maxTrainers = parser.readCDefines(opponentsFilename, QStringList() << "\\bMAX_"); QMap<QString, int> maxTrainers = parser.readCDefines(opponentsFilename, QStringList() << "\\bMAX_");
// Parse flags // Parse flags
flagNames->clear(); flagNames.clear();
QStringList prefixes = (QStringList() << "\\bFLAG_"); QStringList prefixes("\\bFLAG_");
QString flagsFilename = "include/constants/flags.h"; QString flagsFilename = "include/constants/flags.h";
fileWatcher.addPath(root + "/" + flagsFilename); fileWatcher.addPath(root + "/" + flagsFilename);
parser.readCDefinesSorted(flagsFilename, prefixes, flagNames, maxTrainers); parser.readCDefinesSorted(flagsFilename, prefixes, &flagNames, maxTrainers);
if (flagNames->isEmpty()) { if (flagNames.isEmpty()) {
logError(QString("Failed to read flag constants from %1").arg(flagsFilename)); logError(QString("Failed to read flag constants from %1").arg(flagsFilename));
return false; return false;
} }
@ -2174,12 +2145,12 @@ bool Project::readFlagNames() {
} }
bool Project::readVarNames() { bool Project::readVarNames() {
varNames->clear(); varNames.clear();
QStringList prefixes = (QStringList() << "\\bVAR_"); QStringList prefixes("\\bVAR_");
QString filename = "include/constants/vars.h"; QString filename = "include/constants/vars.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, varNames); parser.readCDefinesSorted(filename, prefixes, &varNames);
if (varNames->isEmpty()) { if (varNames.isEmpty()) {
logError(QString("Failed to read var constants from %1").arg(filename)); logError(QString("Failed to read var constants from %1").arg(filename));
return false; return false;
} }
@ -2187,12 +2158,12 @@ bool Project::readVarNames() {
} }
bool Project::readMovementTypes() { bool Project::readMovementTypes() {
movementTypes->clear(); movementTypes.clear();
QStringList prefixes = (QStringList() << "\\bMOVEMENT_TYPE_"); QStringList prefixes("\\bMOVEMENT_TYPE_");
QString filename = "include/constants/event_object_movement.h"; QString filename = "include/constants/event_object_movement.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, movementTypes); parser.readCDefinesSorted(filename, prefixes, &movementTypes);
if (movementTypes->isEmpty()) { if (movementTypes.isEmpty()) {
logError(QString("Failed to read movement type constants from %1").arg(filename)); logError(QString("Failed to read movement type constants from %1").arg(filename));
return false; return false;
} }
@ -2211,12 +2182,12 @@ bool Project::readInitialFacingDirections() {
} }
bool Project::readMapTypes() { bool Project::readMapTypes() {
mapTypes->clear(); mapTypes.clear();
QStringList prefixes = (QStringList() << "\\bMAP_TYPE_"); QStringList prefixes("\\bMAP_TYPE_");
QString filename = "include/constants/map_types.h"; QString filename = "include/constants/map_types.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, mapTypes); parser.readCDefinesSorted(filename, prefixes, &mapTypes);
if (mapTypes->isEmpty()) { if (mapTypes.isEmpty()) {
logError(QString("Failed to read map type constants from %1").arg(filename)); logError(QString("Failed to read map type constants from %1").arg(filename));
return false; return false;
} }
@ -2224,12 +2195,12 @@ bool Project::readMapTypes() {
} }
bool Project::readMapBattleScenes() { bool Project::readMapBattleScenes() {
mapBattleScenes->clear(); mapBattleScenes.clear();
QStringList prefixes = (QStringList() << "\\bMAP_BATTLE_SCENE_"); QStringList prefixes("\\bMAP_BATTLE_SCENE_");
QString filename = "include/constants/map_types.h"; QString filename = "include/constants/map_types.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted("include/constants/map_types.h", prefixes, mapBattleScenes); parser.readCDefinesSorted("include/constants/map_types.h", prefixes, &mapBattleScenes);
if (mapBattleScenes->isEmpty()) { if (mapBattleScenes.isEmpty()) {
logError(QString("Failed to read map battle scene constants from %1").arg(filename)); logError(QString("Failed to read map battle scene constants from %1").arg(filename));
return false; return false;
} }
@ -2237,12 +2208,12 @@ bool Project::readMapBattleScenes() {
} }
bool Project::readWeatherNames() { bool Project::readWeatherNames() {
weatherNames->clear(); weatherNames.clear();
QStringList prefixes = (QStringList() << "\\bWEATHER_"); QStringList prefixes("\\bWEATHER_");
QString filename = "include/constants/weather.h"; QString filename = "include/constants/weather.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, weatherNames); parser.readCDefinesSorted(filename, prefixes, &weatherNames);
if (weatherNames->isEmpty()) { if (weatherNames.isEmpty()) {
logError(QString("Failed to read weather constants from %1").arg(filename)); logError(QString("Failed to read weather constants from %1").arg(filename));
return false; return false;
} }
@ -2252,12 +2223,12 @@ bool Project::readWeatherNames() {
bool Project::readCoordEventWeatherNames() { bool Project::readCoordEventWeatherNames() {
if (!projectConfig.getEventWeatherTriggerEnabled()) return true; if (!projectConfig.getEventWeatherTriggerEnabled()) return true;
coordEventWeatherNames->clear(); coordEventWeatherNames.clear();
QStringList prefixes = (QStringList() << "\\bCOORD_EVENT_WEATHER_"); QStringList prefixes("\\bCOORD_EVENT_WEATHER_");
QString filename = "include/constants/weather.h"; QString filename = "include/constants/weather.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, coordEventWeatherNames); parser.readCDefinesSorted(filename, prefixes, &coordEventWeatherNames);
if (coordEventWeatherNames->isEmpty()) { if (coordEventWeatherNames.isEmpty()) {
logError(QString("Failed to read coord event weather constants from %1").arg(filename)); logError(QString("Failed to read coord event weather constants from %1").arg(filename));
return false; return false;
} }
@ -2267,12 +2238,12 @@ bool Project::readCoordEventWeatherNames() {
bool Project::readSecretBaseIds() { bool Project::readSecretBaseIds() {
if (!projectConfig.getEventSecretBaseEnabled()) return true; if (!projectConfig.getEventSecretBaseEnabled()) return true;
secretBaseIds->clear(); secretBaseIds.clear();
QStringList prefixes = (QStringList() << "\\bSECRET_BASE_[A-Za-z0-9_]*_[0-9]+"); QStringList prefixes("\\bSECRET_BASE_[A-Za-z0-9_]*_[0-9]+");
QString filename = "include/constants/secret_bases.h"; QString filename = "include/constants/secret_bases.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, secretBaseIds); parser.readCDefinesSorted(filename, prefixes, &secretBaseIds);
if (secretBaseIds->isEmpty()) { if (secretBaseIds.isEmpty()) {
logError(QString("Failed to read secret base id constants from %1").arg(filename)); logError(QString("Failed to read secret base id constants from %1").arg(filename));
return false; return false;
} }
@ -2280,12 +2251,12 @@ bool Project::readSecretBaseIds() {
} }
bool Project::readBgEventFacingDirections() { bool Project::readBgEventFacingDirections() {
bgEventFacingDirections->clear(); bgEventFacingDirections.clear();
QStringList prefixes = (QStringList() << "\\bBG_EVENT_PLAYER_FACING_"); QStringList prefixes("\\bBG_EVENT_PLAYER_FACING_");
QString filename = "include/constants/event_bg.h"; QString filename = "include/constants/event_bg.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, bgEventFacingDirections); parser.readCDefinesSorted(filename, prefixes, &bgEventFacingDirections);
if (bgEventFacingDirections->isEmpty()) { if (bgEventFacingDirections.isEmpty()) {
logError(QString("Failed to read bg event facing direction constants from %1").arg(filename)); logError(QString("Failed to read bg event facing direction constants from %1").arg(filename));
return false; return false;
} }
@ -2293,12 +2264,12 @@ bool Project::readBgEventFacingDirections() {
} }
bool Project::readTrainerTypes() { bool Project::readTrainerTypes() {
trainerTypes->clear(); trainerTypes.clear();
QStringList prefixes = (QStringList() << "\\bTRAINER_TYPE_"); QStringList prefixes("\\bTRAINER_TYPE_");
QString filename = "include/constants/trainer_types.h"; QString filename = "include/constants/trainer_types.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
parser.readCDefinesSorted(filename, prefixes, trainerTypes); parser.readCDefinesSorted(filename, prefixes, &trainerTypes);
if (trainerTypes->isEmpty()) { if (trainerTypes.isEmpty()) {
logError(QString("Failed to read trainer type constants from %1").arg(filename)); logError(QString("Failed to read trainer type constants from %1").arg(filename));
return false; return false;
} }
@ -2309,7 +2280,7 @@ bool Project::readMetatileBehaviors() {
this->metatileBehaviorMap.clear(); this->metatileBehaviorMap.clear();
this->metatileBehaviorMapInverse.clear(); this->metatileBehaviorMapInverse.clear();
QStringList prefixes = (QStringList() << "\\bMB_"); QStringList prefixes("\\bMB_");
QString filename = "include/constants/metatile_behaviors.h"; QString filename = "include/constants/metatile_behaviors.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
this->metatileBehaviorMap = parser.readCDefines(filename, prefixes); this->metatileBehaviorMap = parser.readCDefines(filename, prefixes);
@ -2325,8 +2296,7 @@ bool Project::readMetatileBehaviors() {
} }
QStringList Project::getSongNames() { QStringList Project::getSongNames() {
QStringList songDefinePrefixes; QStringList songDefinePrefixes{ "\\bSE_", "\\bMUS_" };
songDefinePrefixes << "\\bSE_" << "\\bMUS_";
QString filename = "include/constants/songs.h"; QString filename = "include/constants/songs.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
QMap<QString, int> songDefines = parser.readCDefines(filename, songDefinePrefixes); QMap<QString, int> songDefines = parser.readCDefines(filename, songDefinePrefixes);
@ -2337,8 +2307,7 @@ QStringList Project::getSongNames() {
} }
QMap<QString, int> Project::getEventObjGfxConstants() { QMap<QString, int> Project::getEventObjGfxConstants() {
QStringList eventObjGfxPrefixes; QStringList eventObjGfxPrefixes("\\bOBJ_EVENT_GFX_");
eventObjGfxPrefixes << "\\bOBJ_EVENT_GFX_";
QString filename = "include/constants/event_objects.h"; QString filename = "include/constants/event_objects.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
@ -2352,15 +2321,14 @@ bool Project::readMiscellaneousConstants() {
if (projectConfig.getEncounterJsonActive()) { if (projectConfig.getEncounterJsonActive()) {
QString filename = "include/constants/pokemon.h"; QString filename = "include/constants/pokemon.h";
fileWatcher.addPath(root + "/" + filename); 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("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); miscConstants.insert("min_level_define", pokemonDefines.value("MIN_LEVEL") < pokemonDefines.value("MAX_LEVEL") ? pokemonDefines.value("MIN_LEVEL") : 1);
} }
QString filename = "include/constants/global.h"; QString filename = "include/constants/global.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
QStringList definePrefixes; QStringList definePrefixes("\\bOBJECT_");
definePrefixes << "\\bOBJECT_";
QMap<QString, int> defines = parser.readCDefines(filename, definePrefixes); QMap<QString, int> defines = parser.readCDefines(filename, definePrefixes);
auto it = defines.find("OBJECT_EVENT_TEMPLATES_COUNT"); 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->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()); ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values());
if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setCurrentText(mapSec); if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setCurrentText(mapSec);
ui->checkBox_NewMap_Show_Location->setChecked(true); 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->location = this->ui->comboBox_NewMap_Location->currentText();
newMap->song = this->project->defaultSong; newMap->song = this->project->defaultSong;
newMap->requiresFlash = "0"; 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->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) { if (this->existingLayout) {
layout = this->project->mapLayouts.value(this->layoutId); layout = this->project->mapLayouts.value(this->layoutId);