|
@@ -19,6 +19,8 @@ Project::Project()
|
19
|
19
|
map_groups = new QMap<QString, int>;
|
20
|
20
|
mapNames = new QStringList;
|
21
|
21
|
itemNames = new QStringList;
|
|
22
|
+ flagNames = new QStringList;
|
|
23
|
+ varNames = new QStringList;
|
22
|
24
|
map_cache = new QMap<QString, Map*>;
|
23
|
25
|
mapConstantsToMapNames = new QMap<QString, QString>;
|
24
|
26
|
mapNamesToMapConstants = new QMap<QString, QString>;
|
|
@@ -1064,25 +1066,39 @@ QStringList Project::getBattleScenes() {
|
1064
|
1066
|
}
|
1065
|
1067
|
|
1066
|
1068
|
void Project::readItemNames() {
|
1067
|
|
- QString text = readTextFile(root + "/include/constants/items.h");
|
|
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, "SYSTEM_FLAGS", 0x800);
|
|
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
|
+ return readCDefinesSorted(filepath, prefixes, definesToSet, "", 0);
|
|
1088
|
+}
|
|
1089
|
+
|
|
1090
|
+void Project::readCDefinesSorted(QString filepath, QStringList prefixes, QStringList* definesToSet, QString hardcodedDefine, int hardcodedDefineValue) {
|
|
1091
|
+ QString text = readTextFile(filepath);
|
1068
|
1092
|
if (!text.isNull()) {
|
1069
|
|
- QStringList itemDefinePrefixes;
|
1070
|
|
- itemDefinePrefixes << "ITEM_";
|
1071
|
|
- QMap<QString, int> itemDefines = readCDefines(text, itemDefinePrefixes);
|
|
1093
|
+ QMap<QString, int> defines = readCDefines(text, prefixes, hardcodedDefine, hardcodedDefineValue);
|
1072
|
1094
|
|
1073
|
|
- // The item names should to be sorted by their underlying value, not alphabetically.
|
|
1095
|
+ // The defines should to be sorted by their underlying value, not alphabetically.
|
1074
|
1096
|
// Reverse the map and read out the resulting keys in order.
|
1075
|
|
- QMultiMap<int, QString> itemDefinesInverse;
|
1076
|
|
- for (QString itemName : itemDefines.keys()) {
|
1077
|
|
- itemDefinesInverse.insert(itemDefines[itemName], itemName);
|
1078
|
|
- }
|
1079
|
|
-
|
1080
|
|
- for (int itemValue : itemDefinesInverse.keys()) {
|
1081
|
|
- QList<QString> names = itemDefinesInverse.values(itemValue);
|
1082
|
|
- for (QString name : names) {
|
1083
|
|
- itemNames->append(name);
|
1084
|
|
- }
|
|
1097
|
+ QMultiMap<int, QString> definesInverse;
|
|
1098
|
+ for (QString defineName : defines.keys()) {
|
|
1099
|
+ definesInverse.insert(defines[defineName], defineName);
|
1085
|
1100
|
}
|
|
1101
|
+ *definesToSet = definesInverse.values();
|
1086
|
1102
|
}
|
1087
|
1103
|
}
|
1088
|
1104
|
|
|
@@ -1252,8 +1268,8 @@ void Project::saveMapEvents(Map *map) {
|
1252
|
1268
|
text += QString(", %1").arg(coords->get("y"));
|
1253
|
1269
|
text += QString(", %1").arg(coords->get("elevation"));
|
1254
|
1270
|
text += QString(", 0");
|
1255
|
|
- text += QString(", %1").arg(coords->get("coord_unknown1"));
|
1256
|
|
- text += QString(", %1").arg(coords->get("coord_unknown2"));
|
|
1271
|
+ text += QString(", %1").arg(coords->get("script_var"));
|
|
1272
|
+ text += QString(", %1").arg(coords->get("script_var_value"));
|
1257
|
1273
|
text += QString(", 0");
|
1258
|
1274
|
text += QString(", %1").arg(coords->get("script_label"));
|
1259
|
1275
|
text += "\n";
|
|
@@ -1413,8 +1429,8 @@ void Project::readMapEvents(Map *map) {
|
1413
|
1429
|
coord->put("x", command.value(i++));
|
1414
|
1430
|
coord->put("y", command.value(i++));
|
1415
|
1431
|
coord->put("elevation", command.value(i++));
|
1416
|
|
- coord->put("coord_unknown1", command.value(i++));
|
1417
|
|
- coord->put("coord_unknown2", command.value(i++));
|
|
1432
|
+ coord->put("script_var", command.value(i++));
|
|
1433
|
+ coord->put("script_var_value", command.value(i++));
|
1418
|
1434
|
coord->put("script_label", command.value(i++));
|
1419
|
1435
|
//coord_unknown3
|
1420
|
1436
|
//coord_unknown4
|
|
@@ -1539,23 +1555,37 @@ QString Project::readCIncbin(QString text, QString label) {
|
1539
|
1555
|
}
|
1540
|
1556
|
|
1541
|
1557
|
QMap<QString, int> Project::readCDefines(QString text, QStringList prefixes) {
|
|
1558
|
+ return readCDefines(text, prefixes, "", 0);
|
|
1559
|
+}
|
|
1560
|
+
|
|
1561
|
+QMap<QString, int> Project::readCDefines(QString text, QStringList prefixes, QString hardcodedDefine, int hardcodedDefineValue) {
|
1542
|
1562
|
QMap<QString, int> defines;
|
1543
|
1563
|
|
1544
|
|
- QString combinedPrefixes = "[" + prefixes.join('|') + "]";
|
1545
|
|
- QRegularExpression re(QString("#define\\s+(?<defineName>%1\\w+)\\s(?<defineValue>\\w+)").arg(combinedPrefixes));
|
|
1564
|
+ QString combinedPrefixes = "(" + prefixes.join('|') + ")";
|
|
1565
|
+ QString regex;
|
|
1566
|
+ if (hardcodedDefine.isEmpty()) {
|
|
1567
|
+ regex = QString("#define\\s+(?<defineName>(%1)\\w+)\\s+(?<defineValue>\\w+)").arg(combinedPrefixes);
|
|
1568
|
+ } else {
|
|
1569
|
+ regex = QString("#define\\s+(?<defineName>(%1)\\w+)\\s+\\(*(?<hardcodedDefineName>\\\s*%2\\s+\\+\\s+)*(?<defineValue>\\w+\)\\)*").arg(combinedPrefixes, hardcodedDefine);
|
|
1570
|
+ }
|
|
1571
|
+
|
|
1572
|
+ QRegularExpression re(regex);
|
1546
|
1573
|
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
1547
|
1574
|
while (iter.hasNext()) {
|
1548
|
1575
|
QRegularExpressionMatch match = iter.next();
|
1549
|
1576
|
QString name = match.captured("defineName");
|
|
1577
|
+ QString hardcodedDefineName = match.captured("hardcodedDefineName");
|
1550
|
1578
|
QString value = match.captured("defineValue");
|
1551
|
1579
|
bool valid;
|
1552
|
1580
|
int parsedValue = value.startsWith("0x") ? value.toInt(&valid, 16) : value.toInt(&valid, 10);
|
1553
|
1581
|
if (valid) {
|
1554
|
|
- if (!defines.contains(name)) {
|
1555
|
|
- defines.insert(name, parsedValue);
|
1556
|
|
- } else {
|
1557
|
|
- qDebug() << QString("Define '%1' is defined multiple times'").arg(name);
|
|
1582
|
+ int actualValue = parsedValue;
|
|
1583
|
+ if (!hardcodedDefine.isEmpty() && !hardcodedDefineName.isEmpty()) {
|
|
1584
|
+ actualValue += hardcodedDefineValue;
|
1558
|
1585
|
}
|
|
1586
|
+ defines.insert(name, actualValue);
|
|
1587
|
+ } else if (defines.contains(value)) {
|
|
1588
|
+ defines.insert(name, defines.value(value));
|
1559
|
1589
|
} else {
|
1560
|
1590
|
qDebug() << QString("Failed to parse define '%1' value '%2' as base 10 or hexadecimal value").arg(name, value);
|
1561
|
1591
|
}
|