Browse Source

Fix warp map destinations (both loading and saving)

Marcus Huderle 6 years ago
parent
commit
0e268f9ede
3 changed files with 20 additions and 11 deletions
  1. 3
    3
      mainwindow.cpp
  2. 16
    8
      project.cpp
  3. 1
    0
      project.h

+ 3
- 3
mainwindow.cpp View File

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

+ 16
- 8
project.cpp View File

517
         } else if (macro == ".4byte") {
517
         } else if (macro == ".4byte") {
518
             if (group != -1) {
518
             if (group != -1) {
519
                 for (int j = 1; j < params.length(); j++) {
519
                 for (int j = 1; j < params.length(); j++) {
520
+                    QString mapName = params.value(j);
520
                     QStringList *list = groupedMaps->value(group);
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
             warp->put("y", command.value(i++));
857
             warp->put("y", command.value(i++));
856
             warp->put("elevation", command.value(i++));
858
             warp->put("elevation", command.value(i++));
857
             warp->put("destination_warp", command.value(i++));
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 View File

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