Bläddra i källkod

Fix warp map destinations (both loading and saving)

Marcus Huderle 6 år sedan
förälder
incheckning
0e268f9ede
3 ändrade filer med 20 tillägg och 11 borttagningar
  1. 3
    3
      mainwindow.cpp
  2. 16
    8
      project.cpp
  3. 1
    0
      project.h

+ 3
- 3
mainwindow.cpp Visa fil

@@ -504,7 +504,7 @@ void MainWindow::updateSelectedObjects() {
504 504
         field_labels["property"] = "Property";
505 505
         field_labels["sight_radius"] = "Sight Radius";
506 506
         field_labels["destination_warp"] = "Destination Warp";
507
-        field_labels["destination_map"] = "Destination Map";
507
+        field_labels["destination_map_name"] = "Destination Map";
508 508
         field_labels["coord_unknown1"] = "Unknown 1";
509 509
         field_labels["coord_unknown2"] = "Unknown 2";
510 510
         field_labels["type"] = "Type";
@@ -542,7 +542,7 @@ void MainWindow::updateSelectedObjects() {
542 542
         }
543 543
         else if (event_type == "warp") {
544 544
             fields << "destination_warp";
545
-            fields << "destination_map";
545
+            fields << "destination_map_name";
546 546
         }
547 547
         else if (event_type == "trap") {
548 548
             fields << "script_label";
@@ -568,7 +568,7 @@ void MainWindow::updateSelectedObjects() {
568 568
             combo->setEditable(true);
569 569
 
570 570
             QString value = item->event->get(key);
571
-            if (key == "destination_map") {
571
+            if (key == "destination_map_name") {
572 572
                 if (!editor->project->mapNames->contains(value)) {
573 573
                     combo->addItem(value);
574 574
                 }

+ 16
- 8
project.cpp Visa fil

@@ -517,13 +517,15 @@ void Project::readMapGroups() {
517 517
         } else if (macro == ".4byte") {
518 518
             if (group != -1) {
519 519
                 for (int j = 1; j < params.length(); j++) {
520
+                    QString mapName = params.value(j);
520 521
                     QStringList *list = groupedMaps->value(group);
521
-                    list->append(params.value(j));
522
-                    maps->append(params.value(j));
522
+                    list->append(mapName);
523
+                    maps->append(mapName);
523 524
 
524
-                    // Build the mapping between map constants and map names.
525
-                    QString mapConstant = Map::mapConstantFromName(params.value(j));
526
-                    mapConstantsToMapNames.insert(mapConstant, params.value(j));
525
+                    // Build the mapping and reverse mapping between map constants and map names.
526
+                    QString mapConstant = Map::mapConstantFromName(mapName);
527
+                    mapConstantsToMapNames.insert(mapConstant, mapName);
528
+                    mapNamesToMapConstants.insert(mapName, mapConstant);
527 529
                 }
528 530
             }
529 531
         }
@@ -855,10 +857,16 @@ void Project::readMapEvents(Map *map) {
855 857
             warp->put("y", command.value(i++));
856 858
             warp->put("elevation", command.value(i++));
857 859
             warp->put("destination_warp", command.value(i++));
858
-            warp->put("destination_map", command.value(i++));
859 860
 
860
-            warp->put("event_type", "warp");
861
-            map->events["warp"].append(warp);
861
+            // Ensure the warp destination map constant is valid before adding it to the warps.
862
+            QString mapConstant = command.value(i++);
863
+            if (mapConstantsToMapNames.contains(mapConstant)) {
864
+                warp->put("destination_map_name", mapConstantsToMapNames[mapConstant]);
865
+                warp->put("event_type", "warp");
866
+                map->events["warp"].append(warp);
867
+            } else {
868
+                qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant);
869
+            }
862 870
         }
863 871
     }
864 872
 

+ 1
- 0
project.h Visa fil

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