|
@@ -1,4 +1,4 @@
|
1
|
|
-#include "asm.h"
|
|
1
|
+#include "parseutil.h"
|
2
|
2
|
#include "project.h"
|
3
|
3
|
#include "tile.h"
|
4
|
4
|
#include "tileset.h"
|
|
@@ -18,6 +18,9 @@ Project::Project()
|
18
|
18
|
groupNames = new QStringList;
|
19
|
19
|
map_groups = new QMap<QString, int>;
|
20
|
20
|
mapNames = new QStringList;
|
|
21
|
+ itemNames = new QStringList;
|
|
22
|
+ flagNames = new QStringList;
|
|
23
|
+ varNames = new QStringList;
|
21
|
24
|
map_cache = new QMap<QString, Map*>;
|
22
|
25
|
mapConstantsToMapNames = new QMap<QString, QString>;
|
23
|
26
|
mapNamesToMapConstants = new QMap<QString, QString>;
|
|
@@ -68,7 +71,7 @@ void Project::loadMapConnections(Map *map) {
|
68
|
71
|
QString path = root + QString("/data/maps/%1/connections.inc").arg(map->name);
|
69
|
72
|
QString text = readTextFile(path);
|
70
|
73
|
if (!text.isNull()) {
|
71
|
|
- QList<QStringList> *commands = parse(text);
|
|
74
|
+ QList<QStringList> *commands = parseAsm(text);
|
72
|
75
|
QStringList *list = getLabelValues(commands, map->connections_label);
|
73
|
76
|
|
74
|
77
|
//// Avoid using this value. It ought to be generated instead.
|
|
@@ -147,13 +150,13 @@ void Project::readMapHeader(Map* map) {
|
147
|
150
|
}
|
148
|
151
|
|
149
|
152
|
QString label = map->name;
|
150
|
|
- Asm *parser = new Asm;
|
|
153
|
+ ParseUtil *parser = new ParseUtil;
|
151
|
154
|
|
152
|
155
|
QString header_text = readTextFile(root + "/data/maps/" + label + "/header.inc");
|
153
|
156
|
if (header_text.isNull()) {
|
154
|
157
|
return;
|
155
|
158
|
}
|
156
|
|
- QStringList *header = getLabelValues(parser->parse(header_text), label);
|
|
159
|
+ QStringList *header = getLabelValues(parser->parseAsm(header_text), label);
|
157
|
160
|
map->attributes_label = header->value(0);
|
158
|
161
|
map->events_label = header->value(1);
|
159
|
162
|
map->scripts_label = header->value(2);
|
|
@@ -209,7 +212,7 @@ void Project::saveMapHeader(Map *map) {
|
209
|
212
|
void Project::readMapAttributesTable() {
|
210
|
213
|
int curMapIndex = 1;
|
211
|
214
|
QString attributesText = readTextFile(getMapAttributesTableFilepath());
|
212
|
|
- QList<QStringList>* values = parse(attributesText);
|
|
215
|
+ QList<QStringList>* values = parseAsm(attributesText);
|
213
|
216
|
bool inAttributePointers = false;
|
214
|
217
|
for (int i = 0; i < values->length(); i++) {
|
215
|
218
|
QStringList params = values->value(i);
|
|
@@ -262,13 +265,13 @@ void Project::readMapAttributes(Map* map) {
|
262
|
265
|
return;
|
263
|
266
|
}
|
264
|
267
|
|
265
|
|
- Asm *parser = new Asm;
|
|
268
|
+ ParseUtil *parser = new ParseUtil;
|
266
|
269
|
|
267
|
270
|
QString assets_text = readTextFile(getMapAssetsFilepath());
|
268
|
271
|
if (assets_text.isNull()) {
|
269
|
272
|
return;
|
270
|
273
|
}
|
271
|
|
- QStringList *attributes = getLabelValues(parser->parse(assets_text), map->attributes_label);
|
|
274
|
+ QStringList *attributes = getLabelValues(parser->parseAsm(assets_text), map->attributes_label);
|
272
|
275
|
map->width = attributes->value(0);
|
273
|
276
|
map->height = attributes->value(1);
|
274
|
277
|
map->border_label = attributes->value(2);
|
|
@@ -280,13 +283,13 @@ void Project::readMapAttributes(Map* map) {
|
280
|
283
|
void Project::readAllMapAttributes() {
|
281
|
284
|
mapAttributes.clear();
|
282
|
285
|
|
283
|
|
- Asm *parser = new Asm;
|
|
286
|
+ ParseUtil *parser = new ParseUtil;
|
284
|
287
|
QString assets_text = readTextFile(getMapAssetsFilepath());
|
285
|
288
|
if (assets_text.isNull()) {
|
286
|
289
|
return;
|
287
|
290
|
}
|
288
|
291
|
|
289
|
|
- QList<QStringList> *commands = parser->parse(assets_text);
|
|
292
|
+ QList<QStringList> *commands = parser->parseAsm(assets_text);
|
290
|
293
|
|
291
|
294
|
// Assume the _assets.inc file is grouped consistently in the order of:
|
292
|
295
|
// 1. <map_name>_MapBorder
|
|
@@ -536,10 +539,10 @@ void Project::getTilesets(Map* map) {
|
536
|
539
|
}
|
537
|
540
|
|
538
|
541
|
Tileset* Project::loadTileset(QString label) {
|
539
|
|
- Asm *parser = new Asm;
|
|
542
|
+ ParseUtil *parser = new ParseUtil;
|
540
|
543
|
|
541
|
544
|
QString headers_text = readTextFile(root + "/data/tilesets/headers.inc");
|
542
|
|
- QStringList *values = getLabelValues(parser->parse(headers_text), label);
|
|
545
|
+ QStringList *values = getLabelValues(parser->parseAsm(headers_text), label);
|
543
|
546
|
Tileset *tileset = new Tileset;
|
544
|
547
|
tileset->name = label;
|
545
|
548
|
tileset->is_compressed = values->value(0);
|
|
@@ -559,7 +562,7 @@ Tileset* Project::loadTileset(QString label) {
|
559
|
562
|
|
560
|
563
|
QString Project::getBlockdataPath(Map* map) {
|
561
|
564
|
QString text = readTextFile(getMapAssetsFilepath());
|
562
|
|
- QStringList *values = getLabelValues(parse(text), map->blockdata_label);
|
|
565
|
+ QStringList *values = getLabelValues(parseAsm(text), map->blockdata_label);
|
563
|
566
|
QString path;
|
564
|
567
|
if (!values->isEmpty()) {
|
565
|
568
|
path = root + "/" + values->value(0).section('"', 1, 1);
|
|
@@ -571,7 +574,7 @@ QString Project::getBlockdataPath(Map* map) {
|
571
|
574
|
|
572
|
575
|
QString Project::getMapBorderPath(Map *map) {
|
573
|
576
|
QString text = readTextFile(getMapAssetsFilepath());
|
574
|
|
- QStringList *values = getLabelValues(parse(text), map->border_label);
|
|
577
|
+ QStringList *values = getLabelValues(parseAsm(text), map->border_label);
|
575
|
578
|
QString path;
|
576
|
579
|
if (!values->isEmpty()) {
|
577
|
580
|
path = root + "/" + values->value(0).section('"', 1, 1);
|
|
@@ -702,7 +705,7 @@ void Project::saveAllDataStructures() {
|
702
|
705
|
}
|
703
|
706
|
|
704
|
707
|
void Project::loadTilesetAssets(Tileset* tileset) {
|
705
|
|
- Asm* parser = new Asm;
|
|
708
|
+ ParseUtil* parser = new ParseUtil;
|
706
|
709
|
QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
|
707
|
710
|
if (tileset->name.isNull()) {
|
708
|
711
|
return;
|
|
@@ -710,7 +713,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
710
|
713
|
QString dir_path = root + "/data/tilesets/" + category + "/" + tileset->name.replace("gTileset_", "").toLower();
|
711
|
714
|
|
712
|
715
|
QString graphics_text = readTextFile(root + "/data/tilesets/graphics.inc");
|
713
|
|
- QList<QStringList> *graphics = parser->parse(graphics_text);
|
|
716
|
+ QList<QStringList> *graphics = parser->parseAsm(graphics_text);
|
714
|
717
|
QStringList *tiles_values = getLabelValues(graphics, tileset->tiles_label);
|
715
|
718
|
QStringList *palettes_values = getLabelValues(graphics, tileset->palettes_label);
|
716
|
719
|
|
|
@@ -740,7 +743,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
740
|
743
|
QString metatiles_path;
|
741
|
744
|
QString metatile_attrs_path;
|
742
|
745
|
QString metatiles_text = readTextFile(root + "/data/tilesets/metatiles.inc");
|
743
|
|
- QList<QStringList> *metatiles_macros = parser->parse(metatiles_text);
|
|
746
|
+ QList<QStringList> *metatiles_macros = parser->parseAsm(metatiles_text);
|
744
|
747
|
QStringList *metatiles_values = getLabelValues(metatiles_macros, tileset->metatiles_label);
|
745
|
748
|
if (!metatiles_values->isEmpty()) {
|
746
|
749
|
metatiles_path = root + "/" + metatiles_values->value(0).section('"', 1, 1);
|
|
@@ -915,8 +918,8 @@ void Project::readMapGroups() {
|
915
|
918
|
if (text.isNull()) {
|
916
|
919
|
return;
|
917
|
920
|
}
|
918
|
|
- Asm *parser = new Asm;
|
919
|
|
- QList<QStringList> *commands = parser->parse(text);
|
|
921
|
+ ParseUtil *parser = new ParseUtil;
|
|
922
|
+ QList<QStringList> *commands = parser->parseAsm(text);
|
920
|
923
|
|
921
|
924
|
bool in_group_pointers = false;
|
922
|
925
|
QStringList *groups = new QStringList;
|
|
@@ -1012,9 +1015,9 @@ QString Project::getNewMapName() {
|
1012
|
1015
|
return newMapName;
|
1013
|
1016
|
}
|
1014
|
1017
|
|
1015
|
|
-QList<QStringList>* Project::parse(QString text) {
|
1016
|
|
- Asm *parser = new Asm;
|
1017
|
|
- return parser->parse(text);
|
|
1018
|
+QList<QStringList>* Project::parseAsm(QString text) {
|
|
1019
|
+ ParseUtil *parser = new ParseUtil;
|
|
1020
|
+ return parser->parseAsm(text);
|
1018
|
1021
|
}
|
1019
|
1022
|
|
1020
|
1023
|
QStringList Project::getLocations() {
|
|
@@ -1062,36 +1065,49 @@ QStringList Project::getBattleScenes() {
|
1062
|
1065
|
return names;
|
1063
|
1066
|
}
|
1064
|
1067
|
|
1065
|
|
-QStringList Project::getSongNames() {
|
1066
|
|
- QStringList names;
|
1067
|
|
- QString text = readTextFile(root + "/include/constants/songs.h");
|
|
1068
|
+void Project::readItemNames() {
|
|
1069
|
+ QString filepath = root + "/include/constants/items.h";
|
|
1070
|
+ QStringList prefixes = (QStringList() << "ITEM_");
|
|
1071
|
+ readCDefinesSorted(filepath, prefixes, itemNames);
|
|
1072
|
+}
|
|
1073
|
+
|
|
1074
|
+void Project::readFlagNames() {
|
|
1075
|
+ QString filepath = root + "/include/constants/flags.h";
|
|
1076
|
+ QStringList prefixes = (QStringList() << "FLAG_");
|
|
1077
|
+ readCDefinesSorted(filepath, prefixes, flagNames);
|
|
1078
|
+}
|
|
1079
|
+
|
|
1080
|
+void Project::readVarNames() {
|
|
1081
|
+ QString filepath = root + "/include/constants/vars.h";
|
|
1082
|
+ QStringList prefixes = (QStringList() << "VAR_");
|
|
1083
|
+ readCDefinesSorted(filepath, prefixes, varNames);
|
|
1084
|
+}
|
|
1085
|
+
|
|
1086
|
+void Project::readCDefinesSorted(QString filepath, QStringList prefixes, QStringList* definesToSet) {
|
|
1087
|
+ QString text = readTextFile(filepath);
|
1068
|
1088
|
if (!text.isNull()) {
|
1069
|
|
- QStringList songDefinePrefixes;
|
1070
|
|
- songDefinePrefixes << "SE_" << "BGM_";
|
1071
|
|
- QMap<QString, int> songDefines = readCDefines(text, songDefinePrefixes);
|
1072
|
|
- names = songDefines.keys();
|
|
1089
|
+ QMap<QString, int> defines = readCDefines(text, prefixes);
|
|
1090
|
+
|
|
1091
|
+ // The defines should to be sorted by their underlying value, not alphabetically.
|
|
1092
|
+ // Reverse the map and read out the resulting keys in order.
|
|
1093
|
+ QMultiMap<int, QString> definesInverse;
|
|
1094
|
+ for (QString defineName : defines.keys()) {
|
|
1095
|
+ definesInverse.insert(defines[defineName], defineName);
|
|
1096
|
+ }
|
|
1097
|
+ *definesToSet = definesInverse.values();
|
1073
|
1098
|
}
|
1074
|
|
- return names;
|
1075
|
1099
|
}
|
1076
|
1100
|
|
1077
|
|
-QString Project::getSongName(int songNumber) {
|
|
1101
|
+QStringList Project::getSongNames() {
|
1078
|
1102
|
QStringList names;
|
1079
|
1103
|
QString text = readTextFile(root + "/include/constants/songs.h");
|
1080
|
1104
|
if (!text.isNull()) {
|
1081
|
1105
|
QStringList songDefinePrefixes;
|
1082
|
1106
|
songDefinePrefixes << "SE_" << "BGM_";
|
1083
|
1107
|
QMap<QString, int> songDefines = readCDefines(text, songDefinePrefixes);
|
1084
|
|
-
|
1085
|
|
- // Loop through song defines, and fine the one with the matching song number.
|
1086
|
|
- QMap<QString, int>::iterator iter = songDefines.begin();
|
1087
|
|
- while (iter != songDefines.end()) {
|
1088
|
|
- if (iter.value() == songNumber) {
|
1089
|
|
- return iter.key();
|
1090
|
|
- }
|
1091
|
|
- iter++;
|
1092
|
|
- }
|
|
1108
|
+ names = songDefines.keys();
|
1093
|
1109
|
}
|
1094
|
|
- return "";
|
|
1110
|
+ return names;
|
1095
|
1111
|
}
|
1096
|
1112
|
|
1097
|
1113
|
QMap<QString, int> Project::getMapObjGfxConstants() {
|
|
@@ -1128,7 +1144,7 @@ void Project::loadObjectPixmaps(QList<Event*> objects) {
|
1128
|
1144
|
QString pointers_text = readTextFile(root + "/src/data/field_map_obj/map_object_graphics_info_pointers.h");
|
1129
|
1145
|
QString info_text = readTextFile(root + "/src/data/field_map_obj/map_object_graphics_info.h");
|
1130
|
1146
|
QString pic_text = readTextFile(root + "/src/data/field_map_obj/map_object_pic_tables.h");
|
1131
|
|
- QString assets_text = readTextFile(root + "/src/field/field_map_obj.c");
|
|
1147
|
+ QString assets_text = readTextFile(root + "/src/field/event_object_movement.c");
|
1132
|
1148
|
|
1133
|
1149
|
QStringList pointers = readCArray(pointers_text, "gMapObjectGraphicsInfoPointers");
|
1134
|
1150
|
|
|
@@ -1228,8 +1244,8 @@ void Project::saveMapEvents(Map *map) {
|
1228
|
1244
|
text += QString(", %1").arg(coords->get("y"));
|
1229
|
1245
|
text += QString(", %1").arg(coords->get("elevation"));
|
1230
|
1246
|
text += QString(", 0");
|
1231
|
|
- text += QString(", %1").arg(coords->get("coord_unknown1"));
|
1232
|
|
- text += QString(", %1").arg(coords->get("coord_unknown2"));
|
|
1247
|
+ text += QString(", %1").arg(coords->get("script_var"));
|
|
1248
|
+ text += QString(", %1").arg(coords->get("script_var_value"));
|
1233
|
1249
|
text += QString(", 0");
|
1234
|
1250
|
text += QString(", %1").arg(coords->get("script_label"));
|
1235
|
1251
|
text += "\n";
|
|
@@ -1298,13 +1314,13 @@ void Project::readMapEvents(Map *map) {
|
1298
|
1314
|
return;
|
1299
|
1315
|
}
|
1300
|
1316
|
|
1301
|
|
- QStringList *labels = getLabelValues(parse(text), map->events_label);
|
|
1317
|
+ QStringList *labels = getLabelValues(parseAsm(text), map->events_label);
|
1302
|
1318
|
map->object_events_label = labels->value(0);
|
1303
|
1319
|
map->warps_label = labels->value(1);
|
1304
|
1320
|
map->coord_events_label = labels->value(2);
|
1305
|
1321
|
map->bg_events_label = labels->value(3);
|
1306
|
1322
|
|
1307
|
|
- QList<QStringList> *object_events = getLabelMacros(parse(text), map->object_events_label);
|
|
1323
|
+ QList<QStringList> *object_events = getLabelMacros(parseAsm(text), map->object_events_label);
|
1308
|
1324
|
map->events["object"].clear();
|
1309
|
1325
|
for (QStringList command : *object_events) {
|
1310
|
1326
|
if (command.value(0) == "object_event") {
|
|
@@ -1348,7 +1364,7 @@ void Project::readMapEvents(Map *map) {
|
1348
|
1364
|
}
|
1349
|
1365
|
}
|
1350
|
1366
|
|
1351
|
|
- QList<QStringList> *warps = getLabelMacros(parse(text), map->warps_label);
|
|
1367
|
+ QList<QStringList> *warps = getLabelMacros(parseAsm(text), map->warps_label);
|
1352
|
1368
|
map->events["warp"].clear();
|
1353
|
1369
|
for (QStringList command : *warps) {
|
1354
|
1370
|
if (command.value(0) == "warp_def") {
|
|
@@ -1372,7 +1388,7 @@ void Project::readMapEvents(Map *map) {
|
1372
|
1388
|
}
|
1373
|
1389
|
}
|
1374
|
1390
|
|
1375
|
|
- QList<QStringList> *coords = getLabelMacros(parse(text), map->coord_events_label);
|
|
1391
|
+ QList<QStringList> *coords = getLabelMacros(parseAsm(text), map->coord_events_label);
|
1376
|
1392
|
map->events["trap"].clear();
|
1377
|
1393
|
map->events["trap_weather"].clear();
|
1378
|
1394
|
for (QStringList command : *coords) {
|
|
@@ -1389,8 +1405,8 @@ void Project::readMapEvents(Map *map) {
|
1389
|
1405
|
coord->put("x", command.value(i++));
|
1390
|
1406
|
coord->put("y", command.value(i++));
|
1391
|
1407
|
coord->put("elevation", command.value(i++));
|
1392
|
|
- coord->put("coord_unknown1", command.value(i++));
|
1393
|
|
- coord->put("coord_unknown2", command.value(i++));
|
|
1408
|
+ coord->put("script_var", command.value(i++));
|
|
1409
|
+ coord->put("script_var_value", command.value(i++));
|
1394
|
1410
|
coord->put("script_label", command.value(i++));
|
1395
|
1411
|
//coord_unknown3
|
1396
|
1412
|
//coord_unknown4
|
|
@@ -1410,7 +1426,7 @@ void Project::readMapEvents(Map *map) {
|
1410
|
1426
|
}
|
1411
|
1427
|
}
|
1412
|
1428
|
|
1413
|
|
- QList<QStringList> *bgs = getLabelMacros(parse(text), map->bg_events_label);
|
|
1429
|
+ QList<QStringList> *bgs = getLabelMacros(parseAsm(text), map->bg_events_label);
|
1414
|
1430
|
map->events["sign"].clear();
|
1415
|
1431
|
map->events["event_hidden_item"].clear();
|
1416
|
1432
|
map->events["event_secret_base"].clear();
|
|
@@ -1515,27 +1531,23 @@ QString Project::readCIncbin(QString text, QString label) {
|
1515
|
1531
|
}
|
1516
|
1532
|
|
1517
|
1533
|
QMap<QString, int> Project::readCDefines(QString text, QStringList prefixes) {
|
1518
|
|
- QMap<QString, int> defines;
|
1519
|
|
-
|
1520
|
|
- QString combinedPrefixes = "[" + prefixes.join('|') + "]";
|
1521
|
|
- QRegularExpression re(QString("#define\\s+(?<defineName>%1\\w+)\\s(?<defineValue>\\w+)").arg(combinedPrefixes));
|
|
1534
|
+ ParseUtil parser;
|
|
1535
|
+ QMap<QString, int> allDefines;
|
|
1536
|
+ QMap<QString, int> filteredDefines;
|
|
1537
|
+ QRegularExpression re("#define\\s+(?<defineName>\\w+)[^\\S\\n]+(?<defineValue>.+)");
|
1522
|
1538
|
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
1523
|
1539
|
while (iter.hasNext()) {
|
1524
|
1540
|
QRegularExpressionMatch match = iter.next();
|
1525
|
1541
|
QString name = match.captured("defineName");
|
1526
|
|
- QString value = match.captured("defineValue");
|
1527
|
|
- bool valid;
|
1528
|
|
- int parsedValue = value.startsWith("0x") ? value.toInt(&valid, 16) : value.toInt(&valid, 10);
|
1529
|
|
- if (valid) {
|
1530
|
|
- if (!defines.contains(name)) {
|
1531
|
|
- defines.insert(name, parsedValue);
|
1532
|
|
- } else {
|
1533
|
|
- qDebug() << QString("Define '%1' is defined multiple times'").arg(name);
|
|
1542
|
+ QString expression = match.captured("defineValue");
|
|
1543
|
+ expression.replace(QRegularExpression("//.*"), "");
|
|
1544
|
+ int value = parser.evaluateDefine(expression, &allDefines);
|
|
1545
|
+ allDefines.insert(name, value);
|
|
1546
|
+ for (QString prefix : prefixes) {
|
|
1547
|
+ if (name.startsWith(prefix)) {
|
|
1548
|
+ filteredDefines.insert(name, value);
|
1534
|
1549
|
}
|
1535
|
|
- } else {
|
1536
|
|
- qDebug() << QString("Failed to parse define '%1' value '%2' as base 10 or hexadecimal value").arg(name, value);
|
1537
|
1550
|
}
|
1538
|
1551
|
}
|
1539
|
|
-
|
1540
|
|
- return defines;
|
|
1552
|
+ return filteredDefines;
|
1541
|
1553
|
}
|