diff --git a/docsrc/manual/project-files.rst b/docsrc/manual/project-files.rst index 7d1d85c6..46554bb5 100644 --- a/docsrc/manual/project-files.rst +++ b/docsrc/manual/project-files.rst @@ -29,6 +29,7 @@ to a file, it probably is not a good idea to edit yourself unless otherwise note include/constants/global.h, yes, no, include/constants/map_groups.h, no, yes, include/constants/items.h, yes, no, + include/constants/opponents.h, yes, no, reads max trainers constant include/constants/flags.h, yes, no, include/constants/vars.h, yes, no, include/constants/weather.h, yes, no, diff --git a/include/core/parseutil.h b/include/core/parseutil.h index 38157c31..22abe367 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -47,8 +47,8 @@ public: QStringList readCArray(QString text, QString label); QMap readNamedIndexCArray(QString text, QString label); QString readCIncbin(QString text, QString label); - QMap readCDefines(QString filename, QStringList prefixes); - void readCDefinesSorted(QString, QStringList, QStringList*); + QMap readCDefines(QString filename, QStringList prefixes, QMap = QMap()); + void readCDefinesSorted(QString, QStringList, QStringList*, QMap = QMap()); QList* getLabelMacros(QList*, QString); QStringList* getLabelValues(QList*, QString); bool tryParseJsonFile(QJsonDocument *out, QString filepath); diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index 7bd64640..80a4cf6c 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -252,8 +252,7 @@ QString ParseUtil::readCIncbin(QString filename, QString label) { return path; } -QMap ParseUtil::readCDefines(QString filename, QStringList prefixes) { - QMap allDefines; +QMap ParseUtil::readCDefines(QString filename, QStringList prefixes, QMap allDefines) { QMap filteredDefines; file = filename; @@ -293,8 +292,8 @@ QMap ParseUtil::readCDefines(QString filename, QStringList prefixe return filteredDefines; } -void ParseUtil::readCDefinesSorted(QString filename, QStringList prefixes, QStringList* definesToSet) { - QMap defines = readCDefines(filename, prefixes); +void ParseUtil::readCDefinesSorted(QString filename, QStringList prefixes, QStringList* definesToSet, QMap knownDefines) { + QMap defines = readCDefines(filename, prefixes, knownDefines); // The defines should to be sorted by their underlying value, not alphabetically. // Reverse the map and read out the resulting keys in order. diff --git a/src/project.cpp b/src/project.cpp index cf8fdc6b..981e4304 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2171,13 +2171,19 @@ bool Project::readItemNames() { } bool Project::readFlagNames() { + // First read MAX_TRAINERS_COUNT, used to skip over trainer flags + // If this fails flags may simply be out of order, no need to check for success + QString opponentsFilename = "include/constants/opponents.h"; + fileWatcher.addPath(root + "/" + opponentsFilename); + QMap maxTrainers = parser.readCDefines(opponentsFilename, QStringList() << "MAX_"); + // Parse flags flagNames->clear(); QStringList prefixes = (QStringList() << "FLAG_"); - QString filename = "include/constants/flags.h"; - fileWatcher.addPath(root + "/" + filename); - parser.readCDefinesSorted(filename, prefixes, flagNames); + QString flagsFilename = "include/constants/flags.h"; + fileWatcher.addPath(root + "/" + flagsFilename); + parser.readCDefinesSorted(flagsFilename, prefixes, flagNames, maxTrainers); if (flagNames->isEmpty()) { - logError(QString("Failed to read flag constants from %1").arg(filename)); + logError(QString("Failed to read flag constants from %1").arg(flagsFilename)); return false; } return true;