Ver código fonte

Save map constants header based on the current map group data

Marcus Huderle 6 anos atrás
pai
commit
c61b8a9b18
2 arquivos alterados com 41 adições e 0 exclusões
  1. 40
    0
      project.cpp
  2. 1
    0
      project.h

+ 40
- 0
project.cpp Ver arquivo

@@ -492,6 +492,43 @@ void Project::saveMapGroupsTable() {
492 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 532
 void Project::getTilesets(Map* map) {
496 533
     map->tileset_primary = getTileset(map->tileset_primary_label);
497 534
     map->tileset_secondary = getTileset(map->tileset_secondary_label);
@@ -659,6 +696,7 @@ void Project::saveAllDataStructures() {
659 696
     saveMapAttributesTable();
660 697
     saveAllMapAttributes();
661 698
     saveMapGroupsTable();
699
+    saveMapConstantsHeader();
662 700
 }
663 701
 
664 702
 void Project::loadTilesetAssets(Tileset* tileset) {
@@ -945,6 +983,8 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
945 983
     Map *map = new Map;
946 984
     map->isPersistedToFile = false;
947 985
     map->setName(mapName);
986
+    mapConstantsToMapNames->insert(map->constantName, map->name);
987
+    mapNamesToMapConstants->insert(map->name, map->constantName);
948 988
     setNewMapHeader(map, mapIndex);
949 989
     setNewMapAttributes(map);
950 990
     getTilesets(map);

+ 1
- 0
project.h Ver arquivo

@@ -70,6 +70,7 @@ public:
70 70
     void saveAllDataStructures();
71 71
     void saveAllMapAttributes();
72 72
     void saveMapGroupsTable();
73
+    void saveMapConstantsHeader();
73 74
 
74 75
     QList<QStringList>* parse(QString text);
75 76
     QStringList getSongNames();