Просмотр исходного кода

Load and save the gMapAttributes array

Marcus Huderle 6 лет назад
Родитель
Сommit
40a0fbee02
5 измененных файлов: 72 добавлений и 4 удалений
  1. 1
    0
      editor.cpp
  2. 6
    0
      mainwindow.cpp
  3. 1
    0
      mainwindow.h
  4. 57
    3
      project.cpp
  5. 7
    1
      project.h

+ 1
- 0
editor.cpp Просмотреть файл

@@ -9,6 +9,7 @@ Editor::Editor()
9 9
 
10 10
 void Editor::saveProject() {
11 11
     if (project) {
12
+        project->saveAllDataStructures();
12 13
         project->saveAllMaps();
13 14
     }
14 15
 }

+ 6
- 0
mainwindow.cpp Просмотреть файл

@@ -61,10 +61,12 @@ void MainWindow::openProject(QString dir) {
61 61
         editor->project = new Project;
62 62
         editor->project->root = dir;
63 63
         setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
64
+        loadDataStructures();
64 65
         populateMapList();
65 66
         setMap(getDefaultMap());
66 67
     } else {
67 68
         setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
69
+        loadDataStructures();
68 70
         populateMapList();
69 71
     }
70 72
 }
@@ -278,6 +280,10 @@ void MainWindow::on_checkBox_ShowLocation_clicked(bool checked)
278 280
     }
279 281
 }
280 282
 
283
+void MainWindow::loadDataStructures() {
284
+    Project *project = editor->project;
285
+    project->readMapAttributesTable();
286
+}
281 287
 
282 288
 void MainWindow::populateMapList() {
283 289
     Project *project = editor->project;

+ 1
- 0
mainwindow.h Просмотреть файл

@@ -76,6 +76,7 @@ private:
76 76
     Editor *editor = NULL;
77 77
     QIcon* mapIcon;
78 78
     void setMap(QString);
79
+    void loadDataStructures();
79 80
     void populateMapList();
80 81
     QString getExistingDirectory(QString);
81 82
     void openProject(QString dir);

+ 57
- 3
project.cpp Просмотреть файл

@@ -22,6 +22,7 @@ Project::Project()
22 22
     map_cache = new QMap<QString, Map*>;
23 23
     mapConstantsToMapNames = new QMap<QString, QString>;
24 24
     mapNamesToMapConstants = new QMap<QString, QString>;
25
+    mapAttributesTable = new QMap<int, QString>;
25 26
     tileset_cache = new QMap<QString, Tileset*>;
26 27
 }
27 28
 
@@ -171,6 +172,53 @@ void Project::saveMapHeader(Map *map) {
171 172
     saveTextFile(header_path, text);
172 173
 }
173 174
 
175
+void Project::readMapAttributesTable() {
176
+    int curMapIndex = 1;
177
+    QString attributesText = readTextFile(getMapAttributesTableFilepath());
178
+    QList<QStringList>* values = parse(attributesText);
179
+    bool inAttributePointers = false;
180
+    for (int i = 0; i < values->length(); i++) {
181
+        QStringList params = values->value(i);
182
+        QString macro = params.value(0);
183
+        if (macro == ".label") {
184
+            if (inAttributePointers) {
185
+                break;
186
+            }
187
+            if (params.value(1) == "gMapAttributes") {
188
+                inAttributePointers = true;
189
+            }
190
+        } else if (macro == ".4byte" && inAttributePointers) {
191
+            QString mapName = params.value(1);
192
+            if (!mapName.contains("UnknownMapAttributes")) {
193
+                // Strip off "_MapAttributes" from the label if it's a real map label.
194
+                mapName = mapName.remove(mapName.length() - 14, 14);
195
+            }
196
+            mapAttributesTable->insert(curMapIndex, mapName);
197
+            curMapIndex++;
198
+        }
199
+    }
200
+}
201
+
202
+void Project::saveMapAttributesTable() {
203
+    QString text = "";
204
+    text += QString("\t.align 2\n");
205
+    text += QString("gMapAttributes::\n");
206
+    for (int i = 0; i < mapAttributesTable->count(); i++) {
207
+        int mapIndex = i + 1;
208
+        QString mapName = mapAttributesTable->value(mapIndex);
209
+        if (!mapName.contains("UnknownMapAttributes")) {
210
+            text += QString("\t.4byte %1_MapAttributes\n").arg(mapName);
211
+        } else {
212
+            text += QString("\t.4byte %1\n").arg(mapName);
213
+        }
214
+    }
215
+    saveTextFile(getMapAttributesTableFilepath(), text);
216
+}
217
+
218
+QString Project::getMapAttributesTableFilepath() {
219
+    return QString("%1/data/maps/attributes_table.inc").arg(root);
220
+}
221
+
174 222
 void Project::readMapAttributes(Map* map) {
175 223
     Asm *parser = new Asm;
176 224
 
@@ -277,6 +325,10 @@ void Project::saveMap(Map *map) {
277 325
     saveMapEvents(map);
278 326
 }
279 327
 
328
+void Project::saveAllDataStructures() {
329
+    saveMapAttributesTable();
330
+}
331
+
280 332
 void Project::loadTilesetAssets(Tileset* tileset) {
281 333
     Asm* parser = new Asm;
282 334
     QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
@@ -543,8 +595,6 @@ void Project::readMapGroups() {
543 595
 }
544 596
 
545 597
 void Project::addNewMapToGroup(QString mapName, int groupNum) {
546
-    int mapIndex = 0;// TODO: need to calculate the new map index.
547
-
548 598
     // Write new map to project files.
549 599
     // 1. Create directory data/maps/<map_name>/
550 600
     // 2. Create file data/maps/<map_name>/border.bin
@@ -563,10 +613,14 @@ void Project::addNewMapToGroup(QString mapName, int groupNum) {
563 613
     // 12. Modify data/maps/attributes_table.inc
564 614
     // 13. Modify data/maps/headers.inc
565 615
 
566
-    // 1. Create directory data/maps/<map_name>/
616
+    int mapIndex = mapAttributesTable->count() + 1;
617
+    mapAttributesTable->insert(mapIndex, mapName);
618
+
567 619
     QString dataDir = QString("%1/data/").arg(root);
568 620
     QString dataMapsDir = QString("%1maps/").arg(dataDir);
569 621
     QString newMapDataDir = QString("%1%2/").arg(dataMapsDir).arg(mapName);
622
+
623
+    // 1. Create directory data/maps/<map_name>/
570 624
     if (!QDir::root().mkdir(newMapDataDir)) {
571 625
         qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
572 626
         return;

+ 7
- 1
project.h Просмотреть файл

@@ -19,6 +19,7 @@ public:
19 19
     QStringList *mapNames = NULL;
20 20
     QMap<QString, QString> *mapConstantsToMapNames;
21 21
     QMap<QString, QString> *mapNamesToMapConstants;
22
+    QMap<int, QString> *mapAttributesTable;
22 23
 
23 24
     QMap<QString, Map*> *map_cache;
24 25
     Map* loadMap(QString);
@@ -42,6 +43,7 @@ public:
42 43
     QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
43 44
     QStringList* getLabelValues(QList<QStringList>*, QString);
44 45
     void readMapHeader(Map*);
46
+    void readMapAttributesTable();
45 47
     void readMapAttributes(Map*);
46 48
     void getTilesets(Map*);
47 49
     void loadTilesetAssets(Tileset*);
@@ -51,7 +53,7 @@ public:
51 53
     void writeBlockdata(QString, Blockdata*);
52 54
     void saveAllMaps();
53 55
     void saveMap(Map*);
54
-    void saveMapHeader(Map*);
56
+    void saveAllDataStructures();
55 57
 
56 58
     QList<QStringList>* parse(QString text);
57 59
     QStringList getSongNames();
@@ -77,6 +79,10 @@ public:
77 79
     QStringList readCArray(QString text, QString label);
78 80
     QString readCIncbin(QString text, QString label);
79 81
     QMap<QString, int> readCDefines(QString text, QStringList prefixes);
82
+private:
83
+    QString getMapAttributesTableFilepath();
84
+    void saveMapHeader(Map*);
85
+    void saveMapAttributesTable();
80 86
 };
81 87
 
82 88
 #endif // PROJECT_H