Stop repeated parsing of event_objects.h and songs.h

This commit is contained in:
GriffinR 2022-01-21 15:22:20 -05:00 committed by huderlem
parent b79ba466e0
commit 366fb5c8a8
6 changed files with 29 additions and 24 deletions

View file

@ -51,6 +51,8 @@ public:
QMap<QString, QString> mapSecToMapHoverName;
QMap<QString, int> mapSectionNameToValue;
QMap<int, QString> mapSectionValueToName;
QStringList gfxNames;
QStringList songNames;
QStringList itemNames;
QStringList flagNames;
QStringList varNames;
@ -151,7 +153,6 @@ public:
void saveTilesetPalettes(Tileset*);
QString defaultSong;
QStringList getSongNames();
QStringList getVisibilities();
QMap<QString, QStringList> getTilesetLabels();
bool readTilesetProperties();
@ -173,9 +174,10 @@ public:
bool readHealLocations();
bool readMiscellaneousConstants();
bool readEventScriptLabels();
bool readObjEventGfxConstants();
bool readSongNames();
void loadEventPixmaps(QList<Event*> objects);
QMap<QString, int> getEventObjGfxConstants();
QString fixPalettePath(QString path);
QString fixGraphicPath(QString path);

View file

@ -71,7 +71,7 @@ Event* Event::createNewObjectEvent(Project *project)
Event *event = new Event;
event->put("event_group_type", "object_event_group");
event->put("event_type", EventType::Object);
event->put("sprite", project->getEventObjGfxConstants().keys().first());
event->put("sprite", project->gfxNames.first());
event->put("movement_type", project->movementTypes.first());
if (projectConfig.getObjectEventInConnectionEnabled()) {
event->put("in_connection", false);

View file

@ -941,7 +941,9 @@ bool MainWindow::loadDataStructures() {
&& project->readMiscellaneousConstants()
&& project->readSpeciesIconPaths()
&& project->readWildMonData()
&& project->readEventScriptLabels();
&& project->readEventScriptLabels()
&& project->readObjEventGfxConstants()
&& project->readSongNames();
return success && loadProjectCombos();
}
@ -960,7 +962,7 @@ bool MainWindow::loadProjectCombos() {
const QSignalBlocker blocker7(ui->comboBox_Type);
ui->comboBox_Song->clear();
ui->comboBox_Song->addItems(project->getSongNames());
ui->comboBox_Song->addItems(project->songNames);
ui->comboBox_Location->clear();
ui->comboBox_Location->addItems(project->mapSectionValueToName.values());
@ -1954,8 +1956,6 @@ void MainWindow::updateSelectedObjects() {
delete button;
openScriptButtons.clear();
QMap<QString, int> event_obj_gfx_constants = editor->project->getEventObjGfxConstants();
QList<EventPropertiesFrame *> frames;
bool inConnectionEnabled = projectConfig.getObjectEventInConnectionEnabled();
@ -2043,7 +2043,7 @@ void MainWindow::updateSelectedObjects() {
if (event_type == EventType::Object) {
frame->ui->sprite->setVisible(true);
frame->ui->comboBox_sprite->addItems(event_obj_gfx_constants.keys());
frame->ui->comboBox_sprite->addItems(editor->project->gfxNames);
frame->ui->comboBox_sprite->setCurrentIndex(frame->ui->comboBox_sprite->findText(item->event->get("sprite")));
connect(frame->ui->comboBox_sprite, &QComboBox::currentTextChanged, item, &DraggablePixmapItem::set_sprite);
connect(frame->ui->comboBox_sprite, &QComboBox::currentTextChanged, this, &MainWindow::markMapEdited);

View file

@ -1078,8 +1078,7 @@ QString MainWindow::getSong() {
void MainWindow::setSong(QString song) {
if (!this->ui || !this->editor || !this->editor->project)
return;
QStringList songs = this->editor->project->getSongNames();
if (!songs.contains(song)) {
if (!this->editor->project->songNames.contains(song)) {
logError(QString("Unknown song '%1'").arg(song));
return;
}

View file

@ -2276,25 +2276,31 @@ bool Project::readMetatileBehaviors() {
return true;
}
QStringList Project::getSongNames() {
bool Project::readSongNames() {
QStringList songDefinePrefixes{ "\\bSE_", "\\bMUS_" };
QString filename = "include/constants/songs.h";
fileWatcher.addPath(root + "/" + filename);
QMap<QString, int> songDefines = parser.readCDefines(filename, songDefinePrefixes);
QStringList names = songDefines.keys();
this->defaultSong = names.value(0, "MUS_DUMMY");
return names;
this->songNames = songDefines.keys();
this->defaultSong = this->songNames.value(0, "MUS_DUMMY");
if (this->songNames.isEmpty()) {
logError(QString("Failed to read song names from %1.").arg(filename));
return false;
}
return true;
}
QMap<QString, int> Project::getEventObjGfxConstants() {
QStringList eventObjGfxPrefixes("\\bOBJ_EVENT_GFX_");
bool Project::readObjEventGfxConstants() {
QStringList objEventGfxPrefixes("\\bOBJ_EVENT_GFX_");
QString filename = "include/constants/event_objects.h";
fileWatcher.addPath(root + "/" + filename);
QMap<QString, int> constants = parser.readCDefines(filename, eventObjGfxPrefixes);
return constants;
QMap<QString, int> gfxDefines = parser.readCDefines(filename, objEventGfxPrefixes);
this->gfxNames = gfxDefines.keys();
if (this->gfxNames.isEmpty()) {
logError(QString("Failed to read object event graphics constants from %1.").arg(filename));
return false;
}
return true;
}
bool Project::readMiscellaneousConstants() {
@ -2424,8 +2430,6 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
return;
}
QMap<QString, int> constants = getEventObjGfxConstants();
fileWatcher.addPaths(QStringList() << root + "/" + "src/data/object_events/object_event_graphics_info_pointers.h"
<< root + "/" + "src/data/object_events/object_event_graphics_info.h"
<< root + "/" + "src/data/object_events/object_event_pic_tables.h"

View file

@ -116,7 +116,7 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
ui->comboBox_NewMap_Group->addItems(project->groupNames);
ui->comboBox_NewMap_Group->setCurrentText(project->groupNames.at(groupNum));
ui->comboBox_Song->addItems(project->getSongNames());
ui->comboBox_Song->addItems(project->songNames);
if (existingLayout) {
ui->spinBox_NewMap_Width->setValue(project->mapLayouts.value(layoutId)->width.toInt(nullptr, 0));