Browse Source

Save connections to file

Marcus Huderle 6 years ago
parent
commit
073a13ac9c
2 changed files with 26 additions and 0 deletions
  1. 25
    0
      project.cpp
  2. 1
    0
      project.h

+ 25
- 0
project.cpp View File

210
     saveTextFile(header_path, text);
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
 void Project::readMapAttributesTable() {
237
 void Project::readMapAttributesTable() {
214
     int curMapIndex = 1;
238
     int curMapIndex = 1;
215
     QString attributesText = readTextFile(getMapAttributesTableFilepath());
239
     QString attributesText = readTextFile(getMapAttributesTableFilepath());
680
 
704
 
681
     saveMapBorder(map);
705
     saveMapBorder(map);
682
     saveMapHeader(map);
706
     saveMapHeader(map);
707
+    saveMapConnections(map);
683
     saveBlockdata(map);
708
     saveBlockdata(map);
684
     saveMapEvents(map);
709
     saveMapEvents(map);
685
 
710
 

+ 1
- 0
project.h View File

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