Parcourir la source

Only write out a map event label if there are actually events to write for its section. Otherwise, you end up writing invalid labels to file, such as '0x0'.

Marcus Huderle il y a 6 ans
Parent
révision
7594fbf3ed
1 fichiers modifiés avec 77 ajouts et 69 suppressions
  1. 77
    69
      project.cpp

+ 77
- 69
project.cpp Voir le fichier

@@ -698,85 +698,93 @@ void Project::saveMapEvents(Map *map) {
698 698
     QString path = root + QString("/data/maps/events/%1.inc").arg(map->name);
699 699
     QString text = "";
700 700
 
701
-    text += QString("%1::\n").arg(map->object_events_label);
702
-    for (int i = 0; i < map->events["object"].length(); i++) {
703
-        Event *object_event = map->events["object"].value(i);
704
-        int radius_x = object_event->getInt("radius_x");
705
-        int radius_y = object_event->getInt("radius_y");
706
-        QString radius = QString("%1").arg((radius_x & 0xf) + ((radius_y & 0xf) << 4));
707
-        uint16_t x = object_event->getInt("x");
708
-        uint16_t y = object_event->getInt("y");
709
-
710
-        text += QString("\tobject_event %1").arg(i + 1);
711
-        text += QString(", %1").arg(object_event->get("sprite"));
712
-        text += QString(", %1").arg(object_event->get("replacement"));
713
-        text += QString(", %1").arg(x & 0xff);
714
-        text += QString(", %1").arg((x >> 8) & 0xff);
715
-        text += QString(", %1").arg(y & 0xff);
716
-        text += QString(", %1").arg((y >> 8) & 0xff);
717
-        text += QString(", %1").arg(object_event->get("elevation"));
718
-        text += QString(", %1").arg(object_event->get("behavior"));
719
-        text += QString(", %1").arg(radius);
720
-        text += QString(", 0");
721
-        text += QString(", %1").arg(object_event->get("property"));
722
-        text += QString(", 0");
723
-        text += QString(", %1").arg(object_event->get("sight_radius"));
724
-        text += QString(", 0");
725
-        text += QString(", %1").arg(object_event->get("script_label"));
726
-        text += QString(", %1").arg(object_event->get("event_flag"));
727
-        text += QString(", 0");
728
-        text += QString(", 0");
701
+    if (map->events["object"].length() > 0) {
702
+        text += QString("%1::\n").arg(map->object_events_label);
703
+        for (int i = 0; i < map->events["object"].length(); i++) {
704
+            Event *object_event = map->events["object"].value(i);
705
+            int radius_x = object_event->getInt("radius_x");
706
+            int radius_y = object_event->getInt("radius_y");
707
+            QString radius = QString("%1").arg((radius_x & 0xf) + ((radius_y & 0xf) << 4));
708
+            uint16_t x = object_event->getInt("x");
709
+            uint16_t y = object_event->getInt("y");
710
+
711
+            text += QString("\tobject_event %1").arg(i + 1);
712
+            text += QString(", %1").arg(object_event->get("sprite"));
713
+            text += QString(", %1").arg(object_event->get("replacement"));
714
+            text += QString(", %1").arg(x & 0xff);
715
+            text += QString(", %1").arg((x >> 8) & 0xff);
716
+            text += QString(", %1").arg(y & 0xff);
717
+            text += QString(", %1").arg((y >> 8) & 0xff);
718
+            text += QString(", %1").arg(object_event->get("elevation"));
719
+            text += QString(", %1").arg(object_event->get("behavior"));
720
+            text += QString(", %1").arg(radius);
721
+            text += QString(", 0");
722
+            text += QString(", %1").arg(object_event->get("property"));
723
+            text += QString(", 0");
724
+            text += QString(", %1").arg(object_event->get("sight_radius"));
725
+            text += QString(", 0");
726
+            text += QString(", %1").arg(object_event->get("script_label"));
727
+            text += QString(", %1").arg(object_event->get("event_flag"));
728
+            text += QString(", 0");
729
+            text += QString(", 0");
730
+            text += "\n";
731
+        }
729 732
         text += "\n";
730 733
     }
731
-    text += "\n";
732 734
 
733
-    text += QString("%1::\n").arg(map->warps_label);
734
-    for (Event *warp : map->events["warp"]) {
735
-        text += QString("\twarp_def %1").arg(warp->get("x"));
736
-        text += QString(", %1").arg(warp->get("y"));
737
-        text += QString(", %1").arg(warp->get("elevation"));
738
-        text += QString(", %1").arg(warp->get("destination_warp"));
739
-        text += QString(", %1").arg(warp->get("destination_map"));
740
-        text += "\n";
741
-    }
742
-    text += "\n";
743
-
744
-    text += QString("%1::\n").arg(map->coord_events_label);
745
-    for (Event *coords : map->events["trap"]) {
746
-        text += QString("\tcoord_event %1").arg(coords->get("x"));
747
-        text += QString(", %1").arg(coords->get("y"));
748
-        text += QString(", %1").arg(coords->get("elevation"));
749
-        text += QString(", 0");
750
-        text += QString(", %1").arg(coords->get("coord_unknown1"));
751
-        text += QString(", %1").arg(coords->get("coord_unknown2"));
752
-        text += QString(", 0");
753
-        text += QString(", %1").arg(coords->get("script_label"));
735
+    if (map->events["warp"].length() > 0) {
736
+        text += QString("%1::\n").arg(map->warps_label);
737
+        for (Event *warp : map->events["warp"]) {
738
+            text += QString("\twarp_def %1").arg(warp->get("x"));
739
+            text += QString(", %1").arg(warp->get("y"));
740
+            text += QString(", %1").arg(warp->get("elevation"));
741
+            text += QString(", %1").arg(warp->get("destination_warp"));
742
+            text += QString(", %1").arg(mapNamesToMapConstants[warp->get("destination_map_name")]);
743
+            text += "\n";
744
+        }
754 745
         text += "\n";
755 746
     }
756
-    text += "\n";
757 747
 
758
-    text += QString("%1::\n").arg(map->bg_events_label);
759
-    for (Event *sign : map->events["sign"]) {
760
-        text += QString("\tbg_event %1").arg(sign->get("x"));
761
-        text += QString(", %1").arg(sign->get("y"));
762
-        text += QString(", %1").arg(sign->get("elevation"));
763
-        text += QString(", %1").arg(sign->get("type"));
764
-        text += QString(", 0");
765
-        text += QString(", %1").arg(sign->get("script_label"));
748
+    if (map->events["trap"].length() > 0) {
749
+        text += QString("%1::\n").arg(map->coord_events_label);
750
+        for (Event *coords : map->events["trap"]) {
751
+            text += QString("\tcoord_event %1").arg(coords->get("x"));
752
+            text += QString(", %1").arg(coords->get("y"));
753
+            text += QString(", %1").arg(coords->get("elevation"));
754
+            text += QString(", 0");
755
+            text += QString(", %1").arg(coords->get("coord_unknown1"));
756
+            text += QString(", %1").arg(coords->get("coord_unknown2"));
757
+            text += QString(", 0");
758
+            text += QString(", %1").arg(coords->get("script_label"));
759
+            text += "\n";
760
+        }
766 761
         text += "\n";
767 762
     }
768
-    for (Event *item : map->events["hidden item"]) {
769
-        text += QString("\tbg_event %1").arg(item->get("x"));
770
-        text += QString(", %1").arg(item->get("y"));
771
-        text += QString(", %1").arg(item->get("elevation"));
772
-        text += QString(", %1").arg(item->get("type"));
773
-        text += QString(", 0");
774
-        text += QString(", %1").arg(item->get("item"));
775
-        text += QString(", %1").arg(item->get("item_unknown5"));
776
-        text += QString(", %1").arg(item->get("item_unknown6"));
763
+
764
+    if (map->events["sign"].length() + map->events["hidden item"].length() > 0) {
765
+        text += QString("%1::\n").arg(map->bg_events_label);
766
+        for (Event *sign : map->events["sign"]) {
767
+            text += QString("\tbg_event %1").arg(sign->get("x"));
768
+            text += QString(", %1").arg(sign->get("y"));
769
+            text += QString(", %1").arg(sign->get("elevation"));
770
+            text += QString(", %1").arg(sign->get("type"));
771
+            text += QString(", 0");
772
+            text += QString(", %1").arg(sign->get("script_label"));
773
+            text += "\n";
774
+        }
775
+        for (Event *item : map->events["hidden item"]) {
776
+            text += QString("\tbg_event %1").arg(item->get("x"));
777
+            text += QString(", %1").arg(item->get("y"));
778
+            text += QString(", %1").arg(item->get("elevation"));
779
+            text += QString(", %1").arg(item->get("type"));
780
+            text += QString(", 0");
781
+            text += QString(", %1").arg(item->get("item"));
782
+            text += QString(", %1").arg(item->get("item_unknown5"));
783
+            text += QString(", %1").arg(item->get("item_unknown6"));
784
+            text += "\n";
785
+        }
777 786
         text += "\n";
778 787
     }
779
-    text += "\n";
780 788
 
781 789
     text += QString("%1::\n").arg(map->events_label);
782 790
     text += QString("\tmap_events %1, %2, %3, %4\n")