From ae341d144e10dfc5a6972c2bb76e3eee1a21e869 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 29 Jan 2024 14:07:13 -0500 Subject: [PATCH] Fix new maps parsing scripts file too early --- CHANGELOG.md | 1 + include/core/map.h | 3 ++- src/core/map.cpp | 11 ++++++++--- src/ui/eventframes.cpp | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d1b6e6b..9bb4a29c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Fix the Tileset Editor selectors scrolling to the wrong selection when zoomed. - Fix the Tileset Editor selectors getting extra white space when changing tilesets. - Fix a crash when adding disabled events with the Pencil tool. +- Fix error log about failing to find the scripts file when a new map is created. ## [5.3.0] - 2024-01-15 ### Added diff --git a/include/core/map.h b/include/core/map.h index c4268ef9..c214fbb7 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -60,6 +60,7 @@ public: bool hasUnsavedDataChanges = false; bool needsLayoutDir = true; bool needsHealLocation = false; + bool scriptsLoaded = false; QImage collision_image; QPixmap collision_pixmap; QImage image; @@ -94,7 +95,7 @@ public: void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); QList getAllEvents() const; - QStringList getScriptLabels(Event::Group group = Event::Group::None) const; + QStringList getScriptLabels(Event::Group group = Event::Group::None); void removeEvent(Event *); void addEvent(Event *); QPixmap renderConnection(MapConnection, MapLayout *); diff --git a/src/core/map.cpp b/src/core/map.cpp index 62357445..a0ecf404 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -27,7 +27,7 @@ Map::~Map() { void Map::setName(QString mapName) { name = mapName; constantName = mapConstantFromName(mapName); - scriptsFileLabels = ParseUtil::getGlobalScriptLabels(this->getScriptsFilePath()); + scriptsLoaded = false; } QString Map::mapConstantFromName(QString mapName, bool includePrefix) { @@ -463,7 +463,12 @@ QList Map::getAllEvents() const { return all_events; } -QStringList Map::getScriptLabels(Event::Group group) const { +QStringList Map::getScriptLabels(Event::Group group) { + if (!this->scriptsLoaded) { + this->scriptsFileLabels = ParseUtil::getGlobalScriptLabels(this->getScriptsFilePath()); + this->scriptsLoaded = true; + } + QStringList scriptLabels; // Get script labels currently in-use by the map's events @@ -482,7 +487,7 @@ QStringList Map::getScriptLabels(Event::Group group) const { } // Add scripts from map's scripts file, and empty names. - scriptLabels.append(scriptsFileLabels); + scriptLabels.append(this->scriptsFileLabels); scriptLabels.sort(Qt::CaseInsensitive); scriptLabels.prepend("0x0"); scriptLabels.prepend("NULL"); diff --git a/src/ui/eventframes.cpp b/src/ui/eventframes.cpp index 26becf97..7537588f 100644 --- a/src/ui/eventframes.cpp +++ b/src/ui/eventframes.cpp @@ -171,7 +171,7 @@ void EventFrame::setActive(bool active) { void EventFrame::populateScriptDropdown(NoScrollComboBox * combo, Project * project) { // The script dropdown is populated with scripts used by the map's events and from its scripts file. if (this->event->getMap()) - combo->addItems(this->event->getMap()->getScriptLabels()); + combo->addItems(this->event->getMap()->getScriptLabels(this->event->getEventGroup())); // The dropdown's autocomplete has all script labels across the full project. auto completer = new QCompleter(project->globalScriptLabels, combo);