Преглед изворни кода

Maintain master and working copies of data structures, to enable saving single maps at a time

Marcus Huderle пре 6 година
родитељ
комит
e4c5d53ffd
4 измењених фајлова са 116 додато и 224 уклоњено
  1. 2
    1
      editor.cpp
  2. 14
    12
      mainwindow.cpp
  3. 91
    205
      project.cpp
  4. 9
    6
      project.h

+ 2
- 1
editor.cpp Прегледај датотеку

@@ -9,14 +9,15 @@ Editor::Editor()
9 9
 
10 10
 void Editor::saveProject() {
11 11
     if (project) {
12
-        project->saveAllDataStructures();
13 12
         project->saveAllMaps();
13
+        project->saveAllDataStructures();
14 14
     }
15 15
 }
16 16
 
17 17
 void Editor::save() {
18 18
     if (project && map) {
19 19
         project->saveMap(map);
20
+        project->saveAllDataStructures();
20 21
     }
21 22
 }
22 23
 

+ 14
- 12
mainwindow.cpp Прегледај датотеку

@@ -73,26 +73,26 @@ void MainWindow::openProject(QString dir) {
73 73
 
74 74
 QString MainWindow::getDefaultMap() {
75 75
     if (editor && editor->project) {
76
-        QList<QStringList*> *names = editor->project->groupedMapNames;
77
-        if (names) {
76
+        QList<QStringList> names = editor->project->groupedMapNames;
77
+        if (!names.isEmpty()) {
78 78
             QSettings settings;
79 79
             QString key = "project:" + editor->project->root;
80 80
             if (settings.contains(key)) {
81 81
                 QMap<QString, QVariant> qmap = settings.value(key).toMap();
82 82
                 if (qmap.contains("recent_map")) {
83 83
                     QString map_name = qmap.value("recent_map").toString();
84
-                    for (int i = 0; i < names->length(); i++) {
85
-                        if (names->value(i)->contains(map_name)) {
84
+                    for (int i = 0; i < names.length(); i++) {
85
+                        if (names.value(i).contains(map_name)) {
86 86
                             return map_name;
87 87
                         }
88 88
                     }
89 89
                 }
90 90
             }
91 91
             // Failing that, just get the first map in the list.
92
-            for (int i = 0; i < names->length(); i++) {
93
-                QStringList *list = names->value(i);
94
-                if (list->length()) {
95
-                    return list->value(0);
92
+            for (int i = 0; i < names.length(); i++) {
93
+                QStringList list = names.value(i);
94
+                if (list.length()) {
95
+                    return list.value(0);
96 96
                 }
97 97
             }
98 98
         }
@@ -327,9 +327,9 @@ void MainWindow::populateMapList() {
327 327
         group->setData(i, MapListUserRoles::GroupRole);
328 328
         maps->appendRow(group);
329 329
         mapGroupsModel->append(group);
330
-        QStringList *names = project->groupedMapNames->value(i);
331
-        for (int j = 0; j < names->length(); j++) {
332
-            QString map_name = names->value(j);
330
+        QStringList names = project->groupedMapNames.value(i);
331
+        for (int j = 0; j < names.length(); j++) {
332
+            QString map_name = names.value(j);
333 333
             QStandardItem *map = createMapItem(map_name, i, j);
334 334
             group->appendRow(map);
335 335
         }
@@ -387,7 +387,9 @@ void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
387 387
     QStandardItem* groupItem = mapGroupsModel->at(groupNum);
388 388
 
389 389
     QString newMapName = editor->project->getNewMapName();
390
-    editor->project->addNewMapToGroup(newMapName, groupNum);
390
+    Map* newMap = editor->project->addNewMapToGroup(newMapName, groupNum);
391
+    editor->project->saveMap(newMap);
392
+    editor->project->saveAllDataStructures();
391 393
 
392 394
     int numMapsInGroup = groupItem->rowCount();
393 395
     QStandardItem *newMapItem = createMapItem(newMapName, groupNum, numMapsInGroup);

+ 91
- 205
project.cpp Прегледај датотеку

@@ -17,13 +17,10 @@ Project::Project()
17 17
 {
18 18
     groupNames = new QStringList;
19 19
     map_groups = new QMap<QString, int>;
20
-    groupedMapNames = new QList<QStringList*>;
21 20
     mapNames = new QStringList;
22 21
     map_cache = new QMap<QString, Map*>;
23 22
     mapConstantsToMapNames = new QMap<QString, QString>;
24 23
     mapNamesToMapConstants = new QMap<QString, QString>;
25
-    mapAttributesTable = new QMap<int, QString>;
26
-    mapAttributes = new QMap<QString, QMap<QString, QString>*>;
27 24
     tileset_cache = new QMap<QString, Tileset*>;
28 25
 }
29 26
 
@@ -36,10 +33,12 @@ QString Project::getProjectTitle() {
36 33
 }
37 34
 
38 35
 Map* Project::loadMap(QString map_name) {
39
-    // New maps are saved to actual files yet, so we need to fetch their data from the map_cache.
40 36
     Map *map;
41
-    if (map_cache->contains(map_name) && !map_cache->value(map_name)->isPersistedToFile) {
37
+    if (map_cache->contains(map_name)) {
42 38
         map = map_cache->value(map_name);
39
+        if (map->hasUnsavedChanges()) {
40
+            return map;
41
+        }
43 42
     } else {
44 43
         map = new Map;
45 44
         map->setName(map_name);
@@ -228,19 +227,22 @@ void Project::readMapAttributesTable() {
228 227
                 // Strip off "_MapAttributes" from the label if it's a real map label.
229 228
                 mapName = mapName.remove(mapName.length() - 14, 14);
230 229
             }
231
-            mapAttributesTable->insert(curMapIndex, mapName);
230
+            mapAttributesTable.insert(curMapIndex, mapName);
232 231
             curMapIndex++;
233 232
         }
234 233
     }
234
+
235
+    mapAttributesTableMaster = mapAttributesTable;
236
+    mapAttributesTableMaster.detach();
235 237
 }
236 238
 
237 239
 void Project::saveMapAttributesTable() {
238 240
     QString text = "";
239 241
     text += QString("\t.align 2\n");
240 242
     text += QString("gMapAttributes::\n");
241
-    for (int i = 0; i < mapAttributesTable->count(); i++) {
243
+    for (int i = 0; i < mapAttributesTableMaster.count(); i++) {
242 244
         int mapIndex = i + 1;
243
-        QString mapName = mapAttributesTable->value(mapIndex);
245
+        QString mapName = mapAttributesTableMaster.value(mapIndex);
244 246
         if (!mapName.contains("UnknownMapAttributes")) {
245 247
             text += QString("\t.4byte %1_MapAttributes\n").arg(mapName);
246 248
         } else {
@@ -275,7 +277,7 @@ void Project::readMapAttributes(Map* map) {
275 277
 }
276 278
 
277 279
 void Project::readAllMapAttributes() {
278
-    mapAttributes->clear();
280
+    mapAttributes.clear();
279 281
 
280 282
     Asm *parser = new Asm;
281 283
     QString assets_text = readTextFile(getMapAssetsFilepath());
@@ -307,11 +309,9 @@ void Project::readAllMapAttributes() {
307 309
             mapName = borderLabel.replace("Border", "Attributes");
308 310
         }
309 311
 
310
-        QMap<QString, QString>* attrs = new QMap<QString, QString>;
311
-        mapAttributes->insert(mapName, attrs);
312
-        attrs->insert("border_label", borderParams.value(1));
312
+        mapAttributes[mapName].insert("border_label", borderParams.value(1));
313 313
         borderParams = commands->value(i++);
314
-        attrs->insert("border_filepath", borderParams.value(1).replace("\"", ""));
314
+        mapAttributes[mapName].insert("border_filepath", borderParams.value(1).replace("\"", ""));
315 315
 
316 316
         // Read MapBlockData assets.
317 317
         QStringList blockDataParams = commands->value(i++);
@@ -321,9 +321,9 @@ void Project::readAllMapAttributes() {
321 321
             continue;
322 322
         }
323 323
         QString blockDataLabel = blockDataParams.value(1);
324
-        attrs->insert("blockdata_label", blockDataLabel);
324
+        mapAttributes[mapName].insert("blockdata_label", blockDataLabel);
325 325
         blockDataParams = commands->value(i++);
326
-        attrs->insert("blockdata_filepath", blockDataParams.value(1).replace("\"", ""));
326
+        mapAttributes[mapName].insert("blockdata_filepath", blockDataParams.value(1).replace("\"", ""));
327 327
 
328 328
         // Read MapAttributes assets.
329 329
         i++; // skip .align
@@ -354,86 +354,90 @@ void Project::readAllMapAttributes() {
354 354
             if (!altMapName.startsWith("UnknownMapAttributes_")) {
355 355
                 altMapName.remove(altMapName.length() - 14, 14);
356 356
             }
357
-            if (!mapAttributes->contains(altMapName)) {
358
-                mapAttributes->insert(altMapName, new QMap<QString, QString>);
357
+            if (!mapAttributes.contains(altMapName)) {
358
+                mapAttributes.insert(altMapName, QMap<QString, QString>());
359 359
             }
360
-            mapAttributes->value(altMapName)->insert("attributes_label", attributeMapLabel);
361
-            mapAttributes->value(altMapName)->insert("width", attrWidth);
362
-            mapAttributes->value(altMapName)->insert("height", attrHeight);
363
-            mapAttributes->value(altMapName)->insert("border_label", attrBorderLabel);
364
-            mapAttributes->value(altMapName)->insert("blockdata_label", attrBlockdataLabel);
365
-            mapAttributes->value(altMapName)->insert("tileset_primary", attrTilesetPrimary);
366
-            mapAttributes->value(altMapName)->insert("tileset_secondary", attrTilesetSecondary);
360
+            mapAttributes[altMapName]["attributes_label"] = attributeMapLabel;
361
+            mapAttributes[altMapName].insert("attributes_label", attributeMapLabel);
362
+            mapAttributes[altMapName].insert("width", attrWidth);
363
+            mapAttributes[altMapName].insert("height", attrHeight);
364
+            mapAttributes[altMapName].insert("border_label", attrBorderLabel);
365
+            mapAttributes[altMapName].insert("blockdata_label", attrBlockdataLabel);
366
+            mapAttributes[altMapName].insert("tileset_primary", attrTilesetPrimary);
367
+            mapAttributes[altMapName].insert("tileset_secondary", attrTilesetSecondary);
367 368
 
368 369
             if (sharedAttrMaps->length() > 1) {
369
-                mapAttributes->value(altMapName)->insert("shared_attr_maps", sharedAttrMaps->join(":"));
370
+                mapAttributes[altMapName].insert("shared_attr_maps", sharedAttrMaps->join(":"));
370 371
             }
371 372
         }
372 373
     }
374
+
375
+    mapAttributesMaster = mapAttributes;
376
+    mapAttributesMaster.detach();
373 377
 }
374 378
 
375 379
 void Project::saveAllMapAttributes() {
376 380
     QString text = "";
377
-    for (int i = 0; i < mapAttributesTable->count(); i++) {
381
+    for (int i = 0; i < mapAttributesTableMaster.count(); i++) {
378 382
         int mapIndex = i + 1;
379
-        QString mapName = mapAttributesTable->value(mapIndex);
380
-        QMap<QString, QString>* attrs = mapAttributes->value(mapName);
383
+        QString mapName = mapAttributesTableMaster.value(mapIndex);
384
+        QMap<QString, QString> attrs = mapAttributesMaster.value(mapName);
381 385
 
382 386
         // Find the map attributes object that contains the border data.
383
-        QMap<QString, QString>* attrsWithBorder;
384
-        if (attrs->contains("border_filepath")) {
387
+        QMap<QString, QString> attrsWithBorder;
388
+        if (attrs.contains("border_filepath")) {
385 389
             attrsWithBorder = attrs;
386 390
         } else {
387
-            QStringList labels = attrs->value("shared_attr_maps").split(":");
391
+            QStringList labels = attrs.value("shared_attr_maps").split(":");
388 392
             for (QString label : labels) {
389 393
                 label.remove(label.length() - 14, 14);
390
-                if (mapAttributes->contains(label) && mapAttributes->value(label)->contains("border_filepath")) {
391
-                    attrsWithBorder = mapAttributes->value(label);
394
+                if (mapAttributesMaster.contains(label) && mapAttributesMaster.value(label).contains("border_filepath")) {
395
+                    attrsWithBorder = mapAttributesMaster.value(label);
392 396
                     break;
393 397
                 }
394 398
             }
395 399
         }
396
-        if (attrsWithBorder != nullptr) {
397
-            text += QString("%1::\n").arg(attrsWithBorder->value("border_label"));
398
-            text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder->value("border_filepath"));
400
+        if (!attrsWithBorder.isEmpty()) {
401
+            text += QString("%1::\n").arg(attrsWithBorder.value("border_label"));
402
+            text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder.value("border_filepath"));
399 403
             text += QString("\n");
400 404
         }
401 405
 
402 406
         // Find the map attributes object that contains the blockdata.
403
-        QMap<QString, QString>* attrsWithBlockdata;
404
-        if (attrs->contains("blockdata_filepath")) {
407
+        QMap<QString, QString> attrsWithBlockdata;
408
+        if (attrs.contains("blockdata_filepath")) {
405 409
             attrsWithBlockdata = attrs;
406 410
         } else {
407
-            QStringList labels = attrs->value("shared_attr_maps").split(":");
411
+            QStringList labels = attrs["shared_attr_maps"].split(":");
408 412
             for (QString label : labels) {
409 413
                 label.remove(label.length() - 14, 14);
410
-                if (mapAttributes->contains(label) && mapAttributes->value(label)->contains("blockdata_filepath")) {
411
-                    attrsWithBlockdata = mapAttributes->value(label);
414
+                if (mapAttributesMaster.contains(label) && mapAttributesMaster.value(label).contains("blockdata_filepath")) {
415
+                    attrsWithBlockdata = mapAttributesMaster.value(label);
412 416
                     break;
413 417
                 }
414 418
             }
415 419
         }
416
-        if (attrsWithBlockdata != nullptr) {
417
-            text += QString("%1::\n").arg(attrsWithBlockdata->value("blockdata_label"));
418
-            text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder->value("blockdata_filepath"));
420
+        if (!attrsWithBlockdata.isEmpty()) {
421
+            text += QString("%1::\n").arg(attrsWithBlockdata.value("blockdata_label"));
422
+            text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder.value("blockdata_filepath"));
419 423
             text += QString("\n");
420 424
         }
421 425
 
422 426
         text += QString("\t.align 2\n");
423
-        if (attrs->contains("shared_attr_maps")) {
424
-            QStringList labels = attrs->value("shared_attr_maps").split(":");
427
+        if (attrs.contains("shared_attr_maps")) {
428
+            QStringList labels = attrs.value("shared_attr_maps").split(":");
425 429
             for (QString label : labels) {
426 430
                 text += QString("%1::\n").arg(label);
427 431
             }
428 432
         } else {
429
-            text += QString("%1::\n").arg(attrs->value("attributes_label"));
433
+            text += QString("%1::\n").arg(attrs.value("attributes_label"));
430 434
         }
431
-        text += QString("\t.4byte %1\n").arg(attrs->value("width"));
432
-        text += QString("\t.4byte %1\n").arg(attrs->value("height"));
433
-        text += QString("\t.4byte %1\n").arg(attrs->value("border_label"));
434
-        text += QString("\t.4byte %1\n").arg(attrs->value("blockdata_label"));
435
-        text += QString("\t.4byte %1\n").arg(attrs->value("tileset_primary"));
436
-        text += QString("\t.4byte %1\n").arg(attrs->value("tileset_secondary"));
435
+        text += QString("\t.4byte %1\n").arg(attrs.value("width"));
436
+        text += QString("\t.4byte %1\n").arg(attrs.value("height"));
437
+        text += QString("\t.4byte %1\n").arg(attrs.value("border_label"));
438
+        text += QString("\t.4byte %1\n").arg(attrs.value("blockdata_label"));
439
+        text += QString("\t.4byte %1\n").arg(attrs.value("tileset_primary"));
440
+        text += QString("\t.4byte %1\n").arg(attrs.value("tileset_secondary"));
437 441
         text += QString("\n");
438 442
     }
439 443
 
@@ -453,26 +457,26 @@ void Project::setNewMapAttributes(Map* map) {
453 457
     map->tileset_secondary_label = "gTileset_Petalburg";
454 458
 
455 459
     // Insert new entry into the global map attributes.
456
-    QMap<QString, QString>* attrs = new QMap<QString, QString>;
457
-    attrs->insert("border_label", QString("%1_MapBorder").arg(map->name));
458
-    attrs->insert("border_filepath", QString("data/maps/%1/border.bin").arg(map->name));
459
-    attrs->insert("blockdata_label", QString("%1_MapBlockdata").arg(map->name));
460
-    attrs->insert("blockdata_filepath", QString("data/maps/%1/map.bin").arg(map->name));
461
-    attrs->insert("attributes_label", QString("%1_MapAttributes").arg(map->name));
462
-    attrs->insert("width", map->width);
463
-    attrs->insert("height", map->height);
464
-    attrs->insert("tileset_primary", map->tileset_primary_label);
465
-    attrs->insert("tileset_secondary", map->tileset_secondary_label);
466
-    mapAttributes->insert(map->name, attrs);
460
+    QMap<QString, QString> attrs;
461
+    attrs.insert("border_label", QString("%1_MapBorder").arg(map->name));
462
+    attrs.insert("border_filepath", QString("data/maps/%1/border.bin").arg(map->name));
463
+    attrs.insert("blockdata_label", QString("%1_MapBlockdata").arg(map->name));
464
+    attrs.insert("blockdata_filepath", QString("data/maps/%1/map.bin").arg(map->name));
465
+    attrs.insert("attributes_label", QString("%1_MapAttributes").arg(map->name));
466
+    attrs.insert("width", map->width);
467
+    attrs.insert("height", map->height);
468
+    attrs.insert("tileset_primary", map->tileset_primary_label);
469
+    attrs.insert("tileset_secondary", map->tileset_secondary_label);
470
+    mapAttributes.insert(map->name, attrs);
467 471
 }
468 472
 
469 473
 void Project::saveMapGroupsTable() {
470 474
     QString text = "";
471 475
     int groupNum = 0;
472
-    for (QStringList* mapNames : *groupedMapNames) {
476
+    for (QStringList mapNames : groupedMapNames) {
473 477
         text += QString("\t.align 2\n");
474 478
         text += QString("gMapGroup%1::\n").arg(groupNum);
475
-        for (QString mapName : *mapNames) {
479
+        for (QString mapName : mapNames) {
476 480
             text += QString("\t.4byte %1\n").arg(mapName);
477 481
         }
478 482
         text += QString("\n");
@@ -610,6 +614,7 @@ void Project::saveMap(Map *map) {
610 614
             qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
611 615
         }
612 616
 
617
+        // TODO: In the future, these files needs more structure to allow for proper parsing/saving.
613 618
         // Create file data/scripts/maps/<map_name>.inc
614 619
         QString text = QString("%1_MapScripts::\n\t.byte 0\n").arg(map->name);
615 620
         saveTextFile(root + "/data/scripts/maps/" + map->name + ".inc", text);
@@ -618,7 +623,6 @@ void Project::saveMap(Map *map) {
618 623
         saveTextFile(root + "/data/text/maps/" + map->name + ".inc", "\n");
619 624
 
620 625
         // Simply append to data/event_scripts.s.
621
-        // TODO: In the future, this file needs more structure to allow for proper parsing.
622 626
         text = QString("\n\t.include \"data/scripts/maps/%1.inc\"\n").arg(map->name);
623 627
         text += QString("\t.include \"data/text/maps/%1.inc\"\n").arg(map->name);
624 628
         appendTextFile(root + "/data/event_scripts.s", text);
@@ -636,9 +640,21 @@ void Project::saveMap(Map *map) {
636 640
     saveMapHeader(map);
637 641
     saveBlockdata(map);
638 642
     saveMapEvents(map);
643
+
644
+    // Update global data structures with current map data.
645
+    updateMapAttributes(map);
646
+
639 647
     map->isPersistedToFile = true;
640 648
 }
641 649
 
650
+void Project::updateMapAttributes(Map* map) {
651
+    mapAttributesTableMaster.insert(map->index.toInt(nullptr, 0), map->name);
652
+
653
+    QMap<QString, QString> attrs = mapAttributes.value(map->name);
654
+    attrs.detach();
655
+    mapAttributesMaster.insert(map->name, attrs);
656
+}
657
+
642 658
 void Project::saveAllDataStructures() {
643 659
     saveMapAttributesTable();
644 660
     saveAllMapAttributes();
@@ -883,10 +899,9 @@ void Project::readMapGroups() {
883 899
         }
884 900
     }
885 901
 
886
-    QList<QStringList*> *groupedMaps = new QList<QStringList*>;
902
+    QList<QStringList> groupedMaps;
887 903
     for (int i = 0; i < groups->length(); i++) {
888
-        QStringList *list = new QStringList;
889
-        groupedMaps->append(list);
904
+        groupedMaps.append(QStringList());
890 905
     }
891 906
 
892 907
     QStringList *maps = new QStringList;
@@ -900,8 +915,7 @@ void Project::readMapGroups() {
900 915
             if (group != -1) {
901 916
                 for (int j = 1; j < params.length(); j++) {
902 917
                     QString mapName = params.value(j);
903
-                    QStringList *list = groupedMaps->value(group);
904
-                    list->append(mapName);
918
+                    groupedMaps[group].append(mapName);
905 919
                     maps->append(mapName);
906 920
                     map_groups->insert(mapName, group);
907 921
 
@@ -919,14 +933,14 @@ void Project::readMapGroups() {
919 933
     mapNames = maps;
920 934
 }
921 935
 
922
-void Project::addNewMapToGroup(QString mapName, int groupNum) {
923
-    int mapIndex = mapAttributesTable->count() + 1;
924
-    mapAttributesTable->insert(mapIndex, mapName);
936
+Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
937
+    int mapIndex = mapAttributesTable.count() + 1;
938
+    mapAttributesTable.insert(mapIndex, mapName);
925 939
 
926 940
     // Setup new map in memory, but don't write to file until map is actually saved later.
927 941
     mapNames->append(mapName);
928 942
     map_groups->insert(mapName, groupNum);
929
-    groupedMapNames->value(groupNum)->append(mapName);
943
+    groupedMapNames[groupNum].append(mapName);
930 944
 
931 945
     Map *map = new Map;
932 946
     map->isPersistedToFile = false;
@@ -942,135 +956,7 @@ void Project::addNewMapToGroup(QString mapName, int groupNum) {
942 956
     map->history.save();
943 957
     map_cache->insert(mapName, map);
944 958
 
945
-
946
-//    QString dataDir = QString("%1/data/").arg(root);
947
-//    QString dataMapsDir = QString("%1maps/").arg(dataDir);
948
-//    QString newMapDataDir = QString("%1%2/").arg(dataMapsDir).arg(mapName);
949
-
950
-//    // 1. Create directory data/maps/<map_name>/
951
-//    if (!QDir::root().mkdir(newMapDataDir)) {
952
-//        qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
953
-//        return;
954
-//    }
955
-
956
-//    // 2. Create file data/maps/<map_name>/border.bin
957
-//    QFile borderFile(newMapDataDir + "border.bin");
958
-//    borderFile.open(QIODevice::WriteOnly);
959
-//    QDataStream borderStream(&borderFile);
960
-//    borderStream.setByteOrder(QDataStream::LittleEndian);
961
-//    borderStream << qint16(0x01D4) << qint16(0x01D5) << qint16(0x01DC) << qint16(0x01DD);
962
-//    borderFile.close();
963
-
964
-//    // 3. Create file data/maps/<map_name>/header.inc
965
-//    QFile headerFile(newMapDataDir + "header.inc");
966
-//    headerFile.open(QIODevice::WriteOnly);
967
-//    QTextStream headerStream(&headerFile);
968
-//    headerStream << mapName << "::" << endl
969
-//                 << "\t.4byte " << mapName << "_MapAttributes" << endl
970
-//                 << "\t.4byte " << mapName << "_MapEvents" << endl
971
-//                 << "\t.4byte " << mapName << "_MapScripts" << endl
972
-//                 << "\t.4byte 0x0" << endl
973
-//                 << "\t.2byte BGM_DAN02" << endl
974
-//                 << "\t.2byte " << mapIndex << endl
975
-//                 << "\t.byte 0" << endl
976
-//                 << "\t.byte 0" << endl
977
-//                 << "\t.byte 11" << endl
978
-//                 << "\t.byte 4" << endl
979
-//                 << "\t.2byte 0" << endl
980
-//                 << "\t.byte 1" << endl
981
-//                 << "\t.byte 0" << endl;
982
-//    headerFile.close();
983
-
984
-//    // 4. Create file data/maps/<map_name>/map.bin
985
-//    QFile mapFile(newMapDataDir + "map.bin");
986
-//    mapFile.open(QIODevice::WriteOnly);
987
-//    QDataStream mapStream(&mapFile);
988
-//    mapStream.setByteOrder(QDataStream::LittleEndian);
989
-//    for (int i = 0; i < 20 * 20; i++) {
990
-//        mapStream << qint16(0x3001);
991
-//    }
992
-//    mapFile.close();
993
-
994
-//    // 5. Create file data/maps/events/<map_name>.inc
995
-//    QFile eventsFile(dataMapsDir + "events/" + mapName + ".inc");
996
-//    eventsFile.open(QIODevice::WriteOnly);
997
-//    QTextStream eventsStream(&eventsFile);
998
-//    eventsStream << mapName << "_MapEvents::" << endl
999
-//                 << "\tmap_events 0x0, 0x0, 0x0, 0x0" << endl;
1000
-//    eventsFile.close();
1001
-
1002
-//    // 6. Create file data/scripts/maps/<map_name>.inc
1003
-//    QFile scriptsFile(dataDir + "scripts/maps/" + mapName + ".inc");
1004
-//    scriptsFile.open(QIODevice::WriteOnly);
1005
-//    QTextStream scriptsStream(&scriptsFile);
1006
-//    scriptsStream << mapName << "_MapScripts::" << endl
1007
-//                  << "\t.byte 0" << endl;
1008
-//    scriptsFile.close();
1009
-
1010
-//    // 7. Create file data/text/maps/<map_name>.inc
1011
-//    QFile textFile(dataDir + "text/maps/" + mapName + ".inc");
1012
-//    textFile.open(QIODevice::WriteOnly);
1013
-//    QTextStream textStream(&textFile);
1014
-//    textStream << endl;
1015
-//    textFile.close();
1016
-
1017
-//    // 8. Modify data/event_scripts.s:
1018
-//    QFile eventScriptsFile(dataDir + "event_scripts.s");
1019
-//    eventScriptsFile.open(QIODevice::Append);
1020
-//    QTextStream eventScriptsStream(&eventScriptsFile);
1021
-//    eventScriptsStream << endl
1022
-//                       << "\t.include \"data/scripts/maps/" << mapName << ".inc\"" << endl
1023
-//                       << "\t.include \"data/text/maps/" << mapName << ".inc\"" << endl;
1024
-//    eventScriptsFile.close();
1025
-
1026
-//    // 9. Modify data/map_events.s:
1027
-//    QFile mapEventsFile(dataDir + "map_events.s");
1028
-//    mapEventsFile.open(QIODevice::Append);
1029
-//    QTextStream mapEventsStream(&mapEventsFile);
1030
-//    mapEventsStream << endl
1031
-//                    << "\t.include \"data/maps/events/" << mapName << ".inc\"" << endl;
1032
-//    mapEventsFile.close();
1033
-
1034
-//    // 10. Modify data/maps/_assets.inc
1035
-//    QFile assetsFile(dataMapsDir + "_assets.inc");
1036
-//    assetsFile.open(QIODevice::Append);
1037
-//    QTextStream assetsStream(&assetsFile);
1038
-//    assetsStream << endl
1039
-//                 << mapName << "_MapBorder::" << endl
1040
-//                 << "\t.incbin \"data/maps/" << mapName << "/border.bin\"" << endl
1041
-//                 << endl
1042
-//                 << mapName << "_MapBlockdata::" << endl
1043
-//                 << "\t.incbin \"data/maps/" << mapName << "/map.bin\"" << endl
1044
-//                 << endl
1045
-//                 << "\t.align 2" << endl
1046
-//                 << mapName << "_MapAttributes::" << endl
1047
-//                 << "\t.4byte 0x14" << endl
1048
-//                 << "\t.4byte 0x14" << endl
1049
-//                 << "\t.4byte " << mapName << "_MapBorder" << endl
1050
-//                 << "\t.4byte " << mapName << "_MapBlockdata" << endl
1051
-//                 << "\t.4byte gTileset_General" << endl
1052
-//                 << "\t.4byte gTileset_Pacifidlog" << endl
1053
-//                 << endl;
1054
-//    assetsFile.close();
1055
-
1056
-//    // 11. Modify data/maps/_groups.inc
1057
-//    // TODO:
1058
-
1059
-//    // 12. Modify data/maps/attributes_table.inc
1060
-//    QFile attributesFile(dataMapsDir + "attributes_table.inc");
1061
-//    attributesFile.open(QIODevice::Append);
1062
-//    QTextStream attributesStream(&attributesFile);
1063
-//    attributesStream << endl
1064
-//                    << "\t.4byte " << mapName << "_MapAttributes" << endl;
1065
-//    attributesFile.close();
1066
-
1067
-//    // 13. Modify data/maps/headers.inc
1068
-//    QFile headersFile(dataMapsDir + "headers.inc");
1069
-//    headersFile.open(QIODevice::Append);
1070
-//    QTextStream headersStream(&headersFile);
1071
-//    headersStream << endl
1072
-//                    << "\t.include \"data/maps/" << mapName << "/header.inc\"" << endl;
1073
-//    headersFile.close();
959
+    return map;
1074 960
 }
1075 961
 
1076 962
 QString Project::getNewMapName() {

+ 9
- 6
project.h Прегледај датотеку

@@ -15,12 +15,14 @@ public:
15 15
     QString root;
16 16
     QStringList *groupNames = NULL;
17 17
     QMap<QString, int> *map_groups;
18
-    QList<QStringList*> *groupedMapNames = NULL;
18
+    QList<QStringList> groupedMapNames;
19 19
     QStringList *mapNames = NULL;
20
-    QMap<QString, QString> *mapConstantsToMapNames;
21
-    QMap<QString, QString> *mapNamesToMapConstants;
22
-    QMap<int, QString> *mapAttributesTable;
23
-    QMap<QString, QMap<QString, QString>*> *mapAttributes;
20
+    QMap<QString, QString>* mapConstantsToMapNames;
21
+    QMap<QString, QString>* mapNamesToMapConstants;
22
+    QMap<int, QString> mapAttributesTable;
23
+    QMap<int, QString> mapAttributesTableMaster;
24
+    QMap<QString, QMap<QString, QString>> mapAttributes;
25
+    QMap<QString, QMap<QString, QString>> mapAttributesMaster;
24 26
 
25 27
 
26 28
     QMap<QString, Map*> *map_cache;
@@ -39,7 +41,7 @@ public:
39 41
     void appendTextFile(QString path, QString text);
40 42
 
41 43
     void readMapGroups();
42
-    void addNewMapToGroup(QString mapName, int groupNum);
44
+    Map* addNewMapToGroup(QString mapName, int groupNum);
43 45
     QString getNewMapName();
44 46
     QString getProjectTitle();
45 47
 
@@ -98,6 +100,7 @@ private:
98 100
     QString getMapAssetsFilepath();
99 101
     void saveMapHeader(Map*);
100 102
     void saveMapAttributesTable();
103
+    void updateMapAttributes(Map* map);
101 104
 };
102 105
 
103 106
 #endif // PROJECT_H