|
@@ -197,7 +197,14 @@ void Project::saveMapHeader(Map *map) {
|
197
|
197
|
text += QString("\t.4byte %1\n").arg(map->attributes_label);
|
198
|
198
|
text += QString("\t.4byte %1\n").arg(map->events_label);
|
199
|
199
|
text += QString("\t.4byte %1\n").arg(map->scripts_label);
|
|
200
|
+
|
|
201
|
+ if (map->connections.length() == 0) {
|
|
202
|
+ map->connections_label = "0x0";
|
|
203
|
+ } else {
|
|
204
|
+ map->connections_label = QString("%1_MapConnections").arg(map->name);
|
|
205
|
+ }
|
200
|
206
|
text += QString("\t.4byte %1\n").arg(map->connections_label);
|
|
207
|
+
|
201
|
208
|
text += QString("\t.2byte %1\n").arg(map->song);
|
202
|
209
|
text += QString("\t.2byte %1\n").arg(map->index);
|
203
|
210
|
text += QString("\t.byte %1\n").arg(map->location);
|
|
@@ -211,27 +218,45 @@ void Project::saveMapHeader(Map *map) {
|
211
|
218
|
}
|
212
|
219
|
|
213
|
220
|
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);
|
|
221
|
+ QString path = root + "/data/maps/" + map->name + "/connections.inc";
|
|
222
|
+ if (map->connections.length() > 0) {
|
|
223
|
+ QString text = "";
|
|
224
|
+ QString connectionsListLabel = QString("%1_MapConnectionsList").arg(map->name);
|
|
225
|
+ int numValidConnections = 0;
|
|
226
|
+ text += QString("%1::\n").arg(connectionsListLabel);
|
|
227
|
+ for (Connection* connection : map->connections) {
|
|
228
|
+ if (mapNamesToMapConstants->contains(connection->map_name)) {
|
|
229
|
+ text += QString("\tconnection %1, %2, %3\n")
|
|
230
|
+ .arg(connection->direction)
|
|
231
|
+ .arg(connection->offset)
|
|
232
|
+ .arg(mapNamesToMapConstants->value(connection->map_name));
|
|
233
|
+ numValidConnections++;
|
|
234
|
+ } else {
|
|
235
|
+ qDebug() << QString("Failed to write map connection. %1 not a valid map name").arg(connection->map_name);
|
|
236
|
+ }
|
|
237
|
+ }
|
|
238
|
+ text += QString("\n");
|
|
239
|
+ text += QString("%1::\n").arg(map->connections_label);
|
|
240
|
+ text += QString("\t.4byte %1\n").arg(numValidConnections);
|
|
241
|
+ text += QString("\t.4byte %1\n").arg(connectionsListLabel);
|
|
242
|
+ saveTextFile(path, text);
|
|
243
|
+ } else {
|
|
244
|
+ deleteFile(path);
|
|
245
|
+ }
|
|
246
|
+
|
|
247
|
+ updateMapsWithConnections(map);
|
|
248
|
+}
|
|
249
|
+
|
|
250
|
+void Project::updateMapsWithConnections(Map *map) {
|
|
251
|
+ if (map->connections.length() > 0) {
|
|
252
|
+ if (!mapsWithConnections.contains(map->name)) {
|
|
253
|
+ mapsWithConnections.append(map->name);
|
|
254
|
+ }
|
|
255
|
+ } else {
|
|
256
|
+ if (mapsWithConnections.contains(map->name)) {
|
|
257
|
+ mapsWithConnections.removeOne(map->name);
|
228
|
258
|
}
|
229
|
259
|
}
|
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
|
260
|
}
|
236
|
261
|
|
237
|
262
|
void Project::readMapAttributesTable() {
|
|
@@ -728,6 +753,7 @@ void Project::saveAllDataStructures() {
|
728
|
753
|
saveAllMapAttributes();
|
729
|
754
|
saveMapGroupsTable();
|
730
|
755
|
saveMapConstantsHeader();
|
|
756
|
+ saveMapsWithConnections();
|
731
|
757
|
}
|
732
|
758
|
|
733
|
759
|
void Project::loadTilesetAssets(Tileset* tileset) {
|
|
@@ -939,6 +965,13 @@ void Project::appendTextFile(QString path, QString text) {
|
939
|
965
|
}
|
940
|
966
|
}
|
941
|
967
|
|
|
968
|
+void Project::deleteFile(QString path) {
|
|
969
|
+ QFile file(path);
|
|
970
|
+ if (file.exists() && !file.remove()) {
|
|
971
|
+ qDebug() << QString("Could not delete file '%1': ").arg(path) + file.errorString();
|
|
972
|
+ }
|
|
973
|
+}
|
|
974
|
+
|
942
|
975
|
void Project::readMapGroups() {
|
943
|
976
|
QString text = readTextFile(root + "/data/maps/_groups.inc");
|
944
|
977
|
if (text.isNull()) {
|
|
@@ -1124,6 +1157,41 @@ void Project::readCDefinesSorted(QString filepath, QStringList prefixes, QString
|
1124
|
1157
|
}
|
1125
|
1158
|
}
|
1126
|
1159
|
|
|
1160
|
+void Project::readMapsWithConnections() {
|
|
1161
|
+ QString path = root + "/data/maps/connections.inc";
|
|
1162
|
+ QString text = readTextFile(path);
|
|
1163
|
+ if (text.isNull()) {
|
|
1164
|
+ return;
|
|
1165
|
+ }
|
|
1166
|
+
|
|
1167
|
+ mapsWithConnections.clear();
|
|
1168
|
+ QRegularExpression re("data\\/maps\\/(?<mapName>\\w+)\\/connections.inc");
|
|
1169
|
+ QList<QStringList>* includes = parseAsm(text);
|
|
1170
|
+ for (QStringList values : *includes) {
|
|
1171
|
+ if (values.length() != 2)
|
|
1172
|
+ continue;
|
|
1173
|
+
|
|
1174
|
+ QRegularExpressionMatch match = re.match(values.value(1));
|
|
1175
|
+ if (match.hasMatch()) {
|
|
1176
|
+ QString mapName = match.captured("mapName");
|
|
1177
|
+ mapsWithConnections.append(mapName);
|
|
1178
|
+ }
|
|
1179
|
+ }
|
|
1180
|
+}
|
|
1181
|
+
|
|
1182
|
+void Project::saveMapsWithConnections() {
|
|
1183
|
+ QString path = root + "/data/maps/connections.inc";
|
|
1184
|
+ QString text = "";
|
|
1185
|
+ for (QString mapName : mapsWithConnections) {
|
|
1186
|
+ if (mapNamesToMapConstants->contains(mapName)) {
|
|
1187
|
+ text += QString("\t.include \"data/maps/%1/connections.inc\"\n").arg(mapName);
|
|
1188
|
+ } else {
|
|
1189
|
+ qDebug() << QString("Failed to write connection include. %1 not a valid map name").arg(mapName);
|
|
1190
|
+ }
|
|
1191
|
+ }
|
|
1192
|
+ saveTextFile(path, text);
|
|
1193
|
+}
|
|
1194
|
+
|
1127
|
1195
|
QStringList Project::getSongNames() {
|
1128
|
1196
|
QStringList names;
|
1129
|
1197
|
QString text = readTextFile(root + "/include/constants/songs.h");
|