Browse Source

Save map constants header based on the current map group data

Marcus Huderle 6 years ago
parent
commit
c61b8a9b18
2 changed files with 41 additions and 0 deletions
  1. 40
    0
      project.cpp
  2. 1
    0
      project.h

+ 40
- 0
project.cpp View File

492
     saveTextFile(root + "/data/maps/_groups.inc", text);
492
     saveTextFile(root + "/data/maps/_groups.inc", text);
493
 }
493
 }
494
 
494
 
495
+void Project::saveMapConstantsHeader() {
496
+    QString text = QString("#ifndef GUARD_CONSTANTS_MAPS_H\n");
497
+    text += QString("#define GUARD_CONSTANTS_MAPS_H\n");
498
+    text += QString("\n");
499
+
500
+    int groupNum = 0;
501
+    for (QStringList mapNames : groupedMapNames) {
502
+        text += QString("// Map Group %1\n").arg(groupNum);
503
+        int maxLength = 0;
504
+        for (QString mapName : mapNames) {
505
+            QString mapConstantName = mapNamesToMapConstants->value(mapName);
506
+            if (mapConstantName.length() > maxLength)
507
+                maxLength = mapConstantName.length();
508
+        }
509
+        int groupIndex = 0;
510
+        for (QString mapName : mapNames) {
511
+            QString mapConstantName = mapNamesToMapConstants->value(mapName);
512
+            text += QString("#define %1%2(%3 | (%4 << 8))\n")
513
+                    .arg(mapConstantName)
514
+                    .arg(QString(" ").repeated(maxLength - mapConstantName.length() + 1))
515
+                    .arg(groupIndex)
516
+                    .arg(groupNum);
517
+            groupIndex++;
518
+        }
519
+        text += QString("\n");
520
+        groupNum++;
521
+    }
522
+
523
+    text += QString("\n");
524
+    text += QString("#define MAP_NONE (0x7F | (0x7F << 8))\n");
525
+    text += QString("#define MAP_UNDEFINED (0xFF | (0xFF << 8))\n\n\n");
526
+    text += QString("#define MAP_GROUP(map) (MAP_##map >> 8)\n");
527
+    text += QString("#define MAP_NUM(map) (MAP_##map & 0xFF)\n\n");
528
+    text += QString("#endif  // GUARD_CONSTANTS_MAPS_H\n");
529
+    saveTextFile(root + "/include/constants/maps.h", text);
530
+}
531
+
495
 void Project::getTilesets(Map* map) {
532
 void Project::getTilesets(Map* map) {
496
     map->tileset_primary = getTileset(map->tileset_primary_label);
533
     map->tileset_primary = getTileset(map->tileset_primary_label);
497
     map->tileset_secondary = getTileset(map->tileset_secondary_label);
534
     map->tileset_secondary = getTileset(map->tileset_secondary_label);
659
     saveMapAttributesTable();
696
     saveMapAttributesTable();
660
     saveAllMapAttributes();
697
     saveAllMapAttributes();
661
     saveMapGroupsTable();
698
     saveMapGroupsTable();
699
+    saveMapConstantsHeader();
662
 }
700
 }
663
 
701
 
664
 void Project::loadTilesetAssets(Tileset* tileset) {
702
 void Project::loadTilesetAssets(Tileset* tileset) {
945
     Map *map = new Map;
983
     Map *map = new Map;
946
     map->isPersistedToFile = false;
984
     map->isPersistedToFile = false;
947
     map->setName(mapName);
985
     map->setName(mapName);
986
+    mapConstantsToMapNames->insert(map->constantName, map->name);
987
+    mapNamesToMapConstants->insert(map->name, map->constantName);
948
     setNewMapHeader(map, mapIndex);
988
     setNewMapHeader(map, mapIndex);
949
     setNewMapAttributes(map);
989
     setNewMapAttributes(map);
950
     getTilesets(map);
990
     getTilesets(map);

+ 1
- 0
project.h View File

70
     void saveAllDataStructures();
70
     void saveAllDataStructures();
71
     void saveAllMapAttributes();
71
     void saveAllMapAttributes();
72
     void saveMapGroupsTable();
72
     void saveMapGroupsTable();
73
+    void saveMapConstantsHeader();
73
 
74
 
74
     QList<QStringList>* parse(QString text);
75
     QList<QStringList>* parse(QString text);
75
     QStringList getSongNames();
76
     QStringList getSongNames();