Load and save the gMapAttributes array
This commit is contained in:
parent
f6cb002592
commit
40a0fbee02
5 changed files with 72 additions and 4 deletions
|
@ -9,6 +9,7 @@ Editor::Editor()
|
||||||
|
|
||||||
void Editor::saveProject() {
|
void Editor::saveProject() {
|
||||||
if (project) {
|
if (project) {
|
||||||
|
project->saveAllDataStructures();
|
||||||
project->saveAllMaps();
|
project->saveAllMaps();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,10 +61,12 @@ void MainWindow::openProject(QString dir) {
|
||||||
editor->project = new Project;
|
editor->project = new Project;
|
||||||
editor->project->root = dir;
|
editor->project->root = dir;
|
||||||
setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
|
setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
|
||||||
|
loadDataStructures();
|
||||||
populateMapList();
|
populateMapList();
|
||||||
setMap(getDefaultMap());
|
setMap(getDefaultMap());
|
||||||
} else {
|
} else {
|
||||||
setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
|
setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
|
||||||
|
loadDataStructures();
|
||||||
populateMapList();
|
populateMapList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,6 +280,10 @@ void MainWindow::on_checkBox_ShowLocation_clicked(bool checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::loadDataStructures() {
|
||||||
|
Project *project = editor->project;
|
||||||
|
project->readMapAttributesTable();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::populateMapList() {
|
void MainWindow::populateMapList() {
|
||||||
Project *project = editor->project;
|
Project *project = editor->project;
|
||||||
|
|
|
@ -76,6 +76,7 @@ private:
|
||||||
Editor *editor = NULL;
|
Editor *editor = NULL;
|
||||||
QIcon* mapIcon;
|
QIcon* mapIcon;
|
||||||
void setMap(QString);
|
void setMap(QString);
|
||||||
|
void loadDataStructures();
|
||||||
void populateMapList();
|
void populateMapList();
|
||||||
QString getExistingDirectory(QString);
|
QString getExistingDirectory(QString);
|
||||||
void openProject(QString dir);
|
void openProject(QString dir);
|
||||||
|
|
60
project.cpp
60
project.cpp
|
@ -22,6 +22,7 @@ Project::Project()
|
||||||
map_cache = new QMap<QString, Map*>;
|
map_cache = new QMap<QString, Map*>;
|
||||||
mapConstantsToMapNames = new QMap<QString, QString>;
|
mapConstantsToMapNames = new QMap<QString, QString>;
|
||||||
mapNamesToMapConstants = new QMap<QString, QString>;
|
mapNamesToMapConstants = new QMap<QString, QString>;
|
||||||
|
mapAttributesTable = new QMap<int, QString>;
|
||||||
tileset_cache = new QMap<QString, Tileset*>;
|
tileset_cache = new QMap<QString, Tileset*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +172,53 @@ void Project::saveMapHeader(Map *map) {
|
||||||
saveTextFile(header_path, text);
|
saveTextFile(header_path, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::readMapAttributesTable() {
|
||||||
|
int curMapIndex = 1;
|
||||||
|
QString attributesText = readTextFile(getMapAttributesTableFilepath());
|
||||||
|
QList<QStringList>* values = parse(attributesText);
|
||||||
|
bool inAttributePointers = false;
|
||||||
|
for (int i = 0; i < values->length(); i++) {
|
||||||
|
QStringList params = values->value(i);
|
||||||
|
QString macro = params.value(0);
|
||||||
|
if (macro == ".label") {
|
||||||
|
if (inAttributePointers) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (params.value(1) == "gMapAttributes") {
|
||||||
|
inAttributePointers = true;
|
||||||
|
}
|
||||||
|
} else if (macro == ".4byte" && inAttributePointers) {
|
||||||
|
QString mapName = params.value(1);
|
||||||
|
if (!mapName.contains("UnknownMapAttributes")) {
|
||||||
|
// Strip off "_MapAttributes" from the label if it's a real map label.
|
||||||
|
mapName = mapName.remove(mapName.length() - 14, 14);
|
||||||
|
}
|
||||||
|
mapAttributesTable->insert(curMapIndex, mapName);
|
||||||
|
curMapIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::saveMapAttributesTable() {
|
||||||
|
QString text = "";
|
||||||
|
text += QString("\t.align 2\n");
|
||||||
|
text += QString("gMapAttributes::\n");
|
||||||
|
for (int i = 0; i < mapAttributesTable->count(); i++) {
|
||||||
|
int mapIndex = i + 1;
|
||||||
|
QString mapName = mapAttributesTable->value(mapIndex);
|
||||||
|
if (!mapName.contains("UnknownMapAttributes")) {
|
||||||
|
text += QString("\t.4byte %1_MapAttributes\n").arg(mapName);
|
||||||
|
} else {
|
||||||
|
text += QString("\t.4byte %1\n").arg(mapName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveTextFile(getMapAttributesTableFilepath(), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Project::getMapAttributesTableFilepath() {
|
||||||
|
return QString("%1/data/maps/attributes_table.inc").arg(root);
|
||||||
|
}
|
||||||
|
|
||||||
void Project::readMapAttributes(Map* map) {
|
void Project::readMapAttributes(Map* map) {
|
||||||
Asm *parser = new Asm;
|
Asm *parser = new Asm;
|
||||||
|
|
||||||
|
@ -277,6 +325,10 @@ void Project::saveMap(Map *map) {
|
||||||
saveMapEvents(map);
|
saveMapEvents(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::saveAllDataStructures() {
|
||||||
|
saveMapAttributesTable();
|
||||||
|
}
|
||||||
|
|
||||||
void Project::loadTilesetAssets(Tileset* tileset) {
|
void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
Asm* parser = new Asm;
|
Asm* parser = new Asm;
|
||||||
QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
|
QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
|
||||||
|
@ -543,8 +595,6 @@ void Project::readMapGroups() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::addNewMapToGroup(QString mapName, int groupNum) {
|
void Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
int mapIndex = 0;// TODO: need to calculate the new map index.
|
|
||||||
|
|
||||||
// Write new map to project files.
|
// Write new map to project files.
|
||||||
// 1. Create directory data/maps/<map_name>/
|
// 1. Create directory data/maps/<map_name>/
|
||||||
// 2. Create file data/maps/<map_name>/border.bin
|
// 2. Create file data/maps/<map_name>/border.bin
|
||||||
|
@ -563,10 +613,14 @@ void Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
// 12. Modify data/maps/attributes_table.inc
|
// 12. Modify data/maps/attributes_table.inc
|
||||||
// 13. Modify data/maps/headers.inc
|
// 13. Modify data/maps/headers.inc
|
||||||
|
|
||||||
// 1. Create directory data/maps/<map_name>/
|
int mapIndex = mapAttributesTable->count() + 1;
|
||||||
|
mapAttributesTable->insert(mapIndex, mapName);
|
||||||
|
|
||||||
QString dataDir = QString("%1/data/").arg(root);
|
QString dataDir = QString("%1/data/").arg(root);
|
||||||
QString dataMapsDir = QString("%1maps/").arg(dataDir);
|
QString dataMapsDir = QString("%1maps/").arg(dataDir);
|
||||||
QString newMapDataDir = QString("%1%2/").arg(dataMapsDir).arg(mapName);
|
QString newMapDataDir = QString("%1%2/").arg(dataMapsDir).arg(mapName);
|
||||||
|
|
||||||
|
// 1. Create directory data/maps/<map_name>/
|
||||||
if (!QDir::root().mkdir(newMapDataDir)) {
|
if (!QDir::root().mkdir(newMapDataDir)) {
|
||||||
qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
|
qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
QStringList *mapNames = NULL;
|
QStringList *mapNames = NULL;
|
||||||
QMap<QString, QString> *mapConstantsToMapNames;
|
QMap<QString, QString> *mapConstantsToMapNames;
|
||||||
QMap<QString, QString> *mapNamesToMapConstants;
|
QMap<QString, QString> *mapNamesToMapConstants;
|
||||||
|
QMap<int, QString> *mapAttributesTable;
|
||||||
|
|
||||||
QMap<QString, Map*> *map_cache;
|
QMap<QString, Map*> *map_cache;
|
||||||
Map* loadMap(QString);
|
Map* loadMap(QString);
|
||||||
|
@ -42,6 +43,7 @@ public:
|
||||||
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
|
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
|
||||||
QStringList* getLabelValues(QList<QStringList>*, QString);
|
QStringList* getLabelValues(QList<QStringList>*, QString);
|
||||||
void readMapHeader(Map*);
|
void readMapHeader(Map*);
|
||||||
|
void readMapAttributesTable();
|
||||||
void readMapAttributes(Map*);
|
void readMapAttributes(Map*);
|
||||||
void getTilesets(Map*);
|
void getTilesets(Map*);
|
||||||
void loadTilesetAssets(Tileset*);
|
void loadTilesetAssets(Tileset*);
|
||||||
|
@ -51,7 +53,7 @@ public:
|
||||||
void writeBlockdata(QString, Blockdata*);
|
void writeBlockdata(QString, Blockdata*);
|
||||||
void saveAllMaps();
|
void saveAllMaps();
|
||||||
void saveMap(Map*);
|
void saveMap(Map*);
|
||||||
void saveMapHeader(Map*);
|
void saveAllDataStructures();
|
||||||
|
|
||||||
QList<QStringList>* parse(QString text);
|
QList<QStringList>* parse(QString text);
|
||||||
QStringList getSongNames();
|
QStringList getSongNames();
|
||||||
|
@ -77,6 +79,10 @@ public:
|
||||||
QStringList readCArray(QString text, QString label);
|
QStringList readCArray(QString text, QString label);
|
||||||
QString readCIncbin(QString text, QString label);
|
QString readCIncbin(QString text, QString label);
|
||||||
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
||||||
|
private:
|
||||||
|
QString getMapAttributesTableFilepath();
|
||||||
|
void saveMapHeader(Map*);
|
||||||
|
void saveMapAttributesTable();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROJECT_H
|
#endif // PROJECT_H
|
||||||
|
|
Loading…
Reference in a new issue