diff --git a/mainwindow.cpp b/mainwindow.cpp index 63a72522..bc01d7b3 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -504,7 +504,7 @@ void MainWindow::updateSelectedObjects() { field_labels["property"] = "Property"; field_labels["sight_radius"] = "Sight Radius"; field_labels["destination_warp"] = "Destination Warp"; - field_labels["destination_map"] = "Destination Map"; + field_labels["destination_map_name"] = "Destination Map"; field_labels["coord_unknown1"] = "Unknown 1"; field_labels["coord_unknown2"] = "Unknown 2"; field_labels["type"] = "Type"; @@ -542,7 +542,7 @@ void MainWindow::updateSelectedObjects() { } else if (event_type == "warp") { fields << "destination_warp"; - fields << "destination_map"; + fields << "destination_map_name"; } else if (event_type == "trap") { fields << "script_label"; @@ -568,7 +568,7 @@ void MainWindow::updateSelectedObjects() { combo->setEditable(true); QString value = item->event->get(key); - if (key == "destination_map") { + if (key == "destination_map_name") { if (!editor->project->mapNames->contains(value)) { combo->addItem(value); } diff --git a/project.cpp b/project.cpp index b0fae542..fc55bd0e 100755 --- a/project.cpp +++ b/project.cpp @@ -517,13 +517,15 @@ void Project::readMapGroups() { } else if (macro == ".4byte") { if (group != -1) { for (int j = 1; j < params.length(); j++) { + QString mapName = params.value(j); QStringList *list = groupedMaps->value(group); - list->append(params.value(j)); - maps->append(params.value(j)); + list->append(mapName); + maps->append(mapName); - // Build the mapping between map constants and map names. - QString mapConstant = Map::mapConstantFromName(params.value(j)); - mapConstantsToMapNames.insert(mapConstant, params.value(j)); + // Build the mapping and reverse mapping between map constants and map names. + QString mapConstant = Map::mapConstantFromName(mapName); + mapConstantsToMapNames.insert(mapConstant, mapName); + mapNamesToMapConstants.insert(mapName, mapConstant); } } } @@ -855,10 +857,16 @@ void Project::readMapEvents(Map *map) { warp->put("y", command.value(i++)); warp->put("elevation", command.value(i++)); warp->put("destination_warp", command.value(i++)); - warp->put("destination_map", command.value(i++)); - warp->put("event_type", "warp"); - map->events["warp"].append(warp); + // Ensure the warp destination map constant is valid before adding it to the warps. + QString mapConstant = command.value(i++); + if (mapConstantsToMapNames.contains(mapConstant)) { + warp->put("destination_map_name", mapConstantsToMapNames[mapConstant]); + warp->put("event_type", "warp"); + map->events["warp"].append(warp); + } else { + qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant); + } } } diff --git a/project.h b/project.h index b966a58f..ebf1ed28 100755 --- a/project.h +++ b/project.h @@ -16,6 +16,7 @@ public: QList *groupedMapNames = NULL; QStringList *mapNames = NULL; QMap mapConstantsToMapNames; + QMap mapNamesToMapConstants; QMap *map_cache; Map* loadMap(QString);