|
@@ -49,10 +49,7 @@ Map* Project::loadMap(QString map_name) {
|
49
|
49
|
}
|
50
|
50
|
|
51
|
51
|
readMapHeader(map);
|
52
|
|
- readMapAttributes(map);
|
53
|
|
- getTilesets(map);
|
54
|
|
- loadBlockdata(map);
|
55
|
|
- loadMapBorder(map);
|
|
52
|
+ readMapLayout(map);
|
56
|
53
|
readMapEvents(map);
|
57
|
54
|
loadMapConnections(map);
|
58
|
55
|
map->commit();
|
|
@@ -136,9 +133,12 @@ QStringList* Project::getLabelValues(QList<QStringList> *list, QString label) {
|
136
|
133
|
QStringList params = list->value(i);
|
137
|
134
|
QString macro = params.value(0);
|
138
|
135
|
// Ignore .align
|
139
|
|
- if (macro == ".align") {
|
|
136
|
+ if (macro == ".align")
|
|
137
|
+ continue;
|
|
138
|
+ if (macro == ".ifdef")
|
|
139
|
+ continue;
|
|
140
|
+ if (macro == ".ifndef")
|
140
|
141
|
continue;
|
141
|
|
- }
|
142
|
142
|
for (int j = 1; j < params.length(); j++) {
|
143
|
143
|
values->append(params.value(j));
|
144
|
144
|
}
|
|
@@ -159,12 +159,12 @@ void Project::readMapHeader(Map* map) {
|
159
|
159
|
return;
|
160
|
160
|
}
|
161
|
161
|
QStringList *header = getLabelValues(parser->parseAsm(header_text), label);
|
162
|
|
- map->attributes_label = header->value(0);
|
|
162
|
+ map->layout_label = header->value(0);
|
163
|
163
|
map->events_label = header->value(1);
|
164
|
164
|
map->scripts_label = header->value(2);
|
165
|
165
|
map->connections_label = header->value(3);
|
166
|
166
|
map->song = header->value(4);
|
167
|
|
- map->index = header->value(5);
|
|
167
|
+ map->layout_id = header->value(5);
|
168
|
168
|
map->location = header->value(6);
|
169
|
169
|
map->visibility = header->value(7);
|
170
|
170
|
map->weather = header->value(8);
|
|
@@ -175,12 +175,12 @@ void Project::readMapHeader(Map* map) {
|
175
|
175
|
}
|
176
|
176
|
|
177
|
177
|
void Project::setNewMapHeader(Map* map, int mapIndex) {
|
178
|
|
- map->attributes_label = QString("%1_MapAttributes").arg(map->name);
|
|
178
|
+ map->layout_label = QString("%1_Layout").arg(map->name);
|
179
|
179
|
map->events_label = QString("%1_MapEvents").arg(map->name);;
|
180
|
180
|
map->scripts_label = QString("%1_MapScripts").arg(map->name);;
|
181
|
181
|
map->connections_label = "0x0";
|
182
|
182
|
map->song = "BGM_DAN02";
|
183
|
|
- map->index = QString("%1").arg(mapIndex);
|
|
183
|
+ map->layout_id = QString("%1").arg(mapIndex);
|
184
|
184
|
map->location = "0";
|
185
|
185
|
map->visibility = "0";
|
186
|
186
|
map->weather = "2";
|
|
@@ -195,7 +195,7 @@ void Project::saveMapHeader(Map *map) {
|
195
|
195
|
QString header_path = root + "/data/maps/" + label + "/header.inc";
|
196
|
196
|
QString text = "";
|
197
|
197
|
text += QString("%1::\n").arg(label);
|
198
|
|
- text += QString("\t.4byte %1\n").arg(map->attributes_label);
|
|
198
|
+ text += QString("\t.4byte %1\n").arg(map->layout_label);
|
199
|
199
|
text += QString("\t.4byte %1\n").arg(map->events_label);
|
200
|
200
|
text += QString("\t.4byte %1\n").arg(map->scripts_label);
|
201
|
201
|
|
|
@@ -207,7 +207,7 @@ void Project::saveMapHeader(Map *map) {
|
207
|
207
|
text += QString("\t.4byte %1\n").arg(map->connections_label);
|
208
|
208
|
|
209
|
209
|
text += QString("\t.2byte %1\n").arg(map->song);
|
210
|
|
- text += QString("\t.2byte %1\n").arg(map->index);
|
|
210
|
+ text += QString("\t.2byte %1\n").arg(map->layout_id);
|
211
|
211
|
text += QString("\t.byte %1\n").arg(map->location);
|
212
|
212
|
text += QString("\t.byte %1\n").arg(map->visibility);
|
213
|
213
|
text += QString("\t.byte %1\n").arg(map->weather);
|
|
@@ -260,269 +260,180 @@ void Project::updateMapsWithConnections(Map *map) {
|
260
|
260
|
}
|
261
|
261
|
}
|
262
|
262
|
|
263
|
|
-void Project::readMapAttributesTable() {
|
264
|
|
- int curMapIndex = 1;
|
265
|
|
- QString attributesText = readTextFile(getMapAttributesTableFilepath());
|
266
|
|
- QList<QStringList>* values = parseAsm(attributesText);
|
267
|
|
- bool inAttributePointers = false;
|
|
263
|
+void Project::readMapLayoutsTable() {
|
|
264
|
+ int curIndex = 1;
|
|
265
|
+ QString layoutsText = readTextFile(getMapLayoutsTableFilepath());
|
|
266
|
+ QList<QStringList>* values = parseAsm(layoutsText);
|
|
267
|
+ bool inLayoutPointers = false;
|
268
|
268
|
for (int i = 0; i < values->length(); i++) {
|
269
|
269
|
QStringList params = values->value(i);
|
270
|
270
|
QString macro = params.value(0);
|
271
|
271
|
if (macro == ".label") {
|
272
|
|
- if (inAttributePointers) {
|
|
272
|
+ if (inLayoutPointers) {
|
273
|
273
|
break;
|
274
|
274
|
}
|
275
|
|
- if (params.value(1) == "gMapAttributes") {
|
276
|
|
- inAttributePointers = true;
|
|
275
|
+ if (params.value(1) == "gMapLayouts") {
|
|
276
|
+ inLayoutPointers = true;
|
277
|
277
|
}
|
278
|
|
- } else if (macro == ".4byte" && inAttributePointers) {
|
279
|
|
- QString mapName = params.value(1);
|
280
|
|
- if (!mapName.contains("UnknownMapAttributes")) {
|
281
|
|
- // Strip off "_MapAttributes" from the label if it's a real map label.
|
282
|
|
- mapName = mapName.remove(mapName.length() - 14, 14);
|
283
|
|
- }
|
284
|
|
- mapAttributesTable.insert(curMapIndex, mapName);
|
285
|
|
- curMapIndex++;
|
|
278
|
+ } else if (macro == ".4byte" && inLayoutPointers) {
|
|
279
|
+ QString layoutName = params.value(1);
|
|
280
|
+ mapLayoutsTable.append(layoutName);
|
286
|
281
|
}
|
287
|
282
|
}
|
288
|
283
|
|
289
|
284
|
// Deep copy
|
290
|
|
- mapAttributesTableMaster = mapAttributesTable;
|
291
|
|
- mapAttributesTableMaster.detach();
|
|
285
|
+ mapLayoutsTableMaster = mapLayoutsTable;
|
|
286
|
+ mapLayoutsTableMaster.detach();
|
292
|
287
|
}
|
293
|
288
|
|
294
|
|
-void Project::saveMapAttributesTable() {
|
|
289
|
+void Project::saveMapLayoutsTable() {
|
295
|
290
|
QString text = "";
|
296
|
291
|
text += QString("\t.align 2\n");
|
297
|
|
- text += QString("gMapAttributes::\n");
|
298
|
|
- for (int i = 0; i < mapAttributesTableMaster.count(); i++) {
|
299
|
|
- int mapIndex = i + 1;
|
300
|
|
- QString mapName = mapAttributesTableMaster.value(mapIndex);
|
301
|
|
- if (!mapName.contains("UnknownMapAttributes")) {
|
302
|
|
- text += QString("\t.4byte %1_MapAttributes\n").arg(mapName);
|
303
|
|
- } else {
|
304
|
|
- text += QString("\t.4byte %1\n").arg(mapName);
|
305
|
|
- }
|
|
292
|
+ text += QString("gMapLayouts::\n");
|
|
293
|
+ for (QString layoutName : mapLayoutsTableMaster) {
|
|
294
|
+ text += QString("\t.4byte %1\n").arg(layoutName);
|
306
|
295
|
}
|
307
|
|
- saveTextFile(getMapAttributesTableFilepath(), text);
|
|
296
|
+ saveTextFile(getMapLayoutsTableFilepath(), text);
|
308
|
297
|
}
|
309
|
298
|
|
310
|
|
-QString Project::getMapAttributesTableFilepath() {
|
311
|
|
- return QString("%1/data/maps/attributes_table.inc").arg(root);
|
|
299
|
+QString Project::getMapLayoutsTableFilepath() {
|
|
300
|
+ return QString("%1/data/layouts_table.inc").arg(root);
|
312
|
301
|
}
|
313
|
302
|
|
314
|
|
-void Project::readMapAttributes(Map* map) {
|
315
|
|
- if (!map->isPersistedToFile) {
|
316
|
|
- return;
|
|
303
|
+QStringList* Project::readLayoutValues(QString layoutLabel) {
|
|
304
|
+ ParseUtil *parser = new ParseUtil;
|
|
305
|
+
|
|
306
|
+ QString layoutText = readTextFile(getMapLayoutFilepath(layoutLabel));
|
|
307
|
+ if (layoutText.isNull()) {
|
|
308
|
+ return NULL;
|
317
|
309
|
}
|
318
|
310
|
|
319
|
|
- ParseUtil *parser = new ParseUtil;
|
|
311
|
+ QStringList *layoutValues = getLabelValues(parser->parseAsm(layoutText), layoutLabel);
|
|
312
|
+ QString borderLabel = layoutValues->value(2);
|
|
313
|
+ QString blockdataLabel = layoutValues->value(3);
|
|
314
|
+ QStringList *borderValues = getLabelValues(parser->parseAsm(layoutText), borderLabel);
|
|
315
|
+ QString borderPath = borderValues->value(0).replace("\"", "");
|
|
316
|
+ layoutValues->append(borderPath);
|
|
317
|
+ QStringList *blockdataValues = getLabelValues(parser->parseAsm(layoutText), blockdataLabel);
|
|
318
|
+ QString blockdataPath = blockdataValues->value(0).replace("\"", "");
|
|
319
|
+ layoutValues->append(blockdataPath);
|
320
|
320
|
|
321
|
|
- QString assets_text = readTextFile(getMapAssetsFilepath());
|
322
|
|
- if (assets_text.isNull()) {
|
323
|
|
- return;
|
|
321
|
+ if (layoutValues->size() != 8) {
|
|
322
|
+ qDebug() << "Error: Unexpected number of properties in layout '" << layoutLabel << "'";
|
|
323
|
+ return NULL;
|
324
|
324
|
}
|
325
|
|
- QStringList *attributes = getLabelValues(parser->parseAsm(assets_text), map->attributes_label);
|
326
|
|
- map->width = attributes->value(0);
|
327
|
|
- map->height = attributes->value(1);
|
328
|
|
- map->border_label = attributes->value(2);
|
329
|
|
- map->blockdata_label = attributes->value(3);
|
330
|
|
- map->tileset_primary_label = attributes->value(4);
|
331
|
|
- map->tileset_secondary_label = attributes->value(5);
|
332
|
|
-}
|
333
|
325
|
|
334
|
|
-void Project::readAllMapAttributes() {
|
335
|
|
- mapAttributes.clear();
|
|
326
|
+ return layoutValues;
|
|
327
|
+}
|
336
|
328
|
|
337
|
|
- ParseUtil *parser = new ParseUtil;
|
338
|
|
- QString assets_text = readTextFile(getMapAssetsFilepath());
|
339
|
|
- if (assets_text.isNull()) {
|
|
329
|
+void Project::readMapLayout(Map* map) {
|
|
330
|
+ if (!map->isPersistedToFile) {
|
340
|
331
|
return;
|
341
|
332
|
}
|
342
|
333
|
|
343
|
|
- QList<QStringList> *commands = parser->parseAsm(assets_text);
|
344
|
|
-
|
345
|
|
- // Assume the _assets.inc file is grouped consistently in the order of:
|
346
|
|
- // 1. <map_name>_MapBorder
|
347
|
|
- // 2. <map_name>_MapBlockdata
|
348
|
|
- // 3. <map_name>_MapAttributes
|
349
|
|
- int i = 0;
|
350
|
|
- while (i < commands->length()) {
|
351
|
|
- // Read MapBorder assets.
|
352
|
|
- QStringList borderParams = commands->value(i++);
|
353
|
|
- bool isUnknownMapBorder = borderParams.value(1).startsWith("UnknownMapBorder_");
|
354
|
|
- if (borderParams.value(0) != ".label" || (!borderParams.value(1).endsWith("_MapBorder") && !isUnknownMapBorder)) {
|
355
|
|
- qDebug() << QString("Expected MapBorder label, but found %1").arg(borderParams.value(1));
|
356
|
|
- continue;
|
357
|
|
- }
|
358
|
|
- QString borderLabel = borderParams.value(1);
|
359
|
|
- QString mapName;
|
360
|
|
- if (!isUnknownMapBorder) {
|
361
|
|
- mapName = borderLabel.remove(borderLabel.length() - 10, 10);
|
362
|
|
- } else {
|
363
|
|
- // Unknown map name has to match the MapAttributes label.
|
364
|
|
- mapName = borderLabel.replace("Border", "Attributes");
|
|
334
|
+ MapLayout *layout;
|
|
335
|
+ if (!mapLayouts.contains(map->layout_label)) {
|
|
336
|
+ QStringList *layoutValues = readLayoutValues(map->layout->label);
|
|
337
|
+ if (layoutValues == NULL) {
|
|
338
|
+ return;
|
365
|
339
|
}
|
366
|
340
|
|
367
|
|
- mapAttributes[mapName].insert("border_label", borderParams.value(1));
|
368
|
|
- borderParams = commands->value(i++);
|
369
|
|
- mapAttributes[mapName].insert("border_filepath", borderParams.value(1).replace("\"", ""));
|
|
341
|
+ layout = new MapLayout();
|
|
342
|
+ mapLayouts.insert(map->layout_label, layout);
|
|
343
|
+ layout->name = MapLayout::getNameFromLabel(map->layout_label);
|
|
344
|
+ layout->label = map->layout_label;
|
|
345
|
+ layout->width = layoutValues->value(0);
|
|
346
|
+ layout->height = layoutValues->value(1);
|
|
347
|
+ layout->border_label = layoutValues->value(2);
|
|
348
|
+ layout->blockdata_label = layoutValues->value(3);
|
|
349
|
+ layout->tileset_primary_label = layoutValues->value(4);
|
|
350
|
+ layout->tileset_secondary_label = layoutValues->value(5);
|
|
351
|
+ layout->border_path = layoutValues->value(6);
|
|
352
|
+ layout->blockdata_path = layoutValues->value(7);
|
|
353
|
+ map->layout = layout;
|
|
354
|
+ } else {
|
|
355
|
+ map->layout = mapLayouts[map->layout_label];
|
|
356
|
+ }
|
370
|
357
|
|
371
|
|
- // Read MapBlockData assets.
|
372
|
|
- QStringList blockDataParams = commands->value(i++);
|
373
|
|
- bool isUnknownMapBlockdata = blockDataParams.value(1).startsWith("UnknownMapBlockdata_");
|
374
|
|
- if (blockDataParams.value(0) != ".label" || (!blockDataParams.value(1).endsWith("_MapBlockdata") && !isUnknownMapBlockdata)) {
|
375
|
|
- qDebug() << QString("Expected MapBlockdata label, but found %1").arg(blockDataParams.value(1));
|
376
|
|
- continue;
|
377
|
|
- }
|
378
|
|
- QString blockDataLabel = blockDataParams.value(1);
|
379
|
|
- mapAttributes[mapName].insert("blockdata_label", blockDataLabel);
|
380
|
|
- blockDataParams = commands->value(i++);
|
381
|
|
- mapAttributes[mapName].insert("blockdata_filepath", blockDataParams.value(1).replace("\"", ""));
|
382
|
|
-
|
383
|
|
- // Read MapAttributes assets.
|
384
|
|
- i++; // skip .align
|
385
|
|
- // Maps can share MapAttributes, so gather a list of them.
|
386
|
|
- QStringList attributeMapLabels;
|
387
|
|
- QStringList attributesParams;
|
388
|
|
- QStringList* sharedAttrMaps = new QStringList;
|
389
|
|
- while (i < commands->length()) {
|
390
|
|
- attributesParams = commands->value(i);
|
391
|
|
- if (attributesParams.value(0) != ".label") {
|
392
|
|
- break;
|
393
|
|
- }
|
394
|
|
- QString attrLabel = attributesParams.value(1);
|
395
|
|
- attributeMapLabels.append(attrLabel);
|
396
|
|
- sharedAttrMaps->append(attrLabel);
|
397
|
|
- i++;
|
398
|
|
- }
|
|
358
|
+ getTilesets(map);
|
|
359
|
+ loadBlockdata(map);
|
|
360
|
+ loadMapBorder(map);
|
|
361
|
+}
|
399
|
362
|
|
400
|
|
- // Apply the map attributes to each of the shared maps.
|
401
|
|
- QString attrWidth = commands->value(i++).value(1);
|
402
|
|
- QString attrHeight = commands->value(i++).value(1);
|
403
|
|
- QString attrBorderLabel = commands->value(i++).value(1);
|
404
|
|
- QString attrBlockdataLabel = commands->value(i++).value(1);
|
405
|
|
- QString attrTilesetPrimary = commands->value(i++).value(1);
|
406
|
|
- QString attrTilesetSecondary = commands->value(i++).value(1);
|
407
|
|
- for (QString attributeMapLabel: attributeMapLabels) {
|
408
|
|
- QString altMapName = attributeMapLabel;
|
409
|
|
- if (!altMapName.startsWith("UnknownMapAttributes_")) {
|
410
|
|
- altMapName.remove(altMapName.length() - 14, 14);
|
411
|
|
- }
|
412
|
|
- if (!mapAttributes.contains(altMapName)) {
|
413
|
|
- mapAttributes.insert(altMapName, QMap<QString, QString>());
|
414
|
|
- }
|
415
|
|
- mapAttributes[altMapName].insert("attributes_label", attributeMapLabel);
|
416
|
|
- mapAttributes[altMapName].insert("width", attrWidth);
|
417
|
|
- mapAttributes[altMapName].insert("height", attrHeight);
|
418
|
|
- mapAttributes[altMapName].insert("border_label", attrBorderLabel);
|
419
|
|
- mapAttributes[altMapName].insert("blockdata_label", attrBlockdataLabel);
|
420
|
|
- mapAttributes[altMapName].insert("tileset_primary", attrTilesetPrimary);
|
421
|
|
- mapAttributes[altMapName].insert("tileset_secondary", attrTilesetSecondary);
|
422
|
|
-
|
423
|
|
- if (sharedAttrMaps->length() > 1) {
|
424
|
|
- mapAttributes[altMapName].insert("shared_attr_maps", sharedAttrMaps->join(":"));
|
425
|
|
- }
|
|
363
|
+void Project::readAllMapLayouts() {
|
|
364
|
+ mapLayouts.clear();
|
|
365
|
+
|
|
366
|
+ for (int i = 0; i < mapLayoutsTable.size(); i++) {
|
|
367
|
+ QString layoutLabel = mapLayoutsTable[i];
|
|
368
|
+ QStringList *layoutValues = readLayoutValues(layoutLabel);
|
|
369
|
+ if (layoutValues == NULL) {
|
|
370
|
+ return;
|
426
|
371
|
}
|
|
372
|
+
|
|
373
|
+ MapLayout *layout = new MapLayout();
|
|
374
|
+ layout->name = MapLayout::getNameFromLabel(layoutLabel);
|
|
375
|
+ layout->label = layoutLabel;
|
|
376
|
+ layout->index = i;
|
|
377
|
+ layout->width = layoutValues->value(0);
|
|
378
|
+ layout->height = layoutValues->value(1);
|
|
379
|
+ layout->border_label = layoutValues->value(2);
|
|
380
|
+ layout->blockdata_label = layoutValues->value(3);
|
|
381
|
+ layout->tileset_primary_label = layoutValues->value(4);
|
|
382
|
+ layout->tileset_secondary_label = layoutValues->value(5);
|
|
383
|
+ layout->border_path = layoutValues->value(6);
|
|
384
|
+ layout->blockdata_path = layoutValues->value(7);
|
|
385
|
+ mapLayouts.insert(layoutLabel, layout);
|
427
|
386
|
}
|
428
|
387
|
|
429
|
388
|
// Deep copy
|
430
|
|
- mapAttributesMaster = mapAttributes;
|
431
|
|
- mapAttributesMaster.detach();
|
|
389
|
+ mapLayoutsMaster = mapLayouts;
|
|
390
|
+ mapLayoutsMaster.detach();
|
432
|
391
|
}
|
433
|
392
|
|
434
|
|
-void Project::saveAllMapAttributes() {
|
435
|
|
- QString text = "";
|
436
|
|
- for (int i = 0; i < mapAttributesTableMaster.count(); i++) {
|
437
|
|
- int mapIndex = i + 1;
|
438
|
|
- QString mapName = mapAttributesTableMaster.value(mapIndex);
|
439
|
|
- QMap<QString, QString> attrs = mapAttributesMaster.value(mapName);
|
440
|
|
-
|
441
|
|
- // Find the map attributes object that contains the border data.
|
442
|
|
- QMap<QString, QString> attrsWithBorder;
|
443
|
|
- if (attrs.contains("border_filepath")) {
|
444
|
|
- attrsWithBorder = attrs;
|
445
|
|
- } else {
|
446
|
|
- QStringList labels = attrs.value("shared_attr_maps").split(":");
|
447
|
|
- for (QString label : labels) {
|
448
|
|
- label.remove(label.length() - 14, 14);
|
449
|
|
- if (mapAttributesMaster.contains(label) && mapAttributesMaster.value(label).contains("border_filepath")) {
|
450
|
|
- attrsWithBorder = mapAttributesMaster.value(label);
|
451
|
|
- break;
|
452
|
|
- }
|
453
|
|
- }
|
454
|
|
- }
|
455
|
|
- if (!attrsWithBorder.isEmpty()) {
|
456
|
|
- text += QString("%1::\n").arg(attrsWithBorder.value("border_label"));
|
457
|
|
- text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder.value("border_filepath"));
|
458
|
|
- text += QString("\n");
|
459
|
|
- }
|
460
|
|
-
|
461
|
|
- // Find the map attributes object that contains the blockdata.
|
462
|
|
- QMap<QString, QString> attrsWithBlockdata;
|
463
|
|
- if (attrs.contains("blockdata_filepath")) {
|
464
|
|
- attrsWithBlockdata = attrs;
|
465
|
|
- } else {
|
466
|
|
- QStringList labels = attrs["shared_attr_maps"].split(":");
|
467
|
|
- for (QString label : labels) {
|
468
|
|
- label.remove(label.length() - 14, 14);
|
469
|
|
- if (mapAttributesMaster.contains(label) && mapAttributesMaster.value(label).contains("blockdata_filepath")) {
|
470
|
|
- attrsWithBlockdata = mapAttributesMaster.value(label);
|
471
|
|
- break;
|
472
|
|
- }
|
473
|
|
- }
|
474
|
|
- }
|
475
|
|
- if (!attrsWithBlockdata.isEmpty()) {
|
476
|
|
- text += QString("%1::\n").arg(attrsWithBlockdata.value("blockdata_label"));
|
477
|
|
- text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder.value("blockdata_filepath"));
|
478
|
|
- text += QString("\n");
|
479
|
|
- }
|
480
|
|
-
|
|
393
|
+void Project::saveAllMapLayouts() {
|
|
394
|
+ for (QString layoutName : mapLayoutsTableMaster) {
|
|
395
|
+ MapLayout *layout = mapLayouts.value(layoutName);
|
|
396
|
+ QString text = QString("%1::\n").arg(layout->border_label);
|
|
397
|
+ text += QString("\t.incbin \"%1\"\n").arg(layout->border_path);
|
|
398
|
+ text += QString("\n");
|
|
399
|
+ text += QString("%1::\n").arg(layout->blockdata_label);
|
|
400
|
+ text += QString("\t.incbin \"%1\"\n").arg(layout->blockdata_path);
|
|
401
|
+ text += QString("\n");
|
481
|
402
|
text += QString("\t.align 2\n");
|
482
|
|
- if (attrs.contains("shared_attr_maps")) {
|
483
|
|
- QStringList labels = attrs.value("shared_attr_maps").split(":");
|
484
|
|
- for (QString label : labels) {
|
485
|
|
- text += QString("%1::\n").arg(label);
|
486
|
|
- }
|
487
|
|
- } else {
|
488
|
|
- text += QString("%1::\n").arg(attrs.value("attributes_label"));
|
489
|
|
- }
|
490
|
|
- text += QString("\t.4byte %1\n").arg(attrs.value("width"));
|
491
|
|
- text += QString("\t.4byte %1\n").arg(attrs.value("height"));
|
492
|
|
- text += QString("\t.4byte %1\n").arg(attrs.value("border_label"));
|
493
|
|
- text += QString("\t.4byte %1\n").arg(attrs.value("blockdata_label"));
|
494
|
|
- text += QString("\t.4byte %1\n").arg(attrs.value("tileset_primary"));
|
495
|
|
- text += QString("\t.4byte %1\n").arg(attrs.value("tileset_secondary"));
|
|
403
|
+ text += QString("%1::\n").arg(layoutName);
|
|
404
|
+ text += QString("\t.4byte %1\n").arg(layout->width);
|
|
405
|
+ text += QString("\t.4byte %1\n").arg(layout->height);
|
|
406
|
+ text += QString("\t.4byte %1\n").arg(layout->border_label);
|
|
407
|
+ text += QString("\t.4byte %1\n").arg(layout->blockdata_label);
|
|
408
|
+ text += QString("\t.4byte %1\n").arg(layout->tileset_primary_label);
|
|
409
|
+ text += QString("\t.4byte %1\n").arg(layout->tileset_secondary_label);
|
496
|
410
|
text += QString("\n");
|
|
411
|
+ saveTextFile(getMapLayoutFilepath(layout->label), text);
|
497
|
412
|
}
|
498
|
|
-
|
499
|
|
- saveTextFile(getMapAssetsFilepath(), text);
|
500
|
413
|
}
|
501
|
414
|
|
502
|
|
-QString Project::getMapAssetsFilepath() {
|
503
|
|
- return root + "/data/maps/_assets.inc";
|
|
415
|
+QString Project::getMapLayoutFilepath(QString layoutLabel) {
|
|
416
|
+ return QString("%1/data/layouts/%2/layout.inc").arg(root).arg(MapLayout::getNameFromLabel(layoutLabel));
|
504
|
417
|
}
|
505
|
418
|
|
506
|
|
-void Project::setNewMapAttributes(Map* map) {
|
507
|
|
- map->width = "20";
|
508
|
|
- map->height = "20";
|
509
|
|
- map->border_label = QString("%1_MapBorder").arg(map->name);
|
510
|
|
- map->blockdata_label = QString("%1_MapBlockdata").arg(map->name);
|
511
|
|
- map->tileset_primary_label = "gTileset_General";
|
512
|
|
- map->tileset_secondary_label = "gTileset_Petalburg";
|
|
419
|
+void Project::setNewMapLayout(Map* map) {
|
|
420
|
+ MapLayout *layout = new MapLayout();
|
|
421
|
+ layout->label = QString("%1_Layout").arg(map->name);
|
|
422
|
+ layout->name = MapLayout::getNameFromLabel(layout->label);
|
|
423
|
+ layout->width = "20";
|
|
424
|
+ layout->height = "20";
|
|
425
|
+ layout->border_label = QString("%1_MapBorder").arg(map->name);
|
|
426
|
+ layout->border_path = QString("data/layouts/%1/border.bin").arg(map->name);
|
|
427
|
+ layout->blockdata_label = QString("%1_MapBlockdata").arg(map->name);
|
|
428
|
+ layout->blockdata_path = QString("data/layouts/%1/map.bin").arg(map->name);
|
|
429
|
+ layout->tileset_primary_label = "gTileset_General";
|
|
430
|
+ layout->tileset_secondary_label = "gTileset_Petalburg";
|
|
431
|
+ map->layout = layout;
|
|
432
|
+ map->layout_label = layout->label;
|
513
|
433
|
|
514
|
|
- // Insert new entry into the global map attributes.
|
515
|
|
- QMap<QString, QString> attrs;
|
516
|
|
- attrs.insert("border_label", QString("%1_MapBorder").arg(map->name));
|
517
|
|
- attrs.insert("border_filepath", QString("data/maps/%1/border.bin").arg(map->name));
|
518
|
|
- attrs.insert("blockdata_label", QString("%1_MapBlockdata").arg(map->name));
|
519
|
|
- attrs.insert("blockdata_filepath", QString("data/maps/%1/map.bin").arg(map->name));
|
520
|
|
- attrs.insert("attributes_label", QString("%1_MapAttributes").arg(map->name));
|
521
|
|
- attrs.insert("width", map->width);
|
522
|
|
- attrs.insert("height", map->height);
|
523
|
|
- attrs.insert("tileset_primary", map->tileset_primary_label);
|
524
|
|
- attrs.insert("tileset_secondary", map->tileset_secondary_label);
|
525
|
|
- mapAttributes.insert(map->name, attrs);
|
|
434
|
+ // Insert new entry into the global map layouts.
|
|
435
|
+ mapLayouts.insert(layout->label, layout);
|
|
436
|
+ mapLayoutsTable.append(layout->label);
|
526
|
437
|
}
|
527
|
438
|
|
528
|
439
|
void Project::saveMapGroupsTable() {
|
|
@@ -544,7 +455,7 @@ void Project::saveMapGroupsTable() {
|
544
|
455
|
text += QString("\t.4byte gMapGroup%1\n").arg(i);
|
545
|
456
|
}
|
546
|
457
|
|
547
|
|
- saveTextFile(root + "/data/maps/_groups.inc", text);
|
|
458
|
+ saveTextFile(root + "/data/maps/groups.inc", text);
|
548
|
459
|
}
|
549
|
460
|
|
550
|
461
|
void Project::saveMapConstantsHeader() {
|
|
@@ -585,8 +496,12 @@ void Project::saveMapConstantsHeader() {
|
585
|
496
|
}
|
586
|
497
|
|
587
|
498
|
void Project::getTilesets(Map* map) {
|
588
|
|
- map->tileset_primary = getTileset(map->tileset_primary_label);
|
589
|
|
- map->tileset_secondary = getTileset(map->tileset_secondary_label);
|
|
499
|
+ if (map->layout->has_unsaved_changes) {
|
|
500
|
+ return;
|
|
501
|
+ }
|
|
502
|
+
|
|
503
|
+ map->layout->tileset_primary = getTileset(map->layout->tileset_primary_label);
|
|
504
|
+ map->layout->tileset_secondary = getTileset(map->layout->tileset_secondary_label);
|
590
|
505
|
}
|
591
|
506
|
|
592
|
507
|
Tileset* Project::loadTileset(QString label) {
|
|
@@ -611,37 +526,13 @@ Tileset* Project::loadTileset(QString label) {
|
611
|
526
|
return tileset;
|
612
|
527
|
}
|
613
|
528
|
|
614
|
|
-QString Project::getBlockdataPath(Map* map) {
|
615
|
|
- QString text = readTextFile(getMapAssetsFilepath());
|
616
|
|
- QStringList *values = getLabelValues(parseAsm(text), map->blockdata_label);
|
617
|
|
- QString path;
|
618
|
|
- if (!values->isEmpty()) {
|
619
|
|
- path = root + "/" + values->value(0).section('"', 1, 1);
|
620
|
|
- } else {
|
621
|
|
- path = root + "/data/maps/" + map->name + "/map.bin";
|
622
|
|
- }
|
623
|
|
- return path;
|
624
|
|
-}
|
625
|
|
-
|
626
|
|
-QString Project::getMapBorderPath(Map *map) {
|
627
|
|
- QString text = readTextFile(getMapAssetsFilepath());
|
628
|
|
- QStringList *values = getLabelValues(parseAsm(text), map->border_label);
|
629
|
|
- QString path;
|
630
|
|
- if (!values->isEmpty()) {
|
631
|
|
- path = root + "/" + values->value(0).section('"', 1, 1);
|
632
|
|
- } else {
|
633
|
|
- path = root + "/data/maps/" + map->name + "/border.bin";
|
634
|
|
- }
|
635
|
|
- return path;
|
636
|
|
-}
|
637
|
|
-
|
638
|
529
|
void Project::loadBlockdata(Map* map) {
|
639
|
|
- if (!map->isPersistedToFile) {
|
|
530
|
+ if (!map->isPersistedToFile || map->layout->has_unsaved_changes) {
|
640
|
531
|
return;
|
641
|
532
|
}
|
642
|
533
|
|
643
|
|
- QString path = getBlockdataPath(map);
|
644
|
|
- map->blockdata = readBlockdata(path);
|
|
534
|
+ QString path = QString("%1/%2").arg(root).arg(map->layout->blockdata_path);
|
|
535
|
+ map->layout->blockdata = readBlockdata(path);
|
645
|
536
|
}
|
646
|
537
|
|
647
|
538
|
void Project::setNewMapBlockdata(Map* map) {
|
|
@@ -649,16 +540,16 @@ void Project::setNewMapBlockdata(Map* map) {
|
649
|
540
|
for (int i = 0; i < map->getWidth() * map->getHeight(); i++) {
|
650
|
541
|
blockdata->addBlock(qint16(0x3001));
|
651
|
542
|
}
|
652
|
|
- map->blockdata = blockdata;
|
|
543
|
+ map->layout->blockdata = blockdata;
|
653
|
544
|
}
|
654
|
545
|
|
655
|
546
|
void Project::loadMapBorder(Map *map) {
|
656
|
|
- if (!map->isPersistedToFile) {
|
|
547
|
+ if (!map->isPersistedToFile || map->layout->has_unsaved_changes) {
|
657
|
548
|
return;
|
658
|
549
|
}
|
659
|
550
|
|
660
|
|
- QString path = getMapBorderPath(map);
|
661
|
|
- map->border = readBlockdata(path);
|
|
551
|
+ QString path = QString("%1/%2").arg(root).arg(map->layout->border_path);
|
|
552
|
+ map->layout->border = readBlockdata(path);
|
662
|
553
|
}
|
663
|
554
|
|
664
|
555
|
void Project::setNewMapBorder(Map *map) {
|
|
@@ -667,17 +558,17 @@ void Project::setNewMapBorder(Map *map) {
|
667
|
558
|
blockdata->addBlock(qint16(0x01D5));
|
668
|
559
|
blockdata->addBlock(qint16(0x01DC));
|
669
|
560
|
blockdata->addBlock(qint16(0x01DD));
|
670
|
|
- map->border = blockdata;
|
|
561
|
+ map->layout->border = blockdata;
|
671
|
562
|
}
|
672
|
563
|
|
673
|
564
|
void Project::saveMapBorder(Map *map) {
|
674
|
|
- QString path = getMapBorderPath(map);
|
675
|
|
- writeBlockdata(path, map->border);
|
|
565
|
+ QString path = QString("%1/%2").arg(root).arg(map->layout->border_path);
|
|
566
|
+ writeBlockdata(path, map->layout->border);
|
676
|
567
|
}
|
677
|
568
|
|
678
|
569
|
void Project::saveBlockdata(Map* map) {
|
679
|
|
- QString path = getBlockdataPath(map);
|
680
|
|
- writeBlockdata(path, map->blockdata);
|
|
570
|
+ QString path = QString("%1/%2").arg(root).arg(map->layout->blockdata_path);
|
|
571
|
+ writeBlockdata(path, map->layout->blockdata);
|
681
|
572
|
map->history.save();
|
682
|
573
|
}
|
683
|
574
|
|
|
@@ -686,6 +577,8 @@ void Project::writeBlockdata(QString path, Blockdata *blockdata) {
|
686
|
577
|
if (file.open(QIODevice::WriteOnly)) {
|
687
|
578
|
QByteArray data = blockdata->serialize();
|
688
|
579
|
file.write(data);
|
|
580
|
+ } else {
|
|
581
|
+ qDebug() << "Failed to open blockdata file for writing: '" << path << "'";
|
689
|
582
|
}
|
690
|
583
|
}
|
691
|
584
|
|
|
@@ -706,26 +599,35 @@ void Project::saveMap(Map *map) {
|
706
|
599
|
qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
|
707
|
600
|
}
|
708
|
601
|
|
|
602
|
+ QString newLayoutDir = QString(root + "/data/layouts/%1").arg(map->name);
|
|
603
|
+ if (!QDir::root().mkdir(newLayoutDir)) {
|
|
604
|
+ qDebug() << "Error: failed to create directory for new layout. " << newLayoutDir;
|
|
605
|
+ }
|
|
606
|
+
|
709
|
607
|
// TODO: In the future, these files needs more structure to allow for proper parsing/saving.
|
710
|
|
- // Create file data/scripts/maps/<map_name>.inc
|
|
608
|
+ // Create file data/maps/<map_name>/scripts.inc
|
711
|
609
|
QString text = QString("%1_MapScripts::\n\t.byte 0\n").arg(map->name);
|
712
|
|
- saveTextFile(root + "/data/scripts/maps/" + map->name + ".inc", text);
|
|
610
|
+ saveTextFile(root + "/data/maps/" + map->name + "/scripts.inc", text);
|
713
|
611
|
|
714
|
|
- // Create file data/text/maps/<map_name>.inc
|
715
|
|
- saveTextFile(root + "/data/text/maps/" + map->name + ".inc", "\n");
|
|
612
|
+ // Create file data/maps/<map_name>/text.inc
|
|
613
|
+ saveTextFile(root + "/data/maps/" + map->name + "/text.inc", "\n");
|
716
|
614
|
|
717
|
615
|
// Simply append to data/event_scripts.s.
|
718
|
|
- text = QString("\n\t.include \"data/scripts/maps/%1.inc\"\n").arg(map->name);
|
719
|
|
- text += QString("\t.include \"data/text/maps/%1.inc\"\n").arg(map->name);
|
|
616
|
+ text = QString("\n\t.include \"data/maps/%1/scripts.inc\"\n").arg(map->name);
|
|
617
|
+ text += QString("\t.include \"data/maps/%1/text.inc\"\n").arg(map->name);
|
720
|
618
|
appendTextFile(root + "/data/event_scripts.s", text);
|
721
|
619
|
|
722
|
620
|
// Simply append to data/map_events.s.
|
723
|
|
- text = QString("\n\t.include \"data/maps/events/%1.inc\"\n").arg(map->name);
|
|
621
|
+ text = QString("\n\t.include \"data/maps/%1/events.inc\"\n").arg(map->name);
|
724
|
622
|
appendTextFile(root + "/data/map_events.s", text);
|
725
|
623
|
|
726
|
624
|
// Simply append to data/maps/headers.inc.
|
727
|
625
|
text = QString("\t.include \"data/maps/%1/header.inc\"\n").arg(map->name);
|
728
|
626
|
appendTextFile(root + "/data/maps/headers.inc", text);
|
|
627
|
+
|
|
628
|
+ // Simply append to data/layouts.inc.
|
|
629
|
+ text = QString("\t.include \"data/layouts/%1/layout.inc\"\n").arg(map->layout->name);
|
|
630
|
+ appendTextFile(root + "/data/layouts.inc", text);
|
729
|
631
|
}
|
730
|
632
|
|
731
|
633
|
saveMapBorder(map);
|
|
@@ -735,25 +637,27 @@ void Project::saveMap(Map *map) {
|
735
|
637
|
saveMapEvents(map);
|
736
|
638
|
|
737
|
639
|
// Update global data structures with current map data.
|
738
|
|
- updateMapAttributes(map);
|
|
640
|
+ updateMapLayout(map);
|
739
|
641
|
|
740
|
642
|
map->isPersistedToFile = true;
|
|
643
|
+ map->layout->has_unsaved_changes = false;
|
741
|
644
|
}
|
742
|
645
|
|
743
|
|
-void Project::updateMapAttributes(Map* map) {
|
744
|
|
- if (!mapAttributesTableMaster.contains(map->index.toInt())) {
|
745
|
|
- mapAttributesTableMaster.insert(map->index.toInt(), map->name);
|
|
646
|
+void Project::updateMapLayout(Map* map) {
|
|
647
|
+ if (!mapLayoutsTableMaster.contains(map->layout_label)) {
|
|
648
|
+ mapLayoutsTableMaster.append(map->layout_label);
|
746
|
649
|
}
|
747
|
650
|
|
748
|
651
|
// Deep copy
|
749
|
|
- QMap<QString, QString> attrs = mapAttributes.value(map->name);
|
750
|
|
- attrs.detach();
|
751
|
|
- mapAttributesMaster.insert(map->name, attrs);
|
|
652
|
+ MapLayout *layout = mapLayouts.value(map->layout_label);
|
|
653
|
+ MapLayout *newLayout = new MapLayout();
|
|
654
|
+ *newLayout = *layout;
|
|
655
|
+ mapLayoutsMaster.insert(map->layout_label, newLayout);
|
752
|
656
|
}
|
753
|
657
|
|
754
|
658
|
void Project::saveAllDataStructures() {
|
755
|
|
- saveMapAttributesTable();
|
756
|
|
- saveAllMapAttributes();
|
|
659
|
+ saveMapLayoutsTable();
|
|
660
|
+ saveAllMapLayouts();
|
757
|
661
|
saveMapGroupsTable();
|
758
|
662
|
saveMapConstantsHeader();
|
759
|
663
|
saveMapsWithConnections();
|
|
@@ -828,7 +732,6 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
828
|
732
|
tileset->tiles = tiles;
|
829
|
733
|
|
830
|
734
|
// metatiles
|
831
|
|
- //qDebug() << metatiles_path;
|
832
|
735
|
QFile metatiles_file(metatiles_path);
|
833
|
736
|
if (metatiles_file.open(QIODevice::ReadOnly)) {
|
834
|
737
|
QByteArray data = metatiles_file.readAll();
|
|
@@ -895,9 +798,9 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
895
|
798
|
for (int j = 0; j < 16; j++) {
|
896
|
799
|
palette.append(qRgb(j * 16, j * 16, j * 16));
|
897
|
800
|
}
|
898
|
|
- qDebug() << QString("Could not open '%1'").arg(path);
|
|
801
|
+ qDebug() << QString("Could not open palette path '%1'").arg(path);
|
899
|
802
|
}
|
900
|
|
- //qDebug() << path;
|
|
803
|
+
|
901
|
804
|
palettes->append(palette);
|
902
|
805
|
}
|
903
|
806
|
tileset->palettes = palettes;
|
|
@@ -905,7 +808,6 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
905
|
808
|
|
906
|
809
|
Blockdata* Project::readBlockdata(QString path) {
|
907
|
810
|
Blockdata *blockdata = new Blockdata;
|
908
|
|
- //qDebug() << path;
|
909
|
811
|
QFile file(path);
|
910
|
812
|
if (file.open(QIODevice::ReadOnly)) {
|
911
|
813
|
QByteArray data = file.readAll();
|
|
@@ -913,7 +815,10 @@ Blockdata* Project::readBlockdata(QString path) {
|
913
|
815
|
uint16_t word = (data[i] & 0xff) + ((data[i + 1] & 0xff) << 8);
|
914
|
816
|
blockdata->addBlock(word);
|
915
|
817
|
}
|
|
818
|
+ } else {
|
|
819
|
+ qDebug() << "Failed to open blockdata path '" << path << "'";
|
916
|
820
|
}
|
|
821
|
+
|
917
|
822
|
return blockdata;
|
918
|
823
|
}
|
919
|
824
|
|
|
@@ -976,7 +881,7 @@ void Project::deleteFile(QString path) {
|
976
|
881
|
}
|
977
|
882
|
|
978
|
883
|
void Project::readMapGroups() {
|
979
|
|
- QString text = readTextFile(root + "/data/maps/_groups.inc");
|
|
884
|
+ QString text = readTextFile(root + "/data/maps/groups.inc");
|
980
|
885
|
if (text.isNull()) {
|
981
|
886
|
return;
|
982
|
887
|
}
|
|
@@ -1039,9 +944,6 @@ void Project::readMapGroups() {
|
1039
|
944
|
}
|
1040
|
945
|
|
1041
|
946
|
Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
1042
|
|
- int mapIndex = mapAttributesTable.count() + 1;
|
1043
|
|
- mapAttributesTable.insert(mapIndex, mapName);
|
1044
|
|
-
|
1045
|
947
|
// Setup new map in memory, but don't write to file until map is actually saved later.
|
1046
|
948
|
mapNames->append(mapName);
|
1047
|
949
|
map_groups->insert(mapName, groupNum);
|
|
@@ -1052,8 +954,8 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
1052
|
954
|
map->setName(mapName);
|
1053
|
955
|
mapConstantsToMapNames->insert(map->constantName, map->name);
|
1054
|
956
|
mapNamesToMapConstants->insert(map->name, map->constantName);
|
1055
|
|
- setNewMapHeader(map, mapIndex);
|
1056
|
|
- setNewMapAttributes(map);
|
|
957
|
+ setNewMapHeader(map, mapLayoutsTable.size() + 1);
|
|
958
|
+ setNewMapLayout(map);
|
1057
|
959
|
getTilesets(map);
|
1058
|
960
|
setNewMapBlockdata(map);
|
1059
|
961
|
setNewMapBorder(map);
|
|
@@ -1283,7 +1185,7 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
|
1283
|
1185
|
}
|
1284
|
1186
|
|
1285
|
1187
|
void Project::saveMapEvents(Map *map) {
|
1286
|
|
- QString path = root + QString("/data/maps/events/%1.inc").arg(map->name);
|
|
1188
|
+ QString path = root + QString("/data/maps/%1/events.inc").arg(map->name);
|
1287
|
1189
|
QString text = "";
|
1288
|
1190
|
|
1289
|
1191
|
if (map->events["object"].length() > 0) {
|
|
@@ -1397,7 +1299,7 @@ void Project::readMapEvents(Map *map) {
|
1397
|
1299
|
}
|
1398
|
1300
|
|
1399
|
1301
|
// lazy
|
1400
|
|
- QString path = root + QString("/data/maps/events/%1.inc").arg(map->name);
|
|
1302
|
+ QString path = root + QString("/data/maps/%1/events.inc").arg(map->name);
|
1401
|
1303
|
QString text = readTextFile(path);
|
1402
|
1304
|
if (text.isNull()) {
|
1403
|
1305
|
return;
|