|
@@ -23,6 +23,7 @@ Project::Project()
|
23
|
23
|
mapConstantsToMapNames = new QMap<QString, QString>;
|
24
|
24
|
mapNamesToMapConstants = new QMap<QString, QString>;
|
25
|
25
|
mapAttributesTable = new QMap<int, QString>;
|
|
26
|
+ mapAttributes = new QMap<QString, QMap<QString, QString>*>;
|
26
|
27
|
tileset_cache = new QMap<QString, Tileset*>;
|
27
|
28
|
}
|
28
|
29
|
|
|
@@ -273,6 +274,95 @@ void Project::readMapAttributes(Map* map) {
|
273
|
274
|
map->tileset_secondary_label = attributes->value(5);
|
274
|
275
|
}
|
275
|
276
|
|
|
277
|
+void Project::readAllMapAttributes() {
|
|
278
|
+ mapAttributes->clear();
|
|
279
|
+
|
|
280
|
+ Asm *parser = new Asm;
|
|
281
|
+ QString assets_text = readTextFile(root + "/data/maps/_assets.inc");
|
|
282
|
+ if (assets_text.isNull()) {
|
|
283
|
+ return;
|
|
284
|
+ }
|
|
285
|
+
|
|
286
|
+ QList<QStringList> *commands = parser->parse(assets_text);
|
|
287
|
+
|
|
288
|
+ // Assume the _assets.inc file is grouped consistently in the order of:
|
|
289
|
+ // 1. <map_name>_MapBorder
|
|
290
|
+ // 2. <map_name>_MapBlockdata
|
|
291
|
+ // 3. <map_name>_MapAttributes
|
|
292
|
+ int i = 0;
|
|
293
|
+ while (i < commands->length()) {
|
|
294
|
+ // Read MapBorder assets.
|
|
295
|
+ QStringList borderParams = commands->value(i++);
|
|
296
|
+ bool isUnknownMapBorder = borderParams.value(1).startsWith("UnknownMapBorder_");
|
|
297
|
+ if (borderParams.value(0) != ".label" || (!borderParams.value(1).endsWith("_MapBorder") && !isUnknownMapBorder)) {
|
|
298
|
+ qDebug() << QString("Expected MapBorder label, but found %1").arg(borderParams.value(1));
|
|
299
|
+ continue;
|
|
300
|
+ }
|
|
301
|
+ QString borderLabel = borderParams.value(1);
|
|
302
|
+ QString mapName;
|
|
303
|
+ if (!isUnknownMapBorder) {
|
|
304
|
+ mapName = borderLabel.remove(borderLabel.length() - 10, 10);
|
|
305
|
+ } else {
|
|
306
|
+ // Unknown map name has to match the MapAttributes label.
|
|
307
|
+ mapName = borderLabel.replace("Border", "Attributes");
|
|
308
|
+ }
|
|
309
|
+ mapAttributes->insert(mapName, new QMap<QString, QString>);
|
|
310
|
+ mapAttributes->value(mapName)->insert("border_label", borderParams.value(1));
|
|
311
|
+ borderParams = commands->value(i++);
|
|
312
|
+ mapAttributes->value(mapName)->insert("border_filepath", borderParams.value(1).replace("\"", ""));
|
|
313
|
+
|
|
314
|
+ // Read MapBlockData assets.
|
|
315
|
+ QStringList blockDataParams = commands->value(i++);
|
|
316
|
+ bool isUnknownMapBlockdata = blockDataParams.value(1).startsWith("UnknownMapBlockdata_");
|
|
317
|
+ if (blockDataParams.value(0) != ".label" || (!blockDataParams.value(1).endsWith("_MapBlockdata") && !isUnknownMapBlockdata)) {
|
|
318
|
+ qDebug() << QString("Expected MapBlockdata label, but found %1").arg(blockDataParams.value(1));
|
|
319
|
+ continue;
|
|
320
|
+ }
|
|
321
|
+ QString blockDataLabel = blockDataParams.value(1);
|
|
322
|
+ mapAttributes->value(mapName)->insert("blockdata_label", blockDataLabel);
|
|
323
|
+ blockDataParams = commands->value(i++);
|
|
324
|
+ mapAttributes->value(mapName)->insert("blockdata_filepath", blockDataParams.value(1).replace("\"", ""));
|
|
325
|
+
|
|
326
|
+ // Read MapAttributes assets.
|
|
327
|
+ i++; // skip .align
|
|
328
|
+ // Maps can share MapAttributes, so gather a list of them.
|
|
329
|
+ QStringList attributeMapLabels;
|
|
330
|
+ QStringList attributesParams;
|
|
331
|
+ while (i < commands->length()) {
|
|
332
|
+ attributesParams = commands->value(i);
|
|
333
|
+ if (attributesParams.value(0) != ".label") {
|
|
334
|
+ break;
|
|
335
|
+ }
|
|
336
|
+ attributeMapLabels.append(attributesParams.value(1));
|
|
337
|
+ i++;
|
|
338
|
+ }
|
|
339
|
+
|
|
340
|
+ // Apply the map attributes to each of the shared maps.
|
|
341
|
+ QString attrWidth = commands->value(i++).value(1);
|
|
342
|
+ QString attrHeight = commands->value(i++).value(1);
|
|
343
|
+ QString attrBorderLabel = commands->value(i++).value(1);
|
|
344
|
+ QString attrBlockdataLabel = commands->value(i++).value(1);
|
|
345
|
+ QString attrTilesetPrimary = commands->value(i++).value(1);
|
|
346
|
+ QString attrTilesetSecondary = commands->value(i++).value(1);
|
|
347
|
+ for (QString attributeMapLabel: attributeMapLabels) {
|
|
348
|
+ QString altMapName = attributeMapLabel;
|
|
349
|
+ if (!altMapName.startsWith("UnknownMapAttributes_")) {
|
|
350
|
+ altMapName.remove(altMapName.length() - 14, 14);
|
|
351
|
+ }
|
|
352
|
+ if (!mapAttributes->contains(altMapName)) {
|
|
353
|
+ mapAttributes->insert(altMapName, new QMap<QString, QString>);
|
|
354
|
+ }
|
|
355
|
+ mapAttributes->value(altMapName)->insert("attributes_label", attributeMapLabel);
|
|
356
|
+ mapAttributes->value(altMapName)->insert("width", attrWidth);
|
|
357
|
+ mapAttributes->value(altMapName)->insert("height", attrHeight);
|
|
358
|
+ mapAttributes->value(altMapName)->insert("border_label", attrBorderLabel);
|
|
359
|
+ mapAttributes->value(altMapName)->insert("blockdata_label", attrBlockdataLabel);
|
|
360
|
+ mapAttributes->value(altMapName)->insert("tileset_primary", attrTilesetPrimary);
|
|
361
|
+ mapAttributes->value(altMapName)->insert("tileset_secondary", attrTilesetSecondary);
|
|
362
|
+ }
|
|
363
|
+ }
|
|
364
|
+}
|
|
365
|
+
|
276
|
366
|
void Project::setNewMapAttributes(Map* map) {
|
277
|
367
|
map->width = "20";
|
278
|
368
|
map->height = "20";
|