From ed273b9ca0e6f00b7a77463dff13302ede424e8a Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 21 Apr 2025 20:16:59 -0400 Subject: [PATCH 01/25] Add functionality for global constants --- include/config.h | 2 ++ include/core/parseutil.h | 6 ++++- include/project.h | 3 ++- src/core/parseutil.cpp | 56 ++++++++++++++++++++++++---------------- src/mainwindow.cpp | 2 +- src/project.cpp | 19 +++++++++++--- 6 files changed, 60 insertions(+), 28 deletions(-) diff --git a/include/config.h b/include/config.h index 67a8b507..4f1aeada 100644 --- a/include/config.h +++ b/include/config.h @@ -345,6 +345,7 @@ public: this->unusedTileCovered = 0x0000; this->unusedTileSplit = 0x0000; this->maxEventsPerGroup = 255; + this->globalConstantsFilepaths.clear(); this->identifiers.clear(); this->readKeys.clear(); } @@ -417,6 +418,7 @@ public: QMargins playerViewDistance; QList warpBehaviors; int maxEventsPerGroup; + QStringList globalConstantsFilepaths; protected: virtual QString getConfigFilepath() override; diff --git a/include/core/parseutil.h b/include/core/parseutil.h index e02d0504..58b5d0ab 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -43,7 +43,7 @@ class ParseUtil { public: ParseUtil(); - void set_root(const QString &dir); + void setRoot(const QString &dir) { this->root = dir; } static QString readTextFile(const QString &path, QString *error = nullptr); bool cacheFile(const QString &path, QString *error = nullptr); void clearFileCache() { this->fileCache.clear(); } @@ -58,6 +58,8 @@ public: QMap readCDefinesByRegex(const QString &filename, const QSet ®exList, QString *error = nullptr); QMap readCDefinesByName(const QString &filename, const QSet &names, QString *error = nullptr); QStringList readCDefineNames(const QString &filename, const QSet ®exList, QString *error = nullptr); + void loadGlobalCDefines(const QString &filename, QString *error = nullptr); + void resetGlobalCDefines(); OrderedMap> readCStructs(const QString &, const QString & = "", const QHash& = {}); QList getLabelMacros(const QList&, const QString&); QStringList getLabelValues(const QList&, const QString&); @@ -90,6 +92,8 @@ private: QString curDefine; QHash fileCache; QHash errorMap; + QMap globalDefineValues; + QMap globalDefineExpressions; int evaluateDefine(const QString&, const QString &, QMap*, QMap*); QList tokenizeExpression(QString, QMap*, QMap*); QList generatePostfix(const QList &tokens); diff --git a/include/project.h b/include/project.h index 1031640b..2d2b5fd1 100644 --- a/include/project.h +++ b/include/project.h @@ -76,7 +76,7 @@ public: int maxEncounterRate; bool wildEncountersLoaded; - void set_root(QString); + void setRoot(const QString&); void clearMaps(); void clearTilesetCache(); @@ -203,6 +203,7 @@ public: bool readEventGraphics(); bool readFieldmapProperties(); bool readFieldmapMasks(); + bool readGlobalConstants(); QMap> readObjEventGfxInfo(); QPixmap getEventPixmap(const QString &gfxName, const QString &movementName); diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index da2a8f8e..30146284 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -15,26 +15,8 @@ const QRegularExpression ParseUtil::re_poryScriptLabel("\\b(script)(\\((global|l const QRegularExpression ParseUtil::re_globalPoryScriptLabel("\\b(script)(\\((global)\\))?\\s*\\b(?