add data qualifiers struct

This commit is contained in:
garak 2019-04-28 20:20:48 -04:00 committed by huderlem
parent 8c29b00fa4
commit 9098055054
3 changed files with 44 additions and 6 deletions

View file

@ -47,6 +47,14 @@ public:
QMap<int, QString> metatileBehaviorMapInverse;
QMap<QString, QString> facingDirections;
struct DataQualifiers
{
bool isStatic;
bool isConst;
};
DataQualifiers getDataQualifiers(QString, QString);
QMap<QString, DataQualifiers> dataQualifiers;
QMap<QString, Map*> *map_cache;
Map* loadMap(QString);
Map* getMap(QString);

View file

@ -102,17 +102,23 @@ void RegionMap::readLayout() {
QMap<QString, QString> *qmap = new QMap<QString, QString>;
bool mapNamesQualified = false, mapEntriesQualified = false;
QTextStream in(&file);
in.setCodec("UTF-8");
while (!in.atEnd()) {
line = in.readLine();
if (line.startsWith("static const u8")) {
if (line.contains(QRegularExpression(".*sMapName.*="))) {
QRegularExpression reBefore("sMapName_(.*)\\[");
QRegularExpression reAfter("_\\(\"(.*)\"");
QString const_name = reBefore.match(line).captured(1);
QString full_name = reAfter.match(line).captured(1);
sMapNames.append(const_name);
sMapNamesMap.insert(const_name, full_name);
if (!mapNamesQualified) {
project->dataQualifiers.insert("region_map_entries_names", project->getDataQualifiers(line, "sMapName_" + const_name));
mapNamesQualified = true;
}
} else if (line.contains("MAPSEC")) {
QRegularExpression reBefore("\\[(.*)\\]");
QRegularExpression reAfter("{(.*)}");
@ -124,6 +130,11 @@ void RegionMap::readLayout() {
// x y width height name
entry[0].toInt(), entry[1].toInt(), entry[2].toInt(), entry[3].toInt(), insertion
};
} else if (line.contains("gRegionMapEntries")) {
if (!mapEntriesQualified) {
project->dataQualifiers.insert("region_map_entries", project->getDataQualifiers(line, "gRegionMapEntries"));
mapEntriesQualified = true;
}
}
}
file.close();
@ -158,10 +169,15 @@ void RegionMap::saveLayout() {
entries_text += "#define GUARD_DATA_REGION_MAP_REGION_MAP_ENTRIES_H\n\n";
for (auto sName : sMapNames) {
entries_text += "static const u8 sMapName_" + sName + "[] = _(\"" + sMapNamesMap.value(sName) + "\");\n";
entries_text += QString("%1%2u8 sMapName_")
.arg(project->dataQualifiers.value("region_map_entries_names").isStatic ? "static " : "")
.arg(project->dataQualifiers.value("region_map_entries_names").isConst ? "const " : "")
+ sName + "[] = _(\"" + sMapNamesMap.value(sName) + "\");\n";
}
entries_text += "\nconst struct RegionMapLocation gRegionMapEntries[] = {\n";
entries_text += QString("\n%1%2struct RegionMapLocation gRegionMapEntries[] = {\n")
.arg(project->dataQualifiers.value("region_map_entries").isStatic ? "static " : "")
.arg(project->dataQualifiers.value("region_map_entries").isConst ? "const " : "");
int longest = 1;
for (auto sec : project->mapSectionNameToValue.keys()) {

View file

@ -596,9 +596,9 @@ void Project::saveMapConstantsHeader() {
// saves heal location coords in root + /src/data/heal_locations.h
// and indexes as defines in root + /include/constants/heal_locations.h
void Project::saveHealLocationStruct(Map *map) {
QString tab = QString(" ");
QString data_text = QString("static const struct HealLocation sHealLocations[] =\n{\n");
QString data_text = QString("%1%2struct HealLocation sHealLocations[] =\n{\n")
.arg(dataQualifiers.value("heal_locations").isStatic ? "static " : "")
.arg(dataQualifiers.value("heal_locations").isConst ? "const " : "");
QString constants_text = QString("#ifndef GUARD_CONSTANTS_HEAL_LOCATIONS_H\n");
constants_text += QString("#define GUARD_CONSTANTS_HEAL_LOCATIONS_H\n\n");
@ -1388,6 +1388,18 @@ QStringList Project::getVisibilities() {
return names;
}
Project::DataQualifiers Project::getDataQualifiers(QString text, QString label) {
Project::DataQualifiers qualifiers;
QRegularExpression regex(QString("\\s*(?<static>static\\s*)?(?<const>const\\s*)?[A-Za-z0-9_\\s]*\\b%1\\b").arg(label));
QRegularExpressionMatch match = regex.match(text);
qualifiers.isStatic = match.captured("static").isNull() ? false : true;
qualifiers.isConst = match.captured("const").isNull() ? false : true;
return qualifiers;
}
QMap<QString, QStringList> Project::getTilesetLabels() {
QMap<QString, QStringList> allTilesets;
QStringList primaryTilesets;
@ -1507,6 +1519,8 @@ void Project::readHealLocations() {
QString text = readTextFile(root + "/src/data/heal_locations.h");
text.replace(QRegularExpression("//.*?(\r\n?|\n)|/\\*.*?\\*/", QRegularExpression::DotMatchesEverythingOption), "");
dataQualifiers.insert("heal_locations", getDataQualifiers(text, "sHealLocations"));
QRegularExpression regex("MAP_GROUP\\((?<map>[A-Za-z0-9_]*)\\),\\s+MAP_NUM\\((\\1)\\),\\s+(?<x>[0-9A-Fa-fx]*),\\s+(?<y>[0-9A-Fa-fx]*)");
QRegularExpressionMatchIterator iter = regex.globalMatch(text);