diff --git a/CHANGELOG.md b/CHANGELOG.md index efb5c7a3..c676da1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project somewhat adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). The MAJOR version number is bumped when there are **"Breaking Changes"** in the pret projects. For more on this, see [the manual page on breaking changes](https://huderlem.github.io/porymap/manual/breaking-changes.html). ## [Unreleased] +### Added +- Support `INCGFX` in addition to `INCBIN`. The regular expression for these statements is now available under `Project Settings`. + ### Fixed - Fix degraded image quality in exported timelapse gifs. - Fix custom top-level data in the `encounters` object of `wild_encounters.json` being discarded if no `fields` data is present. diff --git a/include/config.h b/include/config.h index 8e363914..539c5f3d 100644 --- a/include/config.h +++ b/include/config.h @@ -244,6 +244,7 @@ enum ProjectIdentifier { regex_music, regex_encounter_types, regex_terrain_types, + regex_incbin, pals_output_extension, tiles_output_extension, }; diff --git a/include/core/parseutil.h b/include/core/parseutil.h index 949f7ddc..471bdd8c 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -5,6 +5,7 @@ #include "log.h" #include "orderedjson.h" #include "orderedmap.h" +#include "regex.h" #include #include @@ -73,6 +74,8 @@ public: bool tryParseJsonFile(QJsonDocument *out, const QString &filepath, QString *error = nullptr); bool tryParseOrderedJsonFile(poryjson::Json::object *out, const QString &filepath, QString *error = nullptr); + void setIncbinPattern(const QString& pattern); + static int getJsonLineNumber(const QString &filepath, const QString &searchText); // Returns the 1-indexed line number for the definition of scriptLabel in the scripts file at filePath. @@ -102,6 +105,10 @@ private: QHash fileCache; QHash errorMap; + QString incbinPattern = Regex::Pattern_INCBIN; + std::unique_ptr incbinRegex = nullptr; + std::unique_ptr incbinArrayRegex = nullptr; + // The maps of define names to values/expressions that are available while parsing C defines. // As the parser reads and evaluates more defines it will update these maps accordingly. QHash knownDefineValues; @@ -140,7 +147,6 @@ private: static const QRegularExpression re_poryScriptLabel; static const QRegularExpression re_globalPoryScriptLabel; static const QRegularExpression re_poryRawSection; - static const QString incbinRegexText; }; #endif // PARSEUTIL_H diff --git a/include/core/regex.h b/include/core/regex.h new file mode 100644 index 00000000..b9a25fa2 --- /dev/null +++ b/include/core/regex.h @@ -0,0 +1,9 @@ +#pragma once +#ifndef REGEX_H +#define REGEX_H + +namespace Regex { + constexpr auto Pattern_INCBIN = R"(INC(BIN|GFX)_\w+?\s*\(\s*\"(?[^\"]*)\"[^\)]*\))"; +}; + +#endif // REGEX_H diff --git a/src/config.cpp b/src/config.cpp index 9b5677ab..9264f99b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -5,6 +5,7 @@ #include "validator.h" #include "utility.h" #include "metatile.h" +#include "regex.h" #include #include #include @@ -133,6 +134,7 @@ const QMap> ProjectConfig::defaultIde {ProjectIdentifier::regex_music, {"regex_music", "\\b(SE|MUS)_"}}, {ProjectIdentifier::regex_encounter_types, {"regex_encounter_types", "\\bTILE_ENCOUNTER_"}}, {ProjectIdentifier::regex_terrain_types, {"regex_terrain_types", "\\bTILE_TERRAIN_"}}, + {ProjectIdentifier::regex_incbin, {"regex_incbin", Regex::Pattern_INCBIN}}, // Other {ProjectIdentifier::pals_output_extension, {"pals_output_extension", ".gbapal"}}, {ProjectIdentifier::tiles_output_extension, {"tiles_output_extension", ".4bpp.lz"}}, diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index 5eeb8333..a1c3e69d 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -16,7 +16,6 @@ const QRegularExpression ParseUtil::re_globalIncScriptLabel("\\b(?