|
@@ -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;
|