Parse all map attributes from _assets into memory
This commit is contained in:
parent
5c0f628f0d
commit
50fc906971
4 changed files with 95 additions and 1 deletions
2
asm.cpp
2
asm.cpp
|
@ -26,7 +26,7 @@ QList<QStringList>* Asm::parse(QString text) {
|
|||
//QString macro;
|
||||
//QStringList *params;
|
||||
strip_comment(&line);
|
||||
if (line.isEmpty()) {
|
||||
if (line.trimmed().isEmpty()) {
|
||||
} else if (line.contains(':')) {
|
||||
label = line.left(line.indexOf(':'));
|
||||
QStringList *list = new QStringList;
|
||||
|
|
|
@ -283,6 +283,7 @@ void MainWindow::on_checkBox_ShowLocation_clicked(bool checked)
|
|||
void MainWindow::loadDataStructures() {
|
||||
Project *project = editor->project;
|
||||
project->readMapAttributesTable();
|
||||
project->readAllMapAttributes();
|
||||
}
|
||||
|
||||
void MainWindow::populateMapList() {
|
||||
|
|
90
project.cpp
90
project.cpp
|
@ -23,6 +23,7 @@ Project::Project()
|
|||
mapConstantsToMapNames = new QMap<QString, QString>;
|
||||
mapNamesToMapConstants = new QMap<QString, QString>;
|
||||
mapAttributesTable = new QMap<int, QString>;
|
||||
mapAttributes = new QMap<QString, QMap<QString, QString>*>;
|
||||
tileset_cache = new QMap<QString, Tileset*>;
|
||||
}
|
||||
|
||||
|
@ -273,6 +274,95 @@ void Project::readMapAttributes(Map* map) {
|
|||
map->tileset_secondary_label = attributes->value(5);
|
||||
}
|
||||
|
||||
void Project::readAllMapAttributes() {
|
||||
mapAttributes->clear();
|
||||
|
||||
Asm *parser = new Asm;
|
||||
QString assets_text = readTextFile(root + "/data/maps/_assets.inc");
|
||||
if (assets_text.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QStringList> *commands = parser->parse(assets_text);
|
||||
|
||||
// Assume the _assets.inc file is grouped consistently in the order of:
|
||||
// 1. <map_name>_MapBorder
|
||||
// 2. <map_name>_MapBlockdata
|
||||
// 3. <map_name>_MapAttributes
|
||||
int i = 0;
|
||||
while (i < commands->length()) {
|
||||
// Read MapBorder assets.
|
||||
QStringList borderParams = commands->value(i++);
|
||||
bool isUnknownMapBorder = borderParams.value(1).startsWith("UnknownMapBorder_");
|
||||
if (borderParams.value(0) != ".label" || (!borderParams.value(1).endsWith("_MapBorder") && !isUnknownMapBorder)) {
|
||||
qDebug() << QString("Expected MapBorder label, but found %1").arg(borderParams.value(1));
|
||||
continue;
|
||||
}
|
||||
QString borderLabel = borderParams.value(1);
|
||||
QString mapName;
|
||||
if (!isUnknownMapBorder) {
|
||||
mapName = borderLabel.remove(borderLabel.length() - 10, 10);
|
||||
} else {
|
||||
// Unknown map name has to match the MapAttributes label.
|
||||
mapName = borderLabel.replace("Border", "Attributes");
|
||||
}
|
||||
mapAttributes->insert(mapName, new QMap<QString, QString>);
|
||||
mapAttributes->value(mapName)->insert("border_label", borderParams.value(1));
|
||||
borderParams = commands->value(i++);
|
||||
mapAttributes->value(mapName)->insert("border_filepath", borderParams.value(1).replace("\"", ""));
|
||||
|
||||
// Read MapBlockData assets.
|
||||
QStringList blockDataParams = commands->value(i++);
|
||||
bool isUnknownMapBlockdata = blockDataParams.value(1).startsWith("UnknownMapBlockdata_");
|
||||
if (blockDataParams.value(0) != ".label" || (!blockDataParams.value(1).endsWith("_MapBlockdata") && !isUnknownMapBlockdata)) {
|
||||
qDebug() << QString("Expected MapBlockdata label, but found %1").arg(blockDataParams.value(1));
|
||||
continue;
|
||||
}
|
||||
QString blockDataLabel = blockDataParams.value(1);
|
||||
mapAttributes->value(mapName)->insert("blockdata_label", blockDataLabel);
|
||||
blockDataParams = commands->value(i++);
|
||||
mapAttributes->value(mapName)->insert("blockdata_filepath", blockDataParams.value(1).replace("\"", ""));
|
||||
|
||||
// Read MapAttributes assets.
|
||||
i++; // skip .align
|
||||
// Maps can share MapAttributes, so gather a list of them.
|
||||
QStringList attributeMapLabels;
|
||||
QStringList attributesParams;
|
||||
while (i < commands->length()) {
|
||||
attributesParams = commands->value(i);
|
||||
if (attributesParams.value(0) != ".label") {
|
||||
break;
|
||||
}
|
||||
attributeMapLabels.append(attributesParams.value(1));
|
||||
i++;
|
||||
}
|
||||
|
||||
// Apply the map attributes to each of the shared maps.
|
||||
QString attrWidth = commands->value(i++).value(1);
|
||||
QString attrHeight = commands->value(i++).value(1);
|
||||
QString attrBorderLabel = commands->value(i++).value(1);
|
||||
QString attrBlockdataLabel = commands->value(i++).value(1);
|
||||
QString attrTilesetPrimary = commands->value(i++).value(1);
|
||||
QString attrTilesetSecondary = commands->value(i++).value(1);
|
||||
for (QString attributeMapLabel: attributeMapLabels) {
|
||||
QString altMapName = attributeMapLabel;
|
||||
if (!altMapName.startsWith("UnknownMapAttributes_")) {
|
||||
altMapName.remove(altMapName.length() - 14, 14);
|
||||
}
|
||||
if (!mapAttributes->contains(altMapName)) {
|
||||
mapAttributes->insert(altMapName, new QMap<QString, QString>);
|
||||
}
|
||||
mapAttributes->value(altMapName)->insert("attributes_label", attributeMapLabel);
|
||||
mapAttributes->value(altMapName)->insert("width", attrWidth);
|
||||
mapAttributes->value(altMapName)->insert("height", attrHeight);
|
||||
mapAttributes->value(altMapName)->insert("border_label", attrBorderLabel);
|
||||
mapAttributes->value(altMapName)->insert("blockdata_label", attrBlockdataLabel);
|
||||
mapAttributes->value(altMapName)->insert("tileset_primary", attrTilesetPrimary);
|
||||
mapAttributes->value(altMapName)->insert("tileset_secondary", attrTilesetSecondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Project::setNewMapAttributes(Map* map) {
|
||||
map->width = "20";
|
||||
map->height = "20";
|
||||
|
|
|
@ -20,6 +20,8 @@ public:
|
|||
QMap<QString, QString> *mapConstantsToMapNames;
|
||||
QMap<QString, QString> *mapNamesToMapConstants;
|
||||
QMap<int, QString> *mapAttributesTable;
|
||||
QMap<QString, QMap<QString, QString>*> *mapAttributes;
|
||||
|
||||
|
||||
QMap<QString, Map*> *map_cache;
|
||||
Map* loadMap(QString);
|
||||
|
@ -44,6 +46,7 @@ public:
|
|||
QStringList* getLabelValues(QList<QStringList>*, QString);
|
||||
void readMapHeader(Map*);
|
||||
void readMapAttributesTable();
|
||||
void readAllMapAttributes();
|
||||
void readMapAttributes(Map*);
|
||||
void getTilesets(Map*);
|
||||
void loadTilesetAssets(Tileset*);
|
||||
|
|
Loading…
Reference in a new issue