|
@@ -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"
|
|
@@ -71,7 +71,7 @@ void Project::loadMapConnections(Map *map) {
|
71
|
71
|
QString path = root + QString("/data/maps/%1/connections.inc").arg(map->name);
|
72
|
72
|
QString text = readTextFile(path);
|
73
|
73
|
if (!text.isNull()) {
|
74
|
|
- QList<QStringList> *commands = parse(text);
|
|
74
|
+ QList<QStringList> *commands = parseAsm(text);
|
75
|
75
|
QStringList *list = getLabelValues(commands, map->connections_label);
|
76
|
76
|
|
77
|
77
|
//// Avoid using this value. It ought to be generated instead.
|
|
@@ -150,13 +150,13 @@ void Project::readMapHeader(Map* map) {
|
150
|
150
|
}
|
151
|
151
|
|
152
|
152
|
QString label = map->name;
|
153
|
|
- Asm *parser = new Asm;
|
|
153
|
+ ParseUtil *parser = new ParseUtil;
|
154
|
154
|
|
155
|
155
|
QString header_text = readTextFile(root + "/data/maps/" + label + "/header.inc");
|
156
|
156
|
if (header_text.isNull()) {
|
157
|
157
|
return;
|
158
|
158
|
}
|
159
|
|
- QStringList *header = getLabelValues(parser->parse(header_text), label);
|
|
159
|
+ QStringList *header = getLabelValues(parser->parseAsm(header_text), label);
|
160
|
160
|
map->attributes_label = header->value(0);
|
161
|
161
|
map->events_label = header->value(1);
|
162
|
162
|
map->scripts_label = header->value(2);
|
|
@@ -212,7 +212,7 @@ void Project::saveMapHeader(Map *map) {
|
212
|
212
|
void Project::readMapAttributesTable() {
|
213
|
213
|
int curMapIndex = 1;
|
214
|
214
|
QString attributesText = readTextFile(getMapAttributesTableFilepath());
|
215
|
|
- QList<QStringList>* values = parse(attributesText);
|
|
215
|
+ QList<QStringList>* values = parseAsm(attributesText);
|
216
|
216
|
bool inAttributePointers = false;
|
217
|
217
|
for (int i = 0; i < values->length(); i++) {
|
218
|
218
|
QStringList params = values->value(i);
|
|
@@ -265,13 +265,13 @@ void Project::readMapAttributes(Map* map) {
|
265
|
265
|
return;
|
266
|
266
|
}
|
267
|
267
|
|
268
|
|
- Asm *parser = new Asm;
|
|
268
|
+ ParseUtil *parser = new ParseUtil;
|
269
|
269
|
|
270
|
270
|
QString assets_text = readTextFile(getMapAssetsFilepath());
|
271
|
271
|
if (assets_text.isNull()) {
|
272
|
272
|
return;
|
273
|
273
|
}
|
274
|
|
- QStringList *attributes = getLabelValues(parser->parse(assets_text), map->attributes_label);
|
|
274
|
+ QStringList *attributes = getLabelValues(parser->parseAsm(assets_text), map->attributes_label);
|
275
|
275
|
map->width = attributes->value(0);
|
276
|
276
|
map->height = attributes->value(1);
|
277
|
277
|
map->border_label = attributes->value(2);
|
|
@@ -283,13 +283,13 @@ void Project::readMapAttributes(Map* map) {
|
283
|
283
|
void Project::readAllMapAttributes() {
|
284
|
284
|
mapAttributes.clear();
|
285
|
285
|
|
286
|
|
- Asm *parser = new Asm;
|
|
286
|
+ ParseUtil *parser = new ParseUtil;
|
287
|
287
|
QString assets_text = readTextFile(getMapAssetsFilepath());
|
288
|
288
|
if (assets_text.isNull()) {
|
289
|
289
|
return;
|
290
|
290
|
}
|
291
|
291
|
|
292
|
|
- QList<QStringList> *commands = parser->parse(assets_text);
|
|
292
|
+ QList<QStringList> *commands = parser->parseAsm(assets_text);
|
293
|
293
|
|
294
|
294
|
// Assume the _assets.inc file is grouped consistently in the order of:
|
295
|
295
|
// 1. <map_name>_MapBorder
|
|
@@ -539,10 +539,10 @@ void Project::getTilesets(Map* map) {
|
539
|
539
|
}
|
540
|
540
|
|
541
|
541
|
Tileset* Project::loadTileset(QString label) {
|
542
|
|
- Asm *parser = new Asm;
|
|
542
|
+ ParseUtil *parser = new ParseUtil;
|
543
|
543
|
|
544
|
544
|
QString headers_text = readTextFile(root + "/data/tilesets/headers.inc");
|
545
|
|
- QStringList *values = getLabelValues(parser->parse(headers_text), label);
|
|
545
|
+ QStringList *values = getLabelValues(parser->parseAsm(headers_text), label);
|
546
|
546
|
Tileset *tileset = new Tileset;
|
547
|
547
|
tileset->name = label;
|
548
|
548
|
tileset->is_compressed = values->value(0);
|
|
@@ -562,7 +562,7 @@ Tileset* Project::loadTileset(QString label) {
|
562
|
562
|
|
563
|
563
|
QString Project::getBlockdataPath(Map* map) {
|
564
|
564
|
QString text = readTextFile(getMapAssetsFilepath());
|
565
|
|
- QStringList *values = getLabelValues(parse(text), map->blockdata_label);
|
|
565
|
+ QStringList *values = getLabelValues(parseAsm(text), map->blockdata_label);
|
566
|
566
|
QString path;
|
567
|
567
|
if (!values->isEmpty()) {
|
568
|
568
|
path = root + "/" + values->value(0).section('"', 1, 1);
|
|
@@ -574,7 +574,7 @@ QString Project::getBlockdataPath(Map* map) {
|
574
|
574
|
|
575
|
575
|
QString Project::getMapBorderPath(Map *map) {
|
576
|
576
|
QString text = readTextFile(getMapAssetsFilepath());
|
577
|
|
- QStringList *values = getLabelValues(parse(text), map->border_label);
|
|
577
|
+ QStringList *values = getLabelValues(parseAsm(text), map->border_label);
|
578
|
578
|
QString path;
|
579
|
579
|
if (!values->isEmpty()) {
|
580
|
580
|
path = root + "/" + values->value(0).section('"', 1, 1);
|
|
@@ -705,7 +705,7 @@ void Project::saveAllDataStructures() {
|
705
|
705
|
}
|
706
|
706
|
|
707
|
707
|
void Project::loadTilesetAssets(Tileset* tileset) {
|
708
|
|
- Asm* parser = new Asm;
|
|
708
|
+ ParseUtil* parser = new ParseUtil;
|
709
|
709
|
QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
|
710
|
710
|
if (tileset->name.isNull()) {
|
711
|
711
|
return;
|
|
@@ -713,7 +713,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
713
|
713
|
QString dir_path = root + "/data/tilesets/" + category + "/" + tileset->name.replace("gTileset_", "").toLower();
|
714
|
714
|
|
715
|
715
|
QString graphics_text = readTextFile(root + "/data/tilesets/graphics.inc");
|
716
|
|
- QList<QStringList> *graphics = parser->parse(graphics_text);
|
|
716
|
+ QList<QStringList> *graphics = parser->parseAsm(graphics_text);
|
717
|
717
|
QStringList *tiles_values = getLabelValues(graphics, tileset->tiles_label);
|
718
|
718
|
QStringList *palettes_values = getLabelValues(graphics, tileset->palettes_label);
|
719
|
719
|
|
|
@@ -743,7 +743,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
743
|
743
|
QString metatiles_path;
|
744
|
744
|
QString metatile_attrs_path;
|
745
|
745
|
QString metatiles_text = readTextFile(root + "/data/tilesets/metatiles.inc");
|
746
|
|
- QList<QStringList> *metatiles_macros = parser->parse(metatiles_text);
|
|
746
|
+ QList<QStringList> *metatiles_macros = parser->parseAsm(metatiles_text);
|
747
|
747
|
QStringList *metatiles_values = getLabelValues(metatiles_macros, tileset->metatiles_label);
|
748
|
748
|
if (!metatiles_values->isEmpty()) {
|
749
|
749
|
metatiles_path = root + "/" + metatiles_values->value(0).section('"', 1, 1);
|
|
@@ -918,8 +918,8 @@ void Project::readMapGroups() {
|
918
|
918
|
if (text.isNull()) {
|
919
|
919
|
return;
|
920
|
920
|
}
|
921
|
|
- Asm *parser = new Asm;
|
922
|
|
- QList<QStringList> *commands = parser->parse(text);
|
|
921
|
+ ParseUtil *parser = new ParseUtil;
|
|
922
|
+ QList<QStringList> *commands = parser->parseAsm(text);
|
923
|
923
|
|
924
|
924
|
bool in_group_pointers = false;
|
925
|
925
|
QStringList *groups = new QStringList;
|
|
@@ -1015,9 +1015,9 @@ QString Project::getNewMapName() {
|
1015
|
1015
|
return newMapName;
|
1016
|
1016
|
}
|
1017
|
1017
|
|
1018
|
|
-QList<QStringList>* Project::parse(QString text) {
|
1019
|
|
- Asm *parser = new Asm;
|
1020
|
|
- return parser->parse(text);
|
|
1018
|
+QList<QStringList>* Project::parseAsm(QString text) {
|
|
1019
|
+ ParseUtil *parser = new ParseUtil;
|
|
1020
|
+ return parser->parseAsm(text);
|
1021
|
1021
|
}
|
1022
|
1022
|
|
1023
|
1023
|
QStringList Project::getLocations() {
|
|
@@ -1074,7 +1074,7 @@ void Project::readItemNames() {
|
1074
|
1074
|
void Project::readFlagNames() {
|
1075
|
1075
|
QString filepath = root + "/include/constants/flags.h";
|
1076
|
1076
|
QStringList prefixes = (QStringList() << "FLAG_");
|
1077
|
|
- readCDefinesSorted(filepath, prefixes, flagNames, "SYSTEM_FLAGS", 0x800);
|
|
1077
|
+ readCDefinesSorted(filepath, prefixes, flagNames);
|
1078
|
1078
|
}
|
1079
|
1079
|
|
1080
|
1080
|
void Project::readVarNames() {
|
|
@@ -1084,13 +1084,9 @@ void Project::readVarNames() {
|
1084
|
1084
|
}
|
1085
|
1085
|
|
1086
|
1086
|
void Project::readCDefinesSorted(QString filepath, QStringList prefixes, QStringList* definesToSet) {
|
1087
|
|
- return readCDefinesSorted(filepath, prefixes, definesToSet, "", 0);
|
1088
|
|
-}
|
1089
|
|
-
|
1090
|
|
-void Project::readCDefinesSorted(QString filepath, QStringList prefixes, QStringList* definesToSet, QString hardcodedDefine, int hardcodedDefineValue) {
|
1091
|
1087
|
QString text = readTextFile(filepath);
|
1092
|
1088
|
if (!text.isNull()) {
|
1093
|
|
- QMap<QString, int> defines = readCDefines(text, prefixes, hardcodedDefine, hardcodedDefineValue);
|
|
1089
|
+ QMap<QString, int> defines = readCDefines(text, prefixes);
|
1094
|
1090
|
|
1095
|
1091
|
// The defines should to be sorted by their underlying value, not alphabetically.
|
1096
|
1092
|
// Reverse the map and read out the resulting keys in order.
|
|
@@ -1318,13 +1314,13 @@ void Project::readMapEvents(Map *map) {
|
1318
|
1314
|
return;
|
1319
|
1315
|
}
|
1320
|
1316
|
|
1321
|
|
- QStringList *labels = getLabelValues(parse(text), map->events_label);
|
|
1317
|
+ QStringList *labels = getLabelValues(parseAsm(text), map->events_label);
|
1322
|
1318
|
map->object_events_label = labels->value(0);
|
1323
|
1319
|
map->warps_label = labels->value(1);
|
1324
|
1320
|
map->coord_events_label = labels->value(2);
|
1325
|
1321
|
map->bg_events_label = labels->value(3);
|
1326
|
1322
|
|
1327
|
|
- QList<QStringList> *object_events = getLabelMacros(parse(text), map->object_events_label);
|
|
1323
|
+ QList<QStringList> *object_events = getLabelMacros(parseAsm(text), map->object_events_label);
|
1328
|
1324
|
map->events["object"].clear();
|
1329
|
1325
|
for (QStringList command : *object_events) {
|
1330
|
1326
|
if (command.value(0) == "object_event") {
|
|
@@ -1368,7 +1364,7 @@ void Project::readMapEvents(Map *map) {
|
1368
|
1364
|
}
|
1369
|
1365
|
}
|
1370
|
1366
|
|
1371
|
|
- QList<QStringList> *warps = getLabelMacros(parse(text), map->warps_label);
|
|
1367
|
+ QList<QStringList> *warps = getLabelMacros(parseAsm(text), map->warps_label);
|
1372
|
1368
|
map->events["warp"].clear();
|
1373
|
1369
|
for (QStringList command : *warps) {
|
1374
|
1370
|
if (command.value(0) == "warp_def") {
|
|
@@ -1392,7 +1388,7 @@ void Project::readMapEvents(Map *map) {
|
1392
|
1388
|
}
|
1393
|
1389
|
}
|
1394
|
1390
|
|
1395
|
|
- QList<QStringList> *coords = getLabelMacros(parse(text), map->coord_events_label);
|
|
1391
|
+ QList<QStringList> *coords = getLabelMacros(parseAsm(text), map->coord_events_label);
|
1396
|
1392
|
map->events["trap"].clear();
|
1397
|
1393
|
map->events["trap_weather"].clear();
|
1398
|
1394
|
for (QStringList command : *coords) {
|
|
@@ -1430,7 +1426,7 @@ void Project::readMapEvents(Map *map) {
|
1430
|
1426
|
}
|
1431
|
1427
|
}
|
1432
|
1428
|
|
1433
|
|
- QList<QStringList> *bgs = getLabelMacros(parse(text), map->bg_events_label);
|
|
1429
|
+ QList<QStringList> *bgs = getLabelMacros(parseAsm(text), map->bg_events_label);
|
1434
|
1430
|
map->events["sign"].clear();
|
1435
|
1431
|
map->events["event_hidden_item"].clear();
|
1436
|
1432
|
map->events["event_secret_base"].clear();
|
|
@@ -1535,41 +1531,23 @@ QString Project::readCIncbin(QString text, QString label) {
|
1535
|
1531
|
}
|
1536
|
1532
|
|
1537
|
1533
|
QMap<QString, int> Project::readCDefines(QString text, QStringList prefixes) {
|
1538
|
|
- return readCDefines(text, prefixes, "", 0);
|
1539
|
|
-}
|
1540
|
|
-
|
1541
|
|
-QMap<QString, int> Project::readCDefines(QString text, QStringList prefixes, QString hardcodedDefine, int hardcodedDefineValue) {
|
1542
|
|
- QMap<QString, int> defines;
|
1543
|
|
-
|
1544
|
|
- QString combinedPrefixes = "(" + prefixes.join('|') + ")";
|
1545
|
|
- QString regex;
|
1546
|
|
- if (hardcodedDefine.isEmpty()) {
|
1547
|
|
- regex = QString("#define\\s+(?<defineName>(%1)\\w+)\\s+(?<defineValue>\\w+)").arg(combinedPrefixes);
|
1548
|
|
- } else {
|
1549
|
|
- regex = QString("#define\\s+(?<defineName>(%1)\\w+)\\s+\\(*(?<hardcodedDefineName>\\\s*%2\\s+\\+\\s+)*(?<defineValue>\\w+\)\\)*").arg(combinedPrefixes, hardcodedDefine);
|
1550
|
|
- }
|
1551
|
|
-
|
1552
|
|
- QRegularExpression re(regex);
|
|
1534
|
+ ParseUtil parser;
|
|
1535
|
+ QMap<QString, int> allDefines;
|
|
1536
|
+ QMap<QString, int> filteredDefines;
|
|
1537
|
+ QRegularExpression re("#define\\s+(?<defineName>\\w+)[^\\S\\n]+(?<defineValue>.+)");
|
1553
|
1538
|
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
1554
|
1539
|
while (iter.hasNext()) {
|
1555
|
1540
|
QRegularExpressionMatch match = iter.next();
|
1556
|
1541
|
QString name = match.captured("defineName");
|
1557
|
|
- QString hardcodedDefineName = match.captured("hardcodedDefineName");
|
1558
|
|
- QString value = match.captured("defineValue");
|
1559
|
|
- bool valid;
|
1560
|
|
- int parsedValue = value.startsWith("0x") ? value.toInt(&valid, 16) : value.toInt(&valid, 10);
|
1561
|
|
- if (valid) {
|
1562
|
|
- int actualValue = parsedValue;
|
1563
|
|
- if (!hardcodedDefine.isEmpty() && !hardcodedDefineName.isEmpty()) {
|
1564
|
|
- actualValue += hardcodedDefineValue;
|
|
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);
|
1565
|
1549
|
}
|
1566
|
|
- defines.insert(name, actualValue);
|
1567
|
|
- } else if (defines.contains(value)) {
|
1568
|
|
- defines.insert(name, defines.value(value));
|
1569
|
|
- } else {
|
1570
|
|
- qDebug() << QString("Failed to parse define '%1' value '%2' as base 10 or hexadecimal value").arg(name, value);
|
1571
|
1550
|
}
|
1572
|
1551
|
}
|
1573
|
|
-
|
1574
|
|
- return defines;
|
|
1552
|
+ return filteredDefines;
|
1575
|
1553
|
}
|