Don't let map.json watches re-accumulate, fix trying to load scripts.inc before it exists

This commit is contained in:
GriffinR 2025-06-08 18:09:11 -04:00
parent ba1aa2b1ff
commit e6a4f88433
4 changed files with 14 additions and 4 deletions

View File

@ -225,6 +225,10 @@ public:
QString buildMetatileLabelsText(const QMap<QString, uint16_t> defines);
QString findMetatileLabelsTileset(QString label);
bool watchFile(const QString &filename);
bool watchFiles(const QStringList &filenames);
bool stopFileWatch(const QString &filename);
static QString getExistingFilepath(QString filepath);
void applyParsedLimits();
@ -324,8 +328,6 @@ private:
void setNewLayoutBlockdata(Layout *layout);
void setNewLayoutBorder(Layout *layout);
bool watchFile(const QString &filename);
bool watchFiles(const QStringList &filenames);
void ignoreWatchedFileTemporarily(const QString &filepath);
void ignoreWatchedFilesTemporarily(const QStringList &filepaths);
void recordFileChange(const QString &filepath);

View File

@ -147,7 +147,7 @@ void Map::invalidateScripts() {
}
QStringList Map::getScriptLabels(Event::Group group) {
if (!m_scriptsLoaded) {
if (!m_scriptsLoaded && m_isPersistedToFile) {
const QString scriptsFilepath = getScriptsFilepath();
QString error;
m_scriptLabels = ParseUtil::getGlobalScriptLabels(scriptsFilepath, &error);

View File

@ -1244,6 +1244,9 @@ void Editor::unsetMap() {
if (this->map) {
this->map->pruneEditHistory();
this->map->disconnect(this);
// Don't let the file watcher accumulate map.json files.
this->project->stopFileWatch(this->map->getJsonFilepath());
}
clearMapEvents();
clearMapConnections();
@ -1279,6 +1282,7 @@ bool Editor::setMap(QString map_name) {
connect(map, &Map::connectionAdded, this, &Editor::displayConnection);
connect(map, &Map::connectionRemoved, this, &Editor::removeConnectionPixmap);
updateEvents();
this->project->watchFile(map->getJsonFilepath());
return true;
}

View File

@ -406,7 +406,6 @@ bool Project::loadMapData(Map* map) {
logError(error);
return false;
}
watchFile(map->getJsonFilepath());
QJsonObject mapObj = mapDoc.object();
@ -770,6 +769,11 @@ bool Project::watchFiles(const QStringList &filenames) {
return success;
}
bool Project::stopFileWatch(const QString &filename) {
QString filepath = filename.startsWith(this->root) ? filename : QString("%1/%2").arg(this->root).arg(filename);
return this->fileWatcher.removePath(filepath);
}
void Project::ignoreWatchedFileTemporarily(const QString &filepath) {
// Ignore any file-change events for this filepath for the next 5 seconds.
this->modifiedFileTimestamps.insert(filepath, QDateTime::currentMSecsSinceEpoch() + 5000);