From 6648fa33b1dc46cb9d4cd73502a7c1d277d86713 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 9 Jun 2025 12:02:56 -0400 Subject: [PATCH] Fix scripts.inc file watches accumulating --- include/core/map.h | 3 +-- src/core/map.cpp | 8 ++++---- src/editor.cpp | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/core/map.h b/include/core/map.h index 36ceed82..d5e28075 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -87,6 +87,7 @@ public: QStringList getScriptLabels(Event::Group group = Event::Group::None); QString getScriptsFilepath() const; void openScript(const QString &label); + void invalidateScripts(); static QString getJsonFilepath(const QString &mapName); QString getJsonFilepath() const { return getJsonFilepath(m_name); } @@ -144,8 +145,6 @@ private: QPointer m_editHistory; QPointer m_scriptFileWatcher; - void invalidateScripts(); - signals: void modified(); void scriptsModified(); diff --git a/src/core/map.cpp b/src/core/map.cpp index c35f07bd..6ced8d4c 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -143,6 +143,7 @@ void Map::setSharedScriptsMap(const QString &sharedScriptsMap) { void Map::invalidateScripts() { m_scriptsLoaded = false; + m_scriptFileWatcher->removePaths(m_scriptFileWatcher->files()); emit scriptsModified(); } @@ -151,7 +152,6 @@ QStringList Map::getScriptLabels(Event::Group group) { const QString scriptsFilepath = getScriptsFilepath(); QString error; m_scriptLabels = ParseUtil::getGlobalScriptLabels(scriptsFilepath, &error); - m_scriptsLoaded = true; if (!error.isEmpty() && !m_loggedScriptsFileError) { logWarn(QString("Failed to read scripts file '%1' for %2: %3") @@ -161,14 +161,14 @@ QStringList Map::getScriptLabels(Event::Group group) { m_loggedScriptsFileError = true; } - // Track the scripts file for changes. Path may have changed, so stop tracking old files. - m_scriptFileWatcher->removePaths(m_scriptFileWatcher->files()); - if (!m_scriptFileWatcher->addPath(scriptsFilepath) && !m_loggedScriptsFileError) { + if (!m_scriptFileWatcher->files().contains(scriptsFilepath) && !m_scriptFileWatcher->addPath(scriptsFilepath) && !m_loggedScriptsFileError) { logWarn(QString("Failed to add scripts file '%1' to file watcher for %2.") .arg(Util::stripPrefix(scriptsFilepath, projectConfig.projectDir() + "/")) .arg(m_name)); m_loggedScriptsFileError = true; } + + m_scriptsLoaded = true; } QStringList scriptLabels = m_scriptLabels; diff --git a/src/editor.cpp b/src/editor.cpp index 3b4ea948..5fb3ef80 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1245,8 +1245,9 @@ void Editor::unsetMap() { this->map->pruneEditHistory(); this->map->disconnect(this); - // Don't let the file watcher accumulate map.json files. + // Don't let the file watcher accumulate map.json / scripts.inc files. this->project->stopFileWatch(this->map->getJsonFilepath()); + this->map->invalidateScripts(); } clearMapEvents(); clearMapConnections();