Fix warp map destinations (both loading and saving)

This commit is contained in:
Marcus Huderle 2018-02-12 09:20:18 -08:00
parent d7756865a9
commit 0e268f9ede
3 changed files with 20 additions and 11 deletions

View file

@ -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);
}

View file

@ -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++));
// 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);
}
}
}

View file

@ -16,6 +16,7 @@ public:
QList<QStringList*> *groupedMapNames = NULL;
QStringList *mapNames = NULL;
QMap<QString, QString> mapConstantsToMapNames;
QMap<QString, QString> mapNamesToMapConstants;
QMap<QString, Map*> *map_cache;
Map* loadMap(QString);