Fix new maps parsing scripts file too early

This commit is contained in:
GriffinR 2024-01-29 14:07:13 -05:00
parent d74affe0b9
commit ae341d144e
4 changed files with 12 additions and 5 deletions

View file

@ -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 scrolling to the wrong selection when zoomed.
- Fix the Tileset Editor selectors getting extra white space when changing tilesets. - Fix the Tileset Editor selectors getting extra white space when changing tilesets.
- Fix a crash when adding disabled events with the Pencil tool. - 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 ## [5.3.0] - 2024-01-15
### Added ### Added

View file

@ -60,6 +60,7 @@ public:
bool hasUnsavedDataChanges = false; bool hasUnsavedDataChanges = false;
bool needsLayoutDir = true; bool needsLayoutDir = true;
bool needsHealLocation = false; bool needsHealLocation = false;
bool scriptsLoaded = false;
QImage collision_image; QImage collision_image;
QPixmap collision_pixmap; QPixmap collision_pixmap;
QImage image; QImage image;
@ -94,7 +95,7 @@ public:
void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
QList<Event *> getAllEvents() const; QList<Event *> getAllEvents() const;
QStringList getScriptLabels(Event::Group group = Event::Group::None) const; QStringList getScriptLabels(Event::Group group = Event::Group::None);
void removeEvent(Event *); void removeEvent(Event *);
void addEvent(Event *); void addEvent(Event *);
QPixmap renderConnection(MapConnection, MapLayout *); QPixmap renderConnection(MapConnection, MapLayout *);

View file

@ -27,7 +27,7 @@ Map::~Map() {
void Map::setName(QString mapName) { void Map::setName(QString mapName) {
name = mapName; name = mapName;
constantName = mapConstantFromName(mapName); constantName = mapConstantFromName(mapName);
scriptsFileLabels = ParseUtil::getGlobalScriptLabels(this->getScriptsFilePath()); scriptsLoaded = false;
} }
QString Map::mapConstantFromName(QString mapName, bool includePrefix) { QString Map::mapConstantFromName(QString mapName, bool includePrefix) {
@ -463,7 +463,12 @@ QList<Event *> Map::getAllEvents() const {
return all_events; 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; QStringList scriptLabels;
// Get script labels currently in-use by the map's events // 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. // Add scripts from map's scripts file, and empty names.
scriptLabels.append(scriptsFileLabels); scriptLabels.append(this->scriptsFileLabels);
scriptLabels.sort(Qt::CaseInsensitive); scriptLabels.sort(Qt::CaseInsensitive);
scriptLabels.prepend("0x0"); scriptLabels.prepend("0x0");
scriptLabels.prepend("NULL"); scriptLabels.prepend("NULL");

View file

@ -171,7 +171,7 @@ void EventFrame::setActive(bool active) {
void EventFrame::populateScriptDropdown(NoScrollComboBox * combo, Project * project) { 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. // The script dropdown is populated with scripts used by the map's events and from its scripts file.
if (this->event->getMap()) 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. // The dropdown's autocomplete has all script labels across the full project.
auto completer = new QCompleter(project->globalScriptLabels, combo); auto completer = new QCompleter(project->globalScriptLabels, combo);