Fix bug when saving heal locations for maps with multiple heal locations

This commit is contained in:
Marcus Huderle 2018-09-12 17:44:37 -05:00
parent 23efdc2bea
commit 2a00e8aee9
2 changed files with 9 additions and 19 deletions

View file

@ -514,36 +514,27 @@ void Project::saveHealLocationStruct(Map *map) {
QMap<QString, int> flyableMapsDupes; QMap<QString, int> flyableMapsDupes;
QSet<QString> flyableMapsUnique; QSet<QString> flyableMapsUnique;
// erase old location from flyableMaps list
// set flyableMapsDupes and flyableMapsUnique // set flyableMapsDupes and flyableMapsUnique
for (auto it = flyableMaps->begin(); it != flyableMaps->end(); it++) { for (auto it = flyableMaps.begin(); it != flyableMaps.end(); it++) {
HealLocation loc = *it; HealLocation loc = *it;
QString xname = loc.name; QString xname = loc.name;
if (flyableMapsUnique.contains(xname)) { if (flyableMapsUnique.contains(xname)) {
flyableMapsDupes[xname] = 1; flyableMapsDupes[xname] = 1;
} }
if (xname == QString(mapNamesToMapConstants->value(map->name)).remove(0,4)) { flyableMapsUnique.insert(xname);
it = flyableMaps->erase(it) - 1;
}
else {
flyableMapsUnique.insert(xname);
}
} }
// set new location in flyableMapsList // set new location in flyableMapsList
if (map->events["heal_event_group"].length() > 0) { if (map->events["heal_event_group"].length() > 0) {
QList<HealLocation>* flymaps = flyableMaps;
for (Event *heal : map->events["heal_event_group"]) { for (Event *heal : map->events["heal_event_group"]) {
HealLocation hl = heal->buildHealLocation(); HealLocation hl = heal->buildHealLocation();
flymaps->insert(hl.index - 1, hl); flyableMaps[hl.index - 1] = hl;
} }
flyableMaps = flymaps;
} }
int i = 1; int i = 1;
for (auto map_in : *flyableMaps) { for (auto map_in : flyableMaps) {
data_text += QString(" {MAP_GROUP(%1), MAP_NUM(%1), %2, %3},\n") data_text += QString(" {MAP_GROUP(%1), MAP_NUM(%1), %2, %3},\n")
.arg(map_in.name) .arg(map_in.name)
.arg(map_in.x) .arg(map_in.x)
@ -1026,7 +1017,8 @@ void Project::readMapGroups() {
QString hltext = readTextFile(root + QString("/src/data/heal_locations.h")); QString hltext = readTextFile(root + QString("/src/data/heal_locations.h"));
QList<HealLocation>* hl = parser->parseHealLocs(hltext); QList<HealLocation>* hl = parser->parseHealLocs(hltext);
flyableMaps = hl; flyableMaps = *hl;
delete hl;
} }
Map* Project::addNewMapToGroup(QString mapName, int groupNum) { Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
@ -1412,12 +1404,10 @@ void Project::saveMapEvents(Map *map) {
// save heal event changes // save heal event changes
if (map->events["heal_event_group"].length() > 0) { if (map->events["heal_event_group"].length() > 0) {
QList<HealLocation>* flymaps = flyableMaps;
for (Event *heal : map->events["heal_event_group"]) { for (Event *heal : map->events["heal_event_group"]) {
HealLocation hl = heal->buildHealLocation(); HealLocation hl = heal->buildHealLocation();
flymaps->append(hl); flyableMaps[hl.index - 1] = hl;
} }
flyableMaps = flymaps;
} }
saveHealLocationStruct(map); saveHealLocationStruct(map);
} }
@ -1492,7 +1482,7 @@ void Project::readMapEvents(Map *map) {
map->events["heal_event_group"].clear(); map->events["heal_event_group"].clear();
for (auto it = flyableMaps->begin(); it != flyableMaps->end(); it++) { for (auto it = flyableMaps.begin(); it != flyableMaps.end(); it++) {
HealLocation loc = *it; HealLocation loc = *it;

View file

@ -18,7 +18,7 @@ public:
QMap<QString, int> *map_groups; QMap<QString, int> *map_groups;
QList<QStringList> groupedMapNames; QList<QStringList> groupedMapNames;
QStringList *mapNames = NULL; QStringList *mapNames = NULL;
QList<HealLocation> *flyableMaps = NULL; // can't be a QMap because duplicates QList<HealLocation> flyableMaps;
QMap<QString, QString>* mapConstantsToMapNames; QMap<QString, QString>* mapConstantsToMapNames;
QMap<QString, QString>* mapNamesToMapConstants; QMap<QString, QString>* mapNamesToMapConstants;
QList<QString> mapLayoutsTable; QList<QString> mapLayoutsTable;