Sfoglia il codice sorgente

Save connections to file

Marcus Huderle 6 anni fa
parent
commit
073a13ac9c
2 ha cambiato i file con 26 aggiunte e 0 eliminazioni
  1. 25
    0
      project.cpp
  2. 1
    0
      project.h

+ 25
- 0
project.cpp Vedi File

@@ -210,6 +210,30 @@ void Project::saveMapHeader(Map *map) {
210 210
     saveTextFile(header_path, text);
211 211
 }
212 212
 
213
+void Project::saveMapConnections(Map *map) {
214
+    QString connections_path = root + "/data/maps/" + map->name + "/connections.inc";
215
+    QString connectionsListLabel = QString("%1_MapConnectionsList").arg(map->name);
216
+    int numValidConnections = 0;
217
+    QString text = "";
218
+    text += QString("%1::\n").arg(connectionsListLabel);
219
+    for (Connection* connection : map->connections) {
220
+        if (mapNamesToMapConstants->contains(connection->map_name)) {
221
+            text += QString("\tconnection %1, %2, %3\n")
222
+                    .arg(connection->direction)
223
+                    .arg(connection->offset)
224
+                    .arg(mapNamesToMapConstants->value(connection->map_name));
225
+            numValidConnections++;
226
+        } else {
227
+            qDebug() << QString("Failed to write map connection. %1 not a valid map name").arg(connection->map_name);
228
+        }
229
+    }
230
+    text += QString("\n");
231
+    text += QString("%1::\n").arg(map->connections_label);
232
+    text += QString("\t.4byte %1\n").arg(numValidConnections);
233
+    text += QString("\t.4byte %1\n").arg(connectionsListLabel);
234
+    saveTextFile(connections_path, text);
235
+}
236
+
213 237
 void Project::readMapAttributesTable() {
214 238
     int curMapIndex = 1;
215 239
     QString attributesText = readTextFile(getMapAttributesTableFilepath());
@@ -680,6 +704,7 @@ void Project::saveMap(Map *map) {
680 704
 
681 705
     saveMapBorder(map);
682 706
     saveMapHeader(map);
707
+    saveMapConnections(map);
683 708
     saveBlockdata(map);
684 709
     saveMapEvents(map);
685 710
 

+ 1
- 0
project.h Vedi File

@@ -97,6 +97,7 @@ private:
97 97
     QString getMapAttributesTableFilepath();
98 98
     QString getMapAssetsFilepath();
99 99
     void saveMapHeader(Map*);
100
+    void saveMapConnections(Map*);
100 101
     void saveMapAttributesTable();
101 102
     void updateMapAttributes(Map* map);
102 103
     void readCDefinesSorted(QString, QStringList, QStringList*);