Browse Source

Load and save the gMapAttributes array

Marcus Huderle 6 years ago
parent
commit
40a0fbee02
5 changed files with 72 additions and 4 deletions
  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 View File

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

+ 6
- 0
mainwindow.cpp View File

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

+ 1
- 0
mainwindow.h View File

76
     Editor *editor = NULL;
76
     Editor *editor = NULL;
77
     QIcon* mapIcon;
77
     QIcon* mapIcon;
78
     void setMap(QString);
78
     void setMap(QString);
79
+    void loadDataStructures();
79
     void populateMapList();
80
     void populateMapList();
80
     QString getExistingDirectory(QString);
81
     QString getExistingDirectory(QString);
81
     void openProject(QString dir);
82
     void openProject(QString dir);

+ 57
- 3
project.cpp View File

22
     map_cache = new QMap<QString, Map*>;
22
     map_cache = new QMap<QString, Map*>;
23
     mapConstantsToMapNames = new QMap<QString, QString>;
23
     mapConstantsToMapNames = new QMap<QString, QString>;
24
     mapNamesToMapConstants = new QMap<QString, QString>;
24
     mapNamesToMapConstants = new QMap<QString, QString>;
25
+    mapAttributesTable = new QMap<int, QString>;
25
     tileset_cache = new QMap<QString, Tileset*>;
26
     tileset_cache = new QMap<QString, Tileset*>;
26
 }
27
 }
27
 
28
 
171
     saveTextFile(header_path, text);
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
 void Project::readMapAttributes(Map* map) {
222
 void Project::readMapAttributes(Map* map) {
175
     Asm *parser = new Asm;
223
     Asm *parser = new Asm;
176
 
224
 
277
     saveMapEvents(map);
325
     saveMapEvents(map);
278
 }
326
 }
279
 
327
 
328
+void Project::saveAllDataStructures() {
329
+    saveMapAttributesTable();
330
+}
331
+
280
 void Project::loadTilesetAssets(Tileset* tileset) {
332
 void Project::loadTilesetAssets(Tileset* tileset) {
281
     Asm* parser = new Asm;
333
     Asm* parser = new Asm;
282
     QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
334
     QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
543
 }
595
 }
544
 
596
 
545
 void Project::addNewMapToGroup(QString mapName, int groupNum) {
597
 void Project::addNewMapToGroup(QString mapName, int groupNum) {
546
-    int mapIndex = 0;// TODO: need to calculate the new map index.
547
-
548
     // Write new map to project files.
598
     // Write new map to project files.
549
     // 1. Create directory data/maps/<map_name>/
599
     // 1. Create directory data/maps/<map_name>/
550
     // 2. Create file data/maps/<map_name>/border.bin
600
     // 2. Create file data/maps/<map_name>/border.bin
563
     // 12. Modify data/maps/attributes_table.inc
613
     // 12. Modify data/maps/attributes_table.inc
564
     // 13. Modify data/maps/headers.inc
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
     QString dataDir = QString("%1/data/").arg(root);
619
     QString dataDir = QString("%1/data/").arg(root);
568
     QString dataMapsDir = QString("%1maps/").arg(dataDir);
620
     QString dataMapsDir = QString("%1maps/").arg(dataDir);
569
     QString newMapDataDir = QString("%1%2/").arg(dataMapsDir).arg(mapName);
621
     QString newMapDataDir = QString("%1%2/").arg(dataMapsDir).arg(mapName);
622
+
623
+    // 1. Create directory data/maps/<map_name>/
570
     if (!QDir::root().mkdir(newMapDataDir)) {
624
     if (!QDir::root().mkdir(newMapDataDir)) {
571
         qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
625
         qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
572
         return;
626
         return;

+ 7
- 1
project.h View File

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