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

Merge pull request #2 from huderlem/filepaths

Fix songs and map obj gfx
yenatch пре 6 година
родитељ
комит
0452156372
No account linked to committer's email address
3 измењених фајлова са 52 додато и 35 уклоњено
  1. 1
    0
      .gitignore
  2. 50
    35
      project.cpp
  3. 1
    0
      project.h

+ 1
- 0
.gitignore Прегледај датотеку

@@ -0,0 +1 @@
1
+pretmap.pro.user

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

@@ -577,33 +577,31 @@ QStringList Project::getBattleScenes() {
577 577
 
578 578
 QStringList Project::getSongNames() {
579 579
     QStringList names;
580
-    QString text = readTextFile(root + "/constants/songs.inc");
580
+    QString text = readTextFile(root + "/include/constants/songs.h");
581 581
     if (!text.isNull()) {
582
-        QList<QStringList> *commands = parse(text);
583
-        for (int i = 0; i < commands->length(); i++) {
584
-            QStringList params = commands->value(i);
585
-            QString macro = params.value(0);
586
-            if (macro == ".equiv") {
587
-                names.append(params.value(1));
588
-            }
589
-        }
582
+        QStringList songDefinePrefixes;
583
+        songDefinePrefixes << "SE_" << "BGM_";
584
+        QMap<QString, int> songDefines = readCDefines(text, songDefinePrefixes);
585
+        names = songDefines.keys();
590 586
     }
591 587
     return names;
592 588
 }
593 589
 
594
-QString Project::getSongName(int value) {
590
+QString Project::getSongName(int songNumber) {
595 591
     QStringList names;
596
-    QString text = readTextFile(root + "/constants/songs.inc");
592
+    QString text = readTextFile(root + "/include/constants/songs.h");
597 593
     if (!text.isNull()) {
598
-        QList<QStringList> *commands = parse(text);
599
-        for (int i = 0; i < commands->length(); i++) {
600
-            QStringList params = commands->value(i);
601
-            QString macro = params.value(0);
602
-            if (macro == ".equiv") {
603
-                if (value == ((QString)(params.value(2))).toInt(nullptr, 0)) {
604
-                    return params.value(1);
605
-                }
594
+        QStringList songDefinePrefixes;
595
+        songDefinePrefixes << "SE_" << "BGM_";
596
+        QMap<QString, int> songDefines = readCDefines(text, songDefinePrefixes);
597
+
598
+        // Loop through song defines, and fine the one with the matching song number.
599
+        QMap<QString, int>::iterator iter = songDefines.begin();
600
+        while (iter != songDefines.end()) {
601
+            if (iter.value() == songNumber) {
602
+                return iter.key();
606 603
             }
604
+            iter++;
607 605
         }
608 606
     }
609 607
     return "";
@@ -611,20 +609,11 @@ QString Project::getSongName(int value) {
611 609
 
612 610
 QMap<QString, int> Project::getMapObjGfxConstants() {
613 611
     QMap<QString, int> constants;
614
-    QString text = readTextFile(root + "/constants/map_object_constants.inc");
612
+    QString text = readTextFile(root + "/include/constants/map_objects.h");
615 613
     if (!text.isNull()) {
616
-        QList<QStringList> *commands = parse(text);
617
-        for (int i = 0; i < commands->length(); i++) {
618
-            QStringList params = commands->value(i);
619
-            QString macro = params.value(0);
620
-            if (macro == ".set") {
621
-                QString constant = params.value(1);
622
-                if (constant.startsWith("MAP_OBJ_GFX_")) {
623
-                    int value = params.value(2).toInt(nullptr, 0);
624
-                    constants.insert(constant, value);
625
-                }
626
-            }
627
-        }
614
+        QStringList mapObjGfxPrefixes;
615
+        mapObjGfxPrefixes << "MAP_OBJ_GFX_";
616
+        constants = readCDefines(text, mapObjGfxPrefixes);
628 617
     }
629 618
     return constants;
630 619
 }
@@ -649,9 +638,9 @@ void Project::loadObjectPixmaps(QList<Event*> objects) {
649 638
 
650 639
     QMap<QString, int> constants = getMapObjGfxConstants();
651 640
 
652
-    QString pointers_text = readTextFile(root + "/include/data/field_map_obj/map_object_graphics_info_pointers.h");
653
-    QString info_text = readTextFile(root + "/include/data/field_map_obj/map_object_graphics_info.h");
654
-    QString pic_text = readTextFile(root + "/include/data/field_map_obj/map_object_pic_tables.h");
641
+    QString pointers_text = readTextFile(root + "/src/data/field_map_obj/map_object_graphics_info_pointers.h");
642
+    QString info_text = readTextFile(root + "/src/data/field_map_obj/map_object_graphics_info.h");
643
+    QString pic_text = readTextFile(root + "/src/data/field_map_obj/map_object_pic_tables.h");
655 644
     QString assets_text = readTextFile(root + "/src/field/field_map_obj.c");
656 645
 
657 646
     QStringList pointers = readCArray(pointers_text, "gMapObjectGraphicsInfoPointers");
@@ -969,3 +958,29 @@ QString Project::readCIncbin(QString text, QString label) {
969 958
 
970 959
     return path;
971 960
 }
961
+
962
+QMap<QString, int> Project::readCDefines(QString text, QStringList prefixes) {
963
+    QMap<QString, int> defines;
964
+
965
+    QString combinedPrefixes = "[" + prefixes.join('|') + "]";
966
+    QRegularExpression re(QString("#define\\s+(?<defineName>%1\\w+)\\s(?<defineValue>\\w+)").arg(combinedPrefixes));
967
+    QRegularExpressionMatchIterator iter = re.globalMatch(text);
968
+    while (iter.hasNext()) {
969
+        QRegularExpressionMatch match = iter.next();
970
+        QString name = match.captured("defineName");
971
+        QString value = match.captured("defineValue");
972
+        bool valid;
973
+        int parsedValue = value.startsWith("0x") ? value.toInt(&valid, 16) : value.toInt(&valid, 10);
974
+        if (valid) {
975
+            if (!defines.contains(name)) {
976
+                defines.insert(name, parsedValue);
977
+            } else {
978
+                qDebug() << QString("Define '%1' is defined multiple times'").arg(name);
979
+            }
980
+        } else {
981
+            qDebug() << QString("Failed to parse define '%1' value '%2' as base 10 or hexadecimal value").arg(name, value);
982
+        }
983
+    }
984
+
985
+    return defines;
986
+}

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

@@ -70,6 +70,7 @@ public:
70 70
 
71 71
     QStringList readCArray(QString text, QString label);
72 72
     QString readCIncbin(QString text, QString label);
73
+    QMap<QString, int> readCDefines(QString text, QStringList prefixes);
73 74
 };
74 75
 
75 76
 #endif // PROJECT_H