mirror of
https://github.com/huderlem/porymap.git
synced 2026-04-24 23:07:52 -05:00
Parser filter lists to QSet
This commit is contained in:
parent
75b8b2c16c
commit
ded9f724dc
|
|
@ -54,9 +54,9 @@ public:
|
|||
QString readCIncbin(const QString &text, const QString &label);
|
||||
QMap<QString, QString> readCIncbinMulti(const QString &filepath);
|
||||
QStringList readCIncbinArray(const QString &filename, const QString &label);
|
||||
QMap<QString, int> readCDefinesByRegex(const QString &filename, const QStringList ®exList, QString *error = nullptr);
|
||||
QMap<QString, int> readCDefinesByName(const QString &filename, const QStringList &names, QString *error = nullptr);
|
||||
QStringList readCDefineNames(const QString &filename, const QStringList ®exList, QString *error = nullptr);
|
||||
QMap<QString, int> readCDefinesByRegex(const QString &filename, const QSet<QString> ®exList, QString *error = nullptr);
|
||||
QMap<QString, int> readCDefinesByName(const QString &filename, const QSet<QString> &names, QString *error = nullptr);
|
||||
QStringList readCDefineNames(const QString &filename, const QSet<QString> ®exList, QString *error = nullptr);
|
||||
tsl::ordered_map<QString, QHash<QString, QString>> readCStructs(const QString &, const QString & = "", const QHash<int, QString>& = {});
|
||||
QList<QStringList> getLabelMacros(const QList<QStringList>&, const QString&);
|
||||
QStringList getLabelValues(const QList<QStringList>&, const QString&);
|
||||
|
|
@ -101,10 +101,10 @@ private:
|
|||
QMap<QString,QString> expressions; // Map of all define names encountered to their expressions
|
||||
QStringList filteredNames; // List of define names that matched the search text, in the order that they were encountered
|
||||
};
|
||||
ParsedDefines readCDefines(const QString &filename, const QStringList &filterList, bool useRegex, QString *error);
|
||||
QMap<QString, int> evaluateCDefines(const QString &filename, const QStringList &filterList, bool useRegex, QString *error);
|
||||
bool defineNameMatchesFilter(const QString &name, const QStringList &filterList) const;
|
||||
bool defineNameMatchesFilter(const QString &name, const QList<QRegularExpression> &filterList) const;
|
||||
ParsedDefines readCDefines(const QString &filename, const QSet<QString> &filterList, bool useRegex, QString *error);
|
||||
QMap<QString, int> evaluateCDefines(const QString &filename, const QSet<QString> &filterList, bool useRegex, QString *error);
|
||||
bool defineNameMatchesFilter(const QString &name, const QSet<QString> &filterList) const;
|
||||
bool defineNameMatchesFilter(const QString &name, const QSet<QRegularExpression> &filterList) const;
|
||||
|
||||
static const QRegularExpression re_incScriptLabel;
|
||||
static const QRegularExpression re_globalIncScriptLabel;
|
||||
|
|
|
|||
|
|
@ -368,11 +368,11 @@ QStringList ParseUtil::readCIncbinArray(const QString &filename, const QString &
|
|||
return paths;
|
||||
}
|
||||
|
||||
bool ParseUtil::defineNameMatchesFilter(const QString &name, const QStringList &filterList) const {
|
||||
bool ParseUtil::defineNameMatchesFilter(const QString &name, const QSet<QString> &filterList) const {
|
||||
return filterList.contains(name);
|
||||
}
|
||||
|
||||
bool ParseUtil::defineNameMatchesFilter(const QString &name, const QList<QRegularExpression> &filterList) const {
|
||||
bool ParseUtil::defineNameMatchesFilter(const QString &name, const QSet<QRegularExpression> &filterList) const {
|
||||
for (auto filter : filterList) {
|
||||
if (filter.match(name).hasMatch())
|
||||
return true;
|
||||
|
|
@ -380,7 +380,7 @@ bool ParseUtil::defineNameMatchesFilter(const QString &name, const QList<QRegula
|
|||
return false;
|
||||
}
|
||||
|
||||
ParseUtil::ParsedDefines ParseUtil::readCDefines(const QString &filename, const QStringList &filterList, bool useRegex, QString *error) {
|
||||
ParseUtil::ParsedDefines ParseUtil::readCDefines(const QString &filename, const QSet<QString> &filterList, bool useRegex, QString *error) {
|
||||
ParsedDefines result;
|
||||
this->file = filename;
|
||||
|
||||
|
|
@ -402,10 +402,10 @@ ParseUtil::ParsedDefines ParseUtil::readCDefines(const QString &filename, const
|
|||
return result;
|
||||
|
||||
// If necessary, construct regular expressions from filter list
|
||||
QList<QRegularExpression> filterList_Regex;
|
||||
QSet<QRegularExpression> filterList_Regex;
|
||||
if (useRegex) {
|
||||
for (auto filter : filterList) {
|
||||
filterList_Regex.append(QRegularExpression(filter));
|
||||
filterList_Regex.insert(QRegularExpression(filter));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -463,7 +463,7 @@ ParseUtil::ParsedDefines ParseUtil::readCDefines(const QString &filename, const
|
|||
}
|
||||
|
||||
// Read all the define names and their expressions in the specified file, then evaluate the ones matching the search text (and any they depend on).
|
||||
QMap<QString, int> ParseUtil::evaluateCDefines(const QString &filename, const QStringList &filterList, bool useRegex, QString *error) {
|
||||
QMap<QString, int> ParseUtil::evaluateCDefines(const QString &filename, const QSet<QString> &filterList, bool useRegex, QString *error) {
|
||||
ParsedDefines defines = readCDefines(filename, filterList, useRegex, error);
|
||||
|
||||
// Evaluate defines
|
||||
|
|
@ -483,19 +483,19 @@ QMap<QString, int> ParseUtil::evaluateCDefines(const QString &filename, const QS
|
|||
}
|
||||
|
||||
// Find and evaluate a specific set of defines with known names.
|
||||
QMap<QString, int> ParseUtil::readCDefinesByName(const QString &filename, const QStringList &names, QString *error) {
|
||||
QMap<QString, int> ParseUtil::readCDefinesByName(const QString &filename, const QSet<QString> &names, QString *error) {
|
||||
return evaluateCDefines(filename, names, false, error);
|
||||
}
|
||||
|
||||
// Find and evaluate an unknown list of defines with a known name pattern.
|
||||
QMap<QString, int> ParseUtil::readCDefinesByRegex(const QString &filename, const QStringList ®exList, QString *error) {
|
||||
QMap<QString, int> ParseUtil::readCDefinesByRegex(const QString &filename, const QSet<QString> ®exList, QString *error) {
|
||||
return evaluateCDefines(filename, regexList, true, error);
|
||||
}
|
||||
|
||||
// Find an unknown list of defines with a known name pattern.
|
||||
// Similar to readCDefinesByRegex, but for cases where we only need to show a list of define names.
|
||||
// We can skip evaluating any expressions (and by extension skip reporting any errors from this process).
|
||||
QStringList ParseUtil::readCDefineNames(const QString &filename, const QStringList ®exList, QString *error) {
|
||||
QStringList ParseUtil::readCDefineNames(const QString &filename, const QSet<QString> ®exList, QString *error) {
|
||||
return readCDefines(filename, regexList, true, error).filteredNames;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1496,7 +1496,7 @@ bool Project::readTilesetMetatileLabels() {
|
|||
QString metatileLabelsFilename = projectConfig.getFilePath(ProjectFilePath::constants_metatile_labels);
|
||||
fileWatcher.addPath(root + "/" + metatileLabelsFilename);
|
||||
|
||||
const QStringList regexList = {QString("\\b%1").arg(projectConfig.getIdentifier(ProjectIdentifier::define_metatile_label_prefix))};
|
||||
const QSet<QString> regexList = {QString("\\b%1").arg(projectConfig.getIdentifier(ProjectIdentifier::define_metatile_label_prefix))};
|
||||
QMap<QString, int> defines = parser.readCDefinesByRegex(metatileLabelsFilename, regexList);
|
||||
|
||||
for (QString label : defines.keys()) {
|
||||
|
|
@ -2088,7 +2088,7 @@ bool Project::readFieldmapProperties() {
|
|||
const QString numPalsTotalName = projectConfig.getIdentifier(ProjectIdentifier::define_pals_total);
|
||||
const QString maxMapSizeName = projectConfig.getIdentifier(ProjectIdentifier::define_map_size);
|
||||
const QString numTilesPerMetatileName = projectConfig.getIdentifier(ProjectIdentifier::define_tiles_per_metatile);
|
||||
const QStringList names = {
|
||||
const QSet<QString> names = {
|
||||
numTilesPrimaryName,
|
||||
numTilesTotalName,
|
||||
numMetatilesPrimaryName,
|
||||
|
|
@ -2172,7 +2172,7 @@ bool Project::readFieldmapMasks() {
|
|||
const QString elevationMaskName = projectConfig.getIdentifier(ProjectIdentifier::define_mask_elevation);
|
||||
const QString behaviorMaskName = projectConfig.getIdentifier(ProjectIdentifier::define_mask_behavior);
|
||||
const QString layerTypeMaskName = projectConfig.getIdentifier(ProjectIdentifier::define_mask_layer);
|
||||
const QStringList searchNames = {
|
||||
const QSet<QString> searchNames = {
|
||||
metatileIdMaskName,
|
||||
collisionMaskName,
|
||||
elevationMaskName,
|
||||
|
|
@ -2429,44 +2429,40 @@ bool Project::readHealLocations() {
|
|||
}
|
||||
|
||||
bool Project::readItemNames() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_items)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_items);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->itemNames = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->itemNames = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_items)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read item constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Project::readFlagNames() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_flags)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_flags);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->flagNames = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->flagNames = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_flags)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read flag constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Project::readVarNames() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_vars)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_vars);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->varNames = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->varNames = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_vars)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read var constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Project::readMovementTypes() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_movement_types)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_obj_event_movement);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->movementTypes = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->movementTypes = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_movement_types)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read movement type constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
|
|
@ -2483,33 +2479,30 @@ bool Project::readInitialFacingDirections() {
|
|||
}
|
||||
|
||||
bool Project::readMapTypes() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_map_types)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_map_types);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->mapTypes = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->mapTypes = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_map_types)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read map type constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Project::readMapBattleScenes() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_battle_scenes)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_map_types);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->mapBattleScenes = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->mapBattleScenes = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_battle_scenes)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read map battle scene constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Project::readWeatherNames() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_weather)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_weather);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->weatherNames = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->weatherNames = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_weather)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read weather constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
|
|
@ -2519,11 +2512,10 @@ bool Project::readCoordEventWeatherNames() {
|
|||
if (!projectConfig.eventWeatherTriggerEnabled)
|
||||
return true;
|
||||
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_coord_event_weather)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_weather);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->coordEventWeatherNames = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->coordEventWeatherNames = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_coord_event_weather)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read coord event weather constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
|
|
@ -2533,33 +2525,30 @@ bool Project::readSecretBaseIds() {
|
|||
if (!projectConfig.eventSecretBaseEnabled)
|
||||
return true;
|
||||
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_secret_bases)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_secret_bases);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->secretBaseIds = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->secretBaseIds = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_secret_bases)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read secret base id constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Project::readBgEventFacingDirections() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_sign_facing_directions)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_event_bg);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->bgEventFacingDirections = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->bgEventFacingDirections = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_sign_facing_directions)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read bg event facing direction constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Project::readTrainerTypes() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_trainer_types)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_trainer_types);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->trainerTypes = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->trainerTypes = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_trainer_types)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read trainer type constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
|
|
@ -2569,11 +2558,10 @@ bool Project::readMetatileBehaviors() {
|
|||
this->metatileBehaviorMap.clear();
|
||||
this->metatileBehaviorMapInverse.clear();
|
||||
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_behaviors)};
|
||||
QString filename = projectConfig.getFilePath(ProjectFilePath::constants_metatile_behaviors);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
QMap<QString, int> defines = parser.readCDefinesByRegex(filename, regexList, &error);
|
||||
QMap<QString, int> defines = parser.readCDefinesByRegex(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_behaviors)}, &error);
|
||||
if (defines.isEmpty() && projectConfig.metatileBehaviorMask) {
|
||||
// Not having any metatile behavior names is ok (their values will be displayed instead)
|
||||
// but if the user's metatiles can have nonzero values then warn them, as they likely want names.
|
||||
|
|
@ -2592,11 +2580,10 @@ bool Project::readMetatileBehaviors() {
|
|||
}
|
||||
|
||||
bool Project::readSongNames() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_music)};
|
||||
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_songs);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->songNames = parser.readCDefineNames(filename, regexList, &error);
|
||||
this->songNames = parser.readCDefineNames(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_music)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read song names from '%1': %2").arg(filename).arg(error));
|
||||
|
||||
|
|
@ -2608,11 +2595,10 @@ bool Project::readSongNames() {
|
|||
}
|
||||
|
||||
bool Project::readObjEventGfxConstants() {
|
||||
const QStringList regexList = {projectConfig.getIdentifier(ProjectIdentifier::regex_obj_event_gfx)};
|
||||
QString filename = projectConfig.getFilePath(ProjectFilePath::constants_obj_events);
|
||||
fileWatcher.addPath(root + "/" + filename);
|
||||
QString error;
|
||||
this->gfxDefines = parser.readCDefinesByRegex(filename, regexList, &error);
|
||||
this->gfxDefines = parser.readCDefinesByRegex(filename, {projectConfig.getIdentifier(ProjectIdentifier::regex_obj_event_gfx)}, &error);
|
||||
if (!error.isEmpty())
|
||||
logWarn(QString("Failed to read object event graphics constants from '%1': %2").arg(filename).arg(error));
|
||||
return true;
|
||||
|
|
@ -2952,10 +2938,9 @@ bool Project::readSpeciesIconPaths() {
|
|||
|
||||
// Read species constants. If this fails we can get them from the icon table (but we shouldn't rely on it).
|
||||
const QString speciesPrefix = projectConfig.getIdentifier(ProjectIdentifier::define_species_prefix);
|
||||
const QStringList regexList = {QString("\\b%1").arg(speciesPrefix)};
|
||||
const QString constantsFilename = projectConfig.getFilePath(ProjectFilePath::constants_species);
|
||||
fileWatcher.addPath(root + "/" + constantsFilename);
|
||||
QStringList speciesNames = parser.readCDefineNames(constantsFilename, regexList);
|
||||
QStringList speciesNames = parser.readCDefineNames(constantsFilename, {QString("\\b%1").arg(speciesPrefix)});
|
||||
if (speciesNames.isEmpty())
|
||||
speciesNames = monIconNames.keys();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user