From 073a13ac9ca67cce4c4559a788ba2651be6ad1da Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Wed, 7 Mar 2018 21:05:35 -0800 Subject: [PATCH] Save connections to file --- project.cpp | 25 +++++++++++++++++++++++++ project.h | 1 + 2 files changed, 26 insertions(+) diff --git a/project.cpp b/project.cpp index 068bd554..9053b164 100755 --- a/project.cpp +++ b/project.cpp @@ -210,6 +210,30 @@ void Project::saveMapHeader(Map *map) { saveTextFile(header_path, text); } +void Project::saveMapConnections(Map *map) { + QString connections_path = root + "/data/maps/" + map->name + "/connections.inc"; + QString connectionsListLabel = QString("%1_MapConnectionsList").arg(map->name); + int numValidConnections = 0; + QString text = ""; + text += QString("%1::\n").arg(connectionsListLabel); + for (Connection* connection : map->connections) { + if (mapNamesToMapConstants->contains(connection->map_name)) { + text += QString("\tconnection %1, %2, %3\n") + .arg(connection->direction) + .arg(connection->offset) + .arg(mapNamesToMapConstants->value(connection->map_name)); + numValidConnections++; + } else { + qDebug() << QString("Failed to write map connection. %1 not a valid map name").arg(connection->map_name); + } + } + text += QString("\n"); + text += QString("%1::\n").arg(map->connections_label); + text += QString("\t.4byte %1\n").arg(numValidConnections); + text += QString("\t.4byte %1\n").arg(connectionsListLabel); + saveTextFile(connections_path, text); +} + void Project::readMapAttributesTable() { int curMapIndex = 1; QString attributesText = readTextFile(getMapAttributesTableFilepath()); @@ -680,6 +704,7 @@ void Project::saveMap(Map *map) { saveMapBorder(map); saveMapHeader(map); + saveMapConnections(map); saveBlockdata(map); saveMapEvents(map); diff --git a/project.h b/project.h index 43736c2a..0c064444 100755 --- a/project.h +++ b/project.h @@ -97,6 +97,7 @@ private: QString getMapAttributesTableFilepath(); QString getMapAssetsFilepath(); void saveMapHeader(Map*); + void saveMapConnections(Map*); void saveMapAttributesTable(); void updateMapAttributes(Map* map); void readCDefinesSorted(QString, QStringList, QStringList*);