Properly support saving map connections
This commit is contained in:
parent
6f71c15629
commit
9b0f686781
4 changed files with 94 additions and 19 deletions
|
@ -409,6 +409,7 @@ void Editor::displayMapConnections() {
|
||||||
for (ConnectionPixmapItem* item : connection_edit_items) {
|
for (ConnectionPixmapItem* item : connection_edit_items) {
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
current_connection_edit_item = NULL;
|
||||||
connection_edit_items.clear();
|
connection_edit_items.clear();
|
||||||
|
|
||||||
for (Connection *connection : map->connections) {
|
for (Connection *connection : map->connections) {
|
||||||
|
|
|
@ -289,6 +289,7 @@ void MainWindow::loadDataStructures() {
|
||||||
project->readItemNames();
|
project->readItemNames();
|
||||||
project->readFlagNames();
|
project->readFlagNames();
|
||||||
project->readVarNames();
|
project->readVarNames();
|
||||||
|
project->readMapsWithConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::populateMapList() {
|
void MainWindow::populateMapList() {
|
||||||
|
|
106
project.cpp
106
project.cpp
|
@ -197,7 +197,14 @@ void Project::saveMapHeader(Map *map) {
|
||||||
text += QString("\t.4byte %1\n").arg(map->attributes_label);
|
text += QString("\t.4byte %1\n").arg(map->attributes_label);
|
||||||
text += QString("\t.4byte %1\n").arg(map->events_label);
|
text += QString("\t.4byte %1\n").arg(map->events_label);
|
||||||
text += QString("\t.4byte %1\n").arg(map->scripts_label);
|
text += QString("\t.4byte %1\n").arg(map->scripts_label);
|
||||||
|
|
||||||
|
if (map->connections.length() == 0) {
|
||||||
|
map->connections_label = "0x0";
|
||||||
|
} else {
|
||||||
|
map->connections_label = QString("%1_MapConnections").arg(map->name);
|
||||||
|
}
|
||||||
text += QString("\t.4byte %1\n").arg(map->connections_label);
|
text += QString("\t.4byte %1\n").arg(map->connections_label);
|
||||||
|
|
||||||
text += QString("\t.2byte %1\n").arg(map->song);
|
text += QString("\t.2byte %1\n").arg(map->song);
|
||||||
text += QString("\t.2byte %1\n").arg(map->index);
|
text += QString("\t.2byte %1\n").arg(map->index);
|
||||||
text += QString("\t.byte %1\n").arg(map->location);
|
text += QString("\t.byte %1\n").arg(map->location);
|
||||||
|
@ -211,27 +218,45 @@ void Project::saveMapHeader(Map *map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveMapConnections(Map *map) {
|
void Project::saveMapConnections(Map *map) {
|
||||||
QString connections_path = root + "/data/maps/" + map->name + "/connections.inc";
|
QString path = root + "/data/maps/" + map->name + "/connections.inc";
|
||||||
QString connectionsListLabel = QString("%1_MapConnectionsList").arg(map->name);
|
if (map->connections.length() > 0) {
|
||||||
int numValidConnections = 0;
|
QString text = "";
|
||||||
QString text = "";
|
QString connectionsListLabel = QString("%1_MapConnectionsList").arg(map->name);
|
||||||
text += QString("%1::\n").arg(connectionsListLabel);
|
int numValidConnections = 0;
|
||||||
for (Connection* connection : map->connections) {
|
text += QString("%1::\n").arg(connectionsListLabel);
|
||||||
if (mapNamesToMapConstants->contains(connection->map_name)) {
|
for (Connection* connection : map->connections) {
|
||||||
text += QString("\tconnection %1, %2, %3\n")
|
if (mapNamesToMapConstants->contains(connection->map_name)) {
|
||||||
.arg(connection->direction)
|
text += QString("\tconnection %1, %2, %3\n")
|
||||||
.arg(connection->offset)
|
.arg(connection->direction)
|
||||||
.arg(mapNamesToMapConstants->value(connection->map_name));
|
.arg(connection->offset)
|
||||||
numValidConnections++;
|
.arg(mapNamesToMapConstants->value(connection->map_name));
|
||||||
} else {
|
numValidConnections++;
|
||||||
qDebug() << QString("Failed to write map connection. %1 not a valid map name").arg(connection->map_name);
|
} else {
|
||||||
|
qDebug() << QString("Failed to write map connection. %1 not a valid map name").arg(connection->map_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
text += QString("\n");
|
||||||
|
text += QString("%1::\n").arg(map->connections_label);
|
||||||
|
text += QString("\t.4byte %1\n").arg(numValidConnections);
|
||||||
|
text += QString("\t.4byte %1\n").arg(connectionsListLabel);
|
||||||
|
saveTextFile(path, text);
|
||||||
|
} else {
|
||||||
|
deleteFile(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMapsWithConnections(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::updateMapsWithConnections(Map *map) {
|
||||||
|
if (map->connections.length() > 0) {
|
||||||
|
if (!mapsWithConnections.contains(map->name)) {
|
||||||
|
mapsWithConnections.append(map->name);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mapsWithConnections.contains(map->name)) {
|
||||||
|
mapsWithConnections.removeOne(map->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text += QString("\n");
|
|
||||||
text += QString("%1::\n").arg(map->connections_label);
|
|
||||||
text += QString("\t.4byte %1\n").arg(numValidConnections);
|
|
||||||
text += QString("\t.4byte %1\n").arg(connectionsListLabel);
|
|
||||||
saveTextFile(connections_path, text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readMapAttributesTable() {
|
void Project::readMapAttributesTable() {
|
||||||
|
@ -728,6 +753,7 @@ void Project::saveAllDataStructures() {
|
||||||
saveAllMapAttributes();
|
saveAllMapAttributes();
|
||||||
saveMapGroupsTable();
|
saveMapGroupsTable();
|
||||||
saveMapConstantsHeader();
|
saveMapConstantsHeader();
|
||||||
|
saveMapsWithConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::loadTilesetAssets(Tileset* tileset) {
|
void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
|
@ -939,6 +965,13 @@ void Project::appendTextFile(QString path, QString text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::deleteFile(QString path) {
|
||||||
|
QFile file(path);
|
||||||
|
if (file.exists() && !file.remove()) {
|
||||||
|
qDebug() << QString("Could not delete file '%1': ").arg(path) + file.errorString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Project::readMapGroups() {
|
void Project::readMapGroups() {
|
||||||
QString text = readTextFile(root + "/data/maps/_groups.inc");
|
QString text = readTextFile(root + "/data/maps/_groups.inc");
|
||||||
if (text.isNull()) {
|
if (text.isNull()) {
|
||||||
|
@ -1124,6 +1157,41 @@ void Project::readCDefinesSorted(QString filepath, QStringList prefixes, QString
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::readMapsWithConnections() {
|
||||||
|
QString path = root + "/data/maps/connections.inc";
|
||||||
|
QString text = readTextFile(path);
|
||||||
|
if (text.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapsWithConnections.clear();
|
||||||
|
QRegularExpression re("data\\/maps\\/(?<mapName>\\w+)\\/connections.inc");
|
||||||
|
QList<QStringList>* includes = parseAsm(text);
|
||||||
|
for (QStringList values : *includes) {
|
||||||
|
if (values.length() != 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QRegularExpressionMatch match = re.match(values.value(1));
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
QString mapName = match.captured("mapName");
|
||||||
|
mapsWithConnections.append(mapName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::saveMapsWithConnections() {
|
||||||
|
QString path = root + "/data/maps/connections.inc";
|
||||||
|
QString text = "";
|
||||||
|
for (QString mapName : mapsWithConnections) {
|
||||||
|
if (mapNamesToMapConstants->contains(mapName)) {
|
||||||
|
text += QString("\t.include \"data/maps/%1/connections.inc\"\n").arg(mapName);
|
||||||
|
} else {
|
||||||
|
qDebug() << QString("Failed to write connection include. %1 not a valid map name").arg(mapName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveTextFile(path, text);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList Project::getSongNames() {
|
QStringList Project::getSongNames() {
|
||||||
QStringList names;
|
QStringList names;
|
||||||
QString text = readTextFile(root + "/include/constants/songs.h");
|
QString text = readTextFile(root + "/include/constants/songs.h");
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
QStringList *itemNames = NULL;
|
QStringList *itemNames = NULL;
|
||||||
QStringList *flagNames = NULL;
|
QStringList *flagNames = NULL;
|
||||||
QStringList *varNames = NULL;
|
QStringList *varNames = NULL;
|
||||||
|
QStringList mapsWithConnections;
|
||||||
|
|
||||||
QMap<QString, Map*> *map_cache;
|
QMap<QString, Map*> *map_cache;
|
||||||
Map* loadMap(QString);
|
Map* loadMap(QString);
|
||||||
|
@ -41,6 +42,7 @@ public:
|
||||||
QString readTextFile(QString path);
|
QString readTextFile(QString path);
|
||||||
void saveTextFile(QString path, QString text);
|
void saveTextFile(QString path, QString text);
|
||||||
void appendTextFile(QString path, QString text);
|
void appendTextFile(QString path, QString text);
|
||||||
|
void deleteFile(QString path);
|
||||||
|
|
||||||
void readMapGroups();
|
void readMapGroups();
|
||||||
Map* addNewMapToGroup(QString mapName, int groupNum);
|
Map* addNewMapToGroup(QString mapName, int groupNum);
|
||||||
|
@ -53,6 +55,7 @@ public:
|
||||||
void readMapAttributesTable();
|
void readMapAttributesTable();
|
||||||
void readAllMapAttributes();
|
void readAllMapAttributes();
|
||||||
void readMapAttributes(Map*);
|
void readMapAttributes(Map*);
|
||||||
|
void readMapsWithConnections();
|
||||||
void getTilesets(Map*);
|
void getTilesets(Map*);
|
||||||
void loadTilesetAssets(Tileset*);
|
void loadTilesetAssets(Tileset*);
|
||||||
|
|
||||||
|
@ -98,6 +101,8 @@ private:
|
||||||
QString getMapAssetsFilepath();
|
QString getMapAssetsFilepath();
|
||||||
void saveMapHeader(Map*);
|
void saveMapHeader(Map*);
|
||||||
void saveMapConnections(Map*);
|
void saveMapConnections(Map*);
|
||||||
|
void updateMapsWithConnections(Map*);
|
||||||
|
void saveMapsWithConnections();
|
||||||
void saveMapAttributesTable();
|
void saveMapAttributesTable();
|
||||||
void updateMapAttributes(Map* map);
|
void updateMapAttributes(Map* map);
|
||||||
void readCDefinesSorted(QString, QStringList, QStringList*);
|
void readCDefinesSorted(QString, QStringList, QStringList*);
|
||||||
|
|
Loading…
Reference in a new issue