Maintain master and working copies of data structures, to enable saving single maps at a time
This commit is contained in:
parent
17e5892cd4
commit
e4c5d53ffd
4 changed files with 116 additions and 224 deletions
|
@ -9,14 +9,15 @@ Editor::Editor()
|
||||||
|
|
||||||
void Editor::saveProject() {
|
void Editor::saveProject() {
|
||||||
if (project) {
|
if (project) {
|
||||||
project->saveAllDataStructures();
|
|
||||||
project->saveAllMaps();
|
project->saveAllMaps();
|
||||||
|
project->saveAllDataStructures();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::save() {
|
void Editor::save() {
|
||||||
if (project && map) {
|
if (project && map) {
|
||||||
project->saveMap(map);
|
project->saveMap(map);
|
||||||
|
project->saveAllDataStructures();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,26 +73,26 @@ void MainWindow::openProject(QString dir) {
|
||||||
|
|
||||||
QString MainWindow::getDefaultMap() {
|
QString MainWindow::getDefaultMap() {
|
||||||
if (editor && editor->project) {
|
if (editor && editor->project) {
|
||||||
QList<QStringList*> *names = editor->project->groupedMapNames;
|
QList<QStringList> names = editor->project->groupedMapNames;
|
||||||
if (names) {
|
if (!names.isEmpty()) {
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString key = "project:" + editor->project->root;
|
QString key = "project:" + editor->project->root;
|
||||||
if (settings.contains(key)) {
|
if (settings.contains(key)) {
|
||||||
QMap<QString, QVariant> qmap = settings.value(key).toMap();
|
QMap<QString, QVariant> qmap = settings.value(key).toMap();
|
||||||
if (qmap.contains("recent_map")) {
|
if (qmap.contains("recent_map")) {
|
||||||
QString map_name = qmap.value("recent_map").toString();
|
QString map_name = qmap.value("recent_map").toString();
|
||||||
for (int i = 0; i < names->length(); i++) {
|
for (int i = 0; i < names.length(); i++) {
|
||||||
if (names->value(i)->contains(map_name)) {
|
if (names.value(i).contains(map_name)) {
|
||||||
return map_name;
|
return map_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Failing that, just get the first map in the list.
|
// Failing that, just get the first map in the list.
|
||||||
for (int i = 0; i < names->length(); i++) {
|
for (int i = 0; i < names.length(); i++) {
|
||||||
QStringList *list = names->value(i);
|
QStringList list = names.value(i);
|
||||||
if (list->length()) {
|
if (list.length()) {
|
||||||
return list->value(0);
|
return list.value(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,9 +327,9 @@ void MainWindow::populateMapList() {
|
||||||
group->setData(i, MapListUserRoles::GroupRole);
|
group->setData(i, MapListUserRoles::GroupRole);
|
||||||
maps->appendRow(group);
|
maps->appendRow(group);
|
||||||
mapGroupsModel->append(group);
|
mapGroupsModel->append(group);
|
||||||
QStringList *names = project->groupedMapNames->value(i);
|
QStringList names = project->groupedMapNames.value(i);
|
||||||
for (int j = 0; j < names->length(); j++) {
|
for (int j = 0; j < names.length(); j++) {
|
||||||
QString map_name = names->value(j);
|
QString map_name = names.value(j);
|
||||||
QStandardItem *map = createMapItem(map_name, i, j);
|
QStandardItem *map = createMapItem(map_name, i, j);
|
||||||
group->appendRow(map);
|
group->appendRow(map);
|
||||||
}
|
}
|
||||||
|
@ -387,7 +387,9 @@ void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
|
||||||
QStandardItem* groupItem = mapGroupsModel->at(groupNum);
|
QStandardItem* groupItem = mapGroupsModel->at(groupNum);
|
||||||
|
|
||||||
QString newMapName = editor->project->getNewMapName();
|
QString newMapName = editor->project->getNewMapName();
|
||||||
editor->project->addNewMapToGroup(newMapName, groupNum);
|
Map* newMap = editor->project->addNewMapToGroup(newMapName, groupNum);
|
||||||
|
editor->project->saveMap(newMap);
|
||||||
|
editor->project->saveAllDataStructures();
|
||||||
|
|
||||||
int numMapsInGroup = groupItem->rowCount();
|
int numMapsInGroup = groupItem->rowCount();
|
||||||
QStandardItem *newMapItem = createMapItem(newMapName, groupNum, numMapsInGroup);
|
QStandardItem *newMapItem = createMapItem(newMapName, groupNum, numMapsInGroup);
|
||||||
|
|
296
project.cpp
296
project.cpp
|
@ -17,13 +17,10 @@ Project::Project()
|
||||||
{
|
{
|
||||||
groupNames = new QStringList;
|
groupNames = new QStringList;
|
||||||
map_groups = new QMap<QString, int>;
|
map_groups = new QMap<QString, int>;
|
||||||
groupedMapNames = new QList<QStringList*>;
|
|
||||||
mapNames = new QStringList;
|
mapNames = new QStringList;
|
||||||
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>;
|
|
||||||
mapAttributes = new QMap<QString, QMap<QString, QString>*>;
|
|
||||||
tileset_cache = new QMap<QString, Tileset*>;
|
tileset_cache = new QMap<QString, Tileset*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +33,12 @@ QString Project::getProjectTitle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map* Project::loadMap(QString map_name) {
|
Map* Project::loadMap(QString map_name) {
|
||||||
// New maps are saved to actual files yet, so we need to fetch their data from the map_cache.
|
|
||||||
Map *map;
|
Map *map;
|
||||||
if (map_cache->contains(map_name) && !map_cache->value(map_name)->isPersistedToFile) {
|
if (map_cache->contains(map_name)) {
|
||||||
map = map_cache->value(map_name);
|
map = map_cache->value(map_name);
|
||||||
|
if (map->hasUnsavedChanges()) {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
map = new Map;
|
map = new Map;
|
||||||
map->setName(map_name);
|
map->setName(map_name);
|
||||||
|
@ -228,19 +227,22 @@ void Project::readMapAttributesTable() {
|
||||||
// Strip off "_MapAttributes" from the label if it's a real map label.
|
// Strip off "_MapAttributes" from the label if it's a real map label.
|
||||||
mapName = mapName.remove(mapName.length() - 14, 14);
|
mapName = mapName.remove(mapName.length() - 14, 14);
|
||||||
}
|
}
|
||||||
mapAttributesTable->insert(curMapIndex, mapName);
|
mapAttributesTable.insert(curMapIndex, mapName);
|
||||||
curMapIndex++;
|
curMapIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapAttributesTableMaster = mapAttributesTable;
|
||||||
|
mapAttributesTableMaster.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveMapAttributesTable() {
|
void Project::saveMapAttributesTable() {
|
||||||
QString text = "";
|
QString text = "";
|
||||||
text += QString("\t.align 2\n");
|
text += QString("\t.align 2\n");
|
||||||
text += QString("gMapAttributes::\n");
|
text += QString("gMapAttributes::\n");
|
||||||
for (int i = 0; i < mapAttributesTable->count(); i++) {
|
for (int i = 0; i < mapAttributesTableMaster.count(); i++) {
|
||||||
int mapIndex = i + 1;
|
int mapIndex = i + 1;
|
||||||
QString mapName = mapAttributesTable->value(mapIndex);
|
QString mapName = mapAttributesTableMaster.value(mapIndex);
|
||||||
if (!mapName.contains("UnknownMapAttributes")) {
|
if (!mapName.contains("UnknownMapAttributes")) {
|
||||||
text += QString("\t.4byte %1_MapAttributes\n").arg(mapName);
|
text += QString("\t.4byte %1_MapAttributes\n").arg(mapName);
|
||||||
} else {
|
} else {
|
||||||
|
@ -275,7 +277,7 @@ void Project::readMapAttributes(Map* map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readAllMapAttributes() {
|
void Project::readAllMapAttributes() {
|
||||||
mapAttributes->clear();
|
mapAttributes.clear();
|
||||||
|
|
||||||
Asm *parser = new Asm;
|
Asm *parser = new Asm;
|
||||||
QString assets_text = readTextFile(getMapAssetsFilepath());
|
QString assets_text = readTextFile(getMapAssetsFilepath());
|
||||||
|
@ -307,11 +309,9 @@ void Project::readAllMapAttributes() {
|
||||||
mapName = borderLabel.replace("Border", "Attributes");
|
mapName = borderLabel.replace("Border", "Attributes");
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QString>* attrs = new QMap<QString, QString>;
|
mapAttributes[mapName].insert("border_label", borderParams.value(1));
|
||||||
mapAttributes->insert(mapName, attrs);
|
|
||||||
attrs->insert("border_label", borderParams.value(1));
|
|
||||||
borderParams = commands->value(i++);
|
borderParams = commands->value(i++);
|
||||||
attrs->insert("border_filepath", borderParams.value(1).replace("\"", ""));
|
mapAttributes[mapName].insert("border_filepath", borderParams.value(1).replace("\"", ""));
|
||||||
|
|
||||||
// Read MapBlockData assets.
|
// Read MapBlockData assets.
|
||||||
QStringList blockDataParams = commands->value(i++);
|
QStringList blockDataParams = commands->value(i++);
|
||||||
|
@ -321,9 +321,9 @@ void Project::readAllMapAttributes() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QString blockDataLabel = blockDataParams.value(1);
|
QString blockDataLabel = blockDataParams.value(1);
|
||||||
attrs->insert("blockdata_label", blockDataLabel);
|
mapAttributes[mapName].insert("blockdata_label", blockDataLabel);
|
||||||
blockDataParams = commands->value(i++);
|
blockDataParams = commands->value(i++);
|
||||||
attrs->insert("blockdata_filepath", blockDataParams.value(1).replace("\"", ""));
|
mapAttributes[mapName].insert("blockdata_filepath", blockDataParams.value(1).replace("\"", ""));
|
||||||
|
|
||||||
// Read MapAttributes assets.
|
// Read MapAttributes assets.
|
||||||
i++; // skip .align
|
i++; // skip .align
|
||||||
|
@ -354,86 +354,90 @@ void Project::readAllMapAttributes() {
|
||||||
if (!altMapName.startsWith("UnknownMapAttributes_")) {
|
if (!altMapName.startsWith("UnknownMapAttributes_")) {
|
||||||
altMapName.remove(altMapName.length() - 14, 14);
|
altMapName.remove(altMapName.length() - 14, 14);
|
||||||
}
|
}
|
||||||
if (!mapAttributes->contains(altMapName)) {
|
if (!mapAttributes.contains(altMapName)) {
|
||||||
mapAttributes->insert(altMapName, new QMap<QString, QString>);
|
mapAttributes.insert(altMapName, QMap<QString, QString>());
|
||||||
}
|
}
|
||||||
mapAttributes->value(altMapName)->insert("attributes_label", attributeMapLabel);
|
mapAttributes[altMapName]["attributes_label"] = attributeMapLabel;
|
||||||
mapAttributes->value(altMapName)->insert("width", attrWidth);
|
mapAttributes[altMapName].insert("attributes_label", attributeMapLabel);
|
||||||
mapAttributes->value(altMapName)->insert("height", attrHeight);
|
mapAttributes[altMapName].insert("width", attrWidth);
|
||||||
mapAttributes->value(altMapName)->insert("border_label", attrBorderLabel);
|
mapAttributes[altMapName].insert("height", attrHeight);
|
||||||
mapAttributes->value(altMapName)->insert("blockdata_label", attrBlockdataLabel);
|
mapAttributes[altMapName].insert("border_label", attrBorderLabel);
|
||||||
mapAttributes->value(altMapName)->insert("tileset_primary", attrTilesetPrimary);
|
mapAttributes[altMapName].insert("blockdata_label", attrBlockdataLabel);
|
||||||
mapAttributes->value(altMapName)->insert("tileset_secondary", attrTilesetSecondary);
|
mapAttributes[altMapName].insert("tileset_primary", attrTilesetPrimary);
|
||||||
|
mapAttributes[altMapName].insert("tileset_secondary", attrTilesetSecondary);
|
||||||
|
|
||||||
if (sharedAttrMaps->length() > 1) {
|
if (sharedAttrMaps->length() > 1) {
|
||||||
mapAttributes->value(altMapName)->insert("shared_attr_maps", sharedAttrMaps->join(":"));
|
mapAttributes[altMapName].insert("shared_attr_maps", sharedAttrMaps->join(":"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapAttributesMaster = mapAttributes;
|
||||||
|
mapAttributesMaster.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveAllMapAttributes() {
|
void Project::saveAllMapAttributes() {
|
||||||
QString text = "";
|
QString text = "";
|
||||||
for (int i = 0; i < mapAttributesTable->count(); i++) {
|
for (int i = 0; i < mapAttributesTableMaster.count(); i++) {
|
||||||
int mapIndex = i + 1;
|
int mapIndex = i + 1;
|
||||||
QString mapName = mapAttributesTable->value(mapIndex);
|
QString mapName = mapAttributesTableMaster.value(mapIndex);
|
||||||
QMap<QString, QString>* attrs = mapAttributes->value(mapName);
|
QMap<QString, QString> attrs = mapAttributesMaster.value(mapName);
|
||||||
|
|
||||||
// Find the map attributes object that contains the border data.
|
// Find the map attributes object that contains the border data.
|
||||||
QMap<QString, QString>* attrsWithBorder;
|
QMap<QString, QString> attrsWithBorder;
|
||||||
if (attrs->contains("border_filepath")) {
|
if (attrs.contains("border_filepath")) {
|
||||||
attrsWithBorder = attrs;
|
attrsWithBorder = attrs;
|
||||||
} else {
|
} else {
|
||||||
QStringList labels = attrs->value("shared_attr_maps").split(":");
|
QStringList labels = attrs.value("shared_attr_maps").split(":");
|
||||||
for (QString label : labels) {
|
for (QString label : labels) {
|
||||||
label.remove(label.length() - 14, 14);
|
label.remove(label.length() - 14, 14);
|
||||||
if (mapAttributes->contains(label) && mapAttributes->value(label)->contains("border_filepath")) {
|
if (mapAttributesMaster.contains(label) && mapAttributesMaster.value(label).contains("border_filepath")) {
|
||||||
attrsWithBorder = mapAttributes->value(label);
|
attrsWithBorder = mapAttributesMaster.value(label);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (attrsWithBorder != nullptr) {
|
if (!attrsWithBorder.isEmpty()) {
|
||||||
text += QString("%1::\n").arg(attrsWithBorder->value("border_label"));
|
text += QString("%1::\n").arg(attrsWithBorder.value("border_label"));
|
||||||
text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder->value("border_filepath"));
|
text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder.value("border_filepath"));
|
||||||
text += QString("\n");
|
text += QString("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the map attributes object that contains the blockdata.
|
// Find the map attributes object that contains the blockdata.
|
||||||
QMap<QString, QString>* attrsWithBlockdata;
|
QMap<QString, QString> attrsWithBlockdata;
|
||||||
if (attrs->contains("blockdata_filepath")) {
|
if (attrs.contains("blockdata_filepath")) {
|
||||||
attrsWithBlockdata = attrs;
|
attrsWithBlockdata = attrs;
|
||||||
} else {
|
} else {
|
||||||
QStringList labels = attrs->value("shared_attr_maps").split(":");
|
QStringList labels = attrs["shared_attr_maps"].split(":");
|
||||||
for (QString label : labels) {
|
for (QString label : labels) {
|
||||||
label.remove(label.length() - 14, 14);
|
label.remove(label.length() - 14, 14);
|
||||||
if (mapAttributes->contains(label) && mapAttributes->value(label)->contains("blockdata_filepath")) {
|
if (mapAttributesMaster.contains(label) && mapAttributesMaster.value(label).contains("blockdata_filepath")) {
|
||||||
attrsWithBlockdata = mapAttributes->value(label);
|
attrsWithBlockdata = mapAttributesMaster.value(label);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (attrsWithBlockdata != nullptr) {
|
if (!attrsWithBlockdata.isEmpty()) {
|
||||||
text += QString("%1::\n").arg(attrsWithBlockdata->value("blockdata_label"));
|
text += QString("%1::\n").arg(attrsWithBlockdata.value("blockdata_label"));
|
||||||
text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder->value("blockdata_filepath"));
|
text += QString("\t.incbin \"%1\"\n").arg(attrsWithBorder.value("blockdata_filepath"));
|
||||||
text += QString("\n");
|
text += QString("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
text += QString("\t.align 2\n");
|
text += QString("\t.align 2\n");
|
||||||
if (attrs->contains("shared_attr_maps")) {
|
if (attrs.contains("shared_attr_maps")) {
|
||||||
QStringList labels = attrs->value("shared_attr_maps").split(":");
|
QStringList labels = attrs.value("shared_attr_maps").split(":");
|
||||||
for (QString label : labels) {
|
for (QString label : labels) {
|
||||||
text += QString("%1::\n").arg(label);
|
text += QString("%1::\n").arg(label);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
text += QString("%1::\n").arg(attrs->value("attributes_label"));
|
text += QString("%1::\n").arg(attrs.value("attributes_label"));
|
||||||
}
|
}
|
||||||
text += QString("\t.4byte %1\n").arg(attrs->value("width"));
|
text += QString("\t.4byte %1\n").arg(attrs.value("width"));
|
||||||
text += QString("\t.4byte %1\n").arg(attrs->value("height"));
|
text += QString("\t.4byte %1\n").arg(attrs.value("height"));
|
||||||
text += QString("\t.4byte %1\n").arg(attrs->value("border_label"));
|
text += QString("\t.4byte %1\n").arg(attrs.value("border_label"));
|
||||||
text += QString("\t.4byte %1\n").arg(attrs->value("blockdata_label"));
|
text += QString("\t.4byte %1\n").arg(attrs.value("blockdata_label"));
|
||||||
text += QString("\t.4byte %1\n").arg(attrs->value("tileset_primary"));
|
text += QString("\t.4byte %1\n").arg(attrs.value("tileset_primary"));
|
||||||
text += QString("\t.4byte %1\n").arg(attrs->value("tileset_secondary"));
|
text += QString("\t.4byte %1\n").arg(attrs.value("tileset_secondary"));
|
||||||
text += QString("\n");
|
text += QString("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,26 +457,26 @@ void Project::setNewMapAttributes(Map* map) {
|
||||||
map->tileset_secondary_label = "gTileset_Petalburg";
|
map->tileset_secondary_label = "gTileset_Petalburg";
|
||||||
|
|
||||||
// Insert new entry into the global map attributes.
|
// Insert new entry into the global map attributes.
|
||||||
QMap<QString, QString>* attrs = new QMap<QString, QString>;
|
QMap<QString, QString> attrs;
|
||||||
attrs->insert("border_label", QString("%1_MapBorder").arg(map->name));
|
attrs.insert("border_label", QString("%1_MapBorder").arg(map->name));
|
||||||
attrs->insert("border_filepath", QString("data/maps/%1/border.bin").arg(map->name));
|
attrs.insert("border_filepath", QString("data/maps/%1/border.bin").arg(map->name));
|
||||||
attrs->insert("blockdata_label", QString("%1_MapBlockdata").arg(map->name));
|
attrs.insert("blockdata_label", QString("%1_MapBlockdata").arg(map->name));
|
||||||
attrs->insert("blockdata_filepath", QString("data/maps/%1/map.bin").arg(map->name));
|
attrs.insert("blockdata_filepath", QString("data/maps/%1/map.bin").arg(map->name));
|
||||||
attrs->insert("attributes_label", QString("%1_MapAttributes").arg(map->name));
|
attrs.insert("attributes_label", QString("%1_MapAttributes").arg(map->name));
|
||||||
attrs->insert("width", map->width);
|
attrs.insert("width", map->width);
|
||||||
attrs->insert("height", map->height);
|
attrs.insert("height", map->height);
|
||||||
attrs->insert("tileset_primary", map->tileset_primary_label);
|
attrs.insert("tileset_primary", map->tileset_primary_label);
|
||||||
attrs->insert("tileset_secondary", map->tileset_secondary_label);
|
attrs.insert("tileset_secondary", map->tileset_secondary_label);
|
||||||
mapAttributes->insert(map->name, attrs);
|
mapAttributes.insert(map->name, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveMapGroupsTable() {
|
void Project::saveMapGroupsTable() {
|
||||||
QString text = "";
|
QString text = "";
|
||||||
int groupNum = 0;
|
int groupNum = 0;
|
||||||
for (QStringList* mapNames : *groupedMapNames) {
|
for (QStringList mapNames : groupedMapNames) {
|
||||||
text += QString("\t.align 2\n");
|
text += QString("\t.align 2\n");
|
||||||
text += QString("gMapGroup%1::\n").arg(groupNum);
|
text += QString("gMapGroup%1::\n").arg(groupNum);
|
||||||
for (QString mapName : *mapNames) {
|
for (QString mapName : mapNames) {
|
||||||
text += QString("\t.4byte %1\n").arg(mapName);
|
text += QString("\t.4byte %1\n").arg(mapName);
|
||||||
}
|
}
|
||||||
text += QString("\n");
|
text += QString("\n");
|
||||||
|
@ -610,6 +614,7 @@ void Project::saveMap(Map *map) {
|
||||||
qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
|
qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: In the future, these files needs more structure to allow for proper parsing/saving.
|
||||||
// Create file data/scripts/maps/<map_name>.inc
|
// Create file data/scripts/maps/<map_name>.inc
|
||||||
QString text = QString("%1_MapScripts::\n\t.byte 0\n").arg(map->name);
|
QString text = QString("%1_MapScripts::\n\t.byte 0\n").arg(map->name);
|
||||||
saveTextFile(root + "/data/scripts/maps/" + map->name + ".inc", text);
|
saveTextFile(root + "/data/scripts/maps/" + map->name + ".inc", text);
|
||||||
|
@ -618,7 +623,6 @@ void Project::saveMap(Map *map) {
|
||||||
saveTextFile(root + "/data/text/maps/" + map->name + ".inc", "\n");
|
saveTextFile(root + "/data/text/maps/" + map->name + ".inc", "\n");
|
||||||
|
|
||||||
// Simply append to data/event_scripts.s.
|
// Simply append to data/event_scripts.s.
|
||||||
// TODO: In the future, this file needs more structure to allow for proper parsing.
|
|
||||||
text = QString("\n\t.include \"data/scripts/maps/%1.inc\"\n").arg(map->name);
|
text = QString("\n\t.include \"data/scripts/maps/%1.inc\"\n").arg(map->name);
|
||||||
text += QString("\t.include \"data/text/maps/%1.inc\"\n").arg(map->name);
|
text += QString("\t.include \"data/text/maps/%1.inc\"\n").arg(map->name);
|
||||||
appendTextFile(root + "/data/event_scripts.s", text);
|
appendTextFile(root + "/data/event_scripts.s", text);
|
||||||
|
@ -636,9 +640,21 @@ void Project::saveMap(Map *map) {
|
||||||
saveMapHeader(map);
|
saveMapHeader(map);
|
||||||
saveBlockdata(map);
|
saveBlockdata(map);
|
||||||
saveMapEvents(map);
|
saveMapEvents(map);
|
||||||
|
|
||||||
|
// Update global data structures with current map data.
|
||||||
|
updateMapAttributes(map);
|
||||||
|
|
||||||
map->isPersistedToFile = true;
|
map->isPersistedToFile = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::updateMapAttributes(Map* map) {
|
||||||
|
mapAttributesTableMaster.insert(map->index.toInt(nullptr, 0), map->name);
|
||||||
|
|
||||||
|
QMap<QString, QString> attrs = mapAttributes.value(map->name);
|
||||||
|
attrs.detach();
|
||||||
|
mapAttributesMaster.insert(map->name, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
void Project::saveAllDataStructures() {
|
void Project::saveAllDataStructures() {
|
||||||
saveMapAttributesTable();
|
saveMapAttributesTable();
|
||||||
saveAllMapAttributes();
|
saveAllMapAttributes();
|
||||||
|
@ -883,10 +899,9 @@ void Project::readMapGroups() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QStringList*> *groupedMaps = new QList<QStringList*>;
|
QList<QStringList> groupedMaps;
|
||||||
for (int i = 0; i < groups->length(); i++) {
|
for (int i = 0; i < groups->length(); i++) {
|
||||||
QStringList *list = new QStringList;
|
groupedMaps.append(QStringList());
|
||||||
groupedMaps->append(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList *maps = new QStringList;
|
QStringList *maps = new QStringList;
|
||||||
|
@ -900,8 +915,7 @@ void Project::readMapGroups() {
|
||||||
if (group != -1) {
|
if (group != -1) {
|
||||||
for (int j = 1; j < params.length(); j++) {
|
for (int j = 1; j < params.length(); j++) {
|
||||||
QString mapName = params.value(j);
|
QString mapName = params.value(j);
|
||||||
QStringList *list = groupedMaps->value(group);
|
groupedMaps[group].append(mapName);
|
||||||
list->append(mapName);
|
|
||||||
maps->append(mapName);
|
maps->append(mapName);
|
||||||
map_groups->insert(mapName, group);
|
map_groups->insert(mapName, group);
|
||||||
|
|
||||||
|
@ -919,14 +933,14 @@ void Project::readMapGroups() {
|
||||||
mapNames = maps;
|
mapNames = maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::addNewMapToGroup(QString mapName, int groupNum) {
|
Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
int mapIndex = mapAttributesTable->count() + 1;
|
int mapIndex = mapAttributesTable.count() + 1;
|
||||||
mapAttributesTable->insert(mapIndex, mapName);
|
mapAttributesTable.insert(mapIndex, mapName);
|
||||||
|
|
||||||
// Setup new map in memory, but don't write to file until map is actually saved later.
|
// Setup new map in memory, but don't write to file until map is actually saved later.
|
||||||
mapNames->append(mapName);
|
mapNames->append(mapName);
|
||||||
map_groups->insert(mapName, groupNum);
|
map_groups->insert(mapName, groupNum);
|
||||||
groupedMapNames->value(groupNum)->append(mapName);
|
groupedMapNames[groupNum].append(mapName);
|
||||||
|
|
||||||
Map *map = new Map;
|
Map *map = new Map;
|
||||||
map->isPersistedToFile = false;
|
map->isPersistedToFile = false;
|
||||||
|
@ -942,135 +956,7 @@ void Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
map->history.save();
|
map->history.save();
|
||||||
map_cache->insert(mapName, map);
|
map_cache->insert(mapName, map);
|
||||||
|
|
||||||
|
return map;
|
||||||
// QString dataDir = QString("%1/data/").arg(root);
|
|
||||||
// QString dataMapsDir = QString("%1maps/").arg(dataDir);
|
|
||||||
// QString newMapDataDir = QString("%1%2/").arg(dataMapsDir).arg(mapName);
|
|
||||||
|
|
||||||
// // 1. Create directory data/maps/<map_name>/
|
|
||||||
// if (!QDir::root().mkdir(newMapDataDir)) {
|
|
||||||
// qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 2. Create file data/maps/<map_name>/border.bin
|
|
||||||
// QFile borderFile(newMapDataDir + "border.bin");
|
|
||||||
// borderFile.open(QIODevice::WriteOnly);
|
|
||||||
// QDataStream borderStream(&borderFile);
|
|
||||||
// borderStream.setByteOrder(QDataStream::LittleEndian);
|
|
||||||
// borderStream << qint16(0x01D4) << qint16(0x01D5) << qint16(0x01DC) << qint16(0x01DD);
|
|
||||||
// borderFile.close();
|
|
||||||
|
|
||||||
// // 3. Create file data/maps/<map_name>/header.inc
|
|
||||||
// QFile headerFile(newMapDataDir + "header.inc");
|
|
||||||
// headerFile.open(QIODevice::WriteOnly);
|
|
||||||
// QTextStream headerStream(&headerFile);
|
|
||||||
// headerStream << mapName << "::" << endl
|
|
||||||
// << "\t.4byte " << mapName << "_MapAttributes" << endl
|
|
||||||
// << "\t.4byte " << mapName << "_MapEvents" << endl
|
|
||||||
// << "\t.4byte " << mapName << "_MapScripts" << endl
|
|
||||||
// << "\t.4byte 0x0" << endl
|
|
||||||
// << "\t.2byte BGM_DAN02" << endl
|
|
||||||
// << "\t.2byte " << mapIndex << endl
|
|
||||||
// << "\t.byte 0" << endl
|
|
||||||
// << "\t.byte 0" << endl
|
|
||||||
// << "\t.byte 11" << endl
|
|
||||||
// << "\t.byte 4" << endl
|
|
||||||
// << "\t.2byte 0" << endl
|
|
||||||
// << "\t.byte 1" << endl
|
|
||||||
// << "\t.byte 0" << endl;
|
|
||||||
// headerFile.close();
|
|
||||||
|
|
||||||
// // 4. Create file data/maps/<map_name>/map.bin
|
|
||||||
// QFile mapFile(newMapDataDir + "map.bin");
|
|
||||||
// mapFile.open(QIODevice::WriteOnly);
|
|
||||||
// QDataStream mapStream(&mapFile);
|
|
||||||
// mapStream.setByteOrder(QDataStream::LittleEndian);
|
|
||||||
// for (int i = 0; i < 20 * 20; i++) {
|
|
||||||
// mapStream << qint16(0x3001);
|
|
||||||
// }
|
|
||||||
// mapFile.close();
|
|
||||||
|
|
||||||
// // 5. Create file data/maps/events/<map_name>.inc
|
|
||||||
// QFile eventsFile(dataMapsDir + "events/" + mapName + ".inc");
|
|
||||||
// eventsFile.open(QIODevice::WriteOnly);
|
|
||||||
// QTextStream eventsStream(&eventsFile);
|
|
||||||
// eventsStream << mapName << "_MapEvents::" << endl
|
|
||||||
// << "\tmap_events 0x0, 0x0, 0x0, 0x0" << endl;
|
|
||||||
// eventsFile.close();
|
|
||||||
|
|
||||||
// // 6. Create file data/scripts/maps/<map_name>.inc
|
|
||||||
// QFile scriptsFile(dataDir + "scripts/maps/" + mapName + ".inc");
|
|
||||||
// scriptsFile.open(QIODevice::WriteOnly);
|
|
||||||
// QTextStream scriptsStream(&scriptsFile);
|
|
||||||
// scriptsStream << mapName << "_MapScripts::" << endl
|
|
||||||
// << "\t.byte 0" << endl;
|
|
||||||
// scriptsFile.close();
|
|
||||||
|
|
||||||
// // 7. Create file data/text/maps/<map_name>.inc
|
|
||||||
// QFile textFile(dataDir + "text/maps/" + mapName + ".inc");
|
|
||||||
// textFile.open(QIODevice::WriteOnly);
|
|
||||||
// QTextStream textStream(&textFile);
|
|
||||||
// textStream << endl;
|
|
||||||
// textFile.close();
|
|
||||||
|
|
||||||
// // 8. Modify data/event_scripts.s:
|
|
||||||
// QFile eventScriptsFile(dataDir + "event_scripts.s");
|
|
||||||
// eventScriptsFile.open(QIODevice::Append);
|
|
||||||
// QTextStream eventScriptsStream(&eventScriptsFile);
|
|
||||||
// eventScriptsStream << endl
|
|
||||||
// << "\t.include \"data/scripts/maps/" << mapName << ".inc\"" << endl
|
|
||||||
// << "\t.include \"data/text/maps/" << mapName << ".inc\"" << endl;
|
|
||||||
// eventScriptsFile.close();
|
|
||||||
|
|
||||||
// // 9. Modify data/map_events.s:
|
|
||||||
// QFile mapEventsFile(dataDir + "map_events.s");
|
|
||||||
// mapEventsFile.open(QIODevice::Append);
|
|
||||||
// QTextStream mapEventsStream(&mapEventsFile);
|
|
||||||
// mapEventsStream << endl
|
|
||||||
// << "\t.include \"data/maps/events/" << mapName << ".inc\"" << endl;
|
|
||||||
// mapEventsFile.close();
|
|
||||||
|
|
||||||
// // 10. Modify data/maps/_assets.inc
|
|
||||||
// QFile assetsFile(dataMapsDir + "_assets.inc");
|
|
||||||
// assetsFile.open(QIODevice::Append);
|
|
||||||
// QTextStream assetsStream(&assetsFile);
|
|
||||||
// assetsStream << endl
|
|
||||||
// << mapName << "_MapBorder::" << endl
|
|
||||||
// << "\t.incbin \"data/maps/" << mapName << "/border.bin\"" << endl
|
|
||||||
// << endl
|
|
||||||
// << mapName << "_MapBlockdata::" << endl
|
|
||||||
// << "\t.incbin \"data/maps/" << mapName << "/map.bin\"" << endl
|
|
||||||
// << endl
|
|
||||||
// << "\t.align 2" << endl
|
|
||||||
// << mapName << "_MapAttributes::" << endl
|
|
||||||
// << "\t.4byte 0x14" << endl
|
|
||||||
// << "\t.4byte 0x14" << endl
|
|
||||||
// << "\t.4byte " << mapName << "_MapBorder" << endl
|
|
||||||
// << "\t.4byte " << mapName << "_MapBlockdata" << endl
|
|
||||||
// << "\t.4byte gTileset_General" << endl
|
|
||||||
// << "\t.4byte gTileset_Pacifidlog" << endl
|
|
||||||
// << endl;
|
|
||||||
// assetsFile.close();
|
|
||||||
|
|
||||||
// // 11. Modify data/maps/_groups.inc
|
|
||||||
// // TODO:
|
|
||||||
|
|
||||||
// // 12. Modify data/maps/attributes_table.inc
|
|
||||||
// QFile attributesFile(dataMapsDir + "attributes_table.inc");
|
|
||||||
// attributesFile.open(QIODevice::Append);
|
|
||||||
// QTextStream attributesStream(&attributesFile);
|
|
||||||
// attributesStream << endl
|
|
||||||
// << "\t.4byte " << mapName << "_MapAttributes" << endl;
|
|
||||||
// attributesFile.close();
|
|
||||||
|
|
||||||
// // 13. Modify data/maps/headers.inc
|
|
||||||
// QFile headersFile(dataMapsDir + "headers.inc");
|
|
||||||
// headersFile.open(QIODevice::Append);
|
|
||||||
// QTextStream headersStream(&headersFile);
|
|
||||||
// headersStream << endl
|
|
||||||
// << "\t.include \"data/maps/" << mapName << "/header.inc\"" << endl;
|
|
||||||
// headersFile.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::getNewMapName() {
|
QString Project::getNewMapName() {
|
||||||
|
|
15
project.h
15
project.h
|
@ -15,12 +15,14 @@ public:
|
||||||
QString root;
|
QString root;
|
||||||
QStringList *groupNames = NULL;
|
QStringList *groupNames = NULL;
|
||||||
QMap<QString, int> *map_groups;
|
QMap<QString, int> *map_groups;
|
||||||
QList<QStringList*> *groupedMapNames = NULL;
|
QList<QStringList> groupedMapNames;
|
||||||
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<int, QString> mapAttributesTable;
|
||||||
QMap<QString, QMap<QString, QString>*> *mapAttributes;
|
QMap<int, QString> mapAttributesTableMaster;
|
||||||
|
QMap<QString, QMap<QString, QString>> mapAttributes;
|
||||||
|
QMap<QString, QMap<QString, QString>> mapAttributesMaster;
|
||||||
|
|
||||||
|
|
||||||
QMap<QString, Map*> *map_cache;
|
QMap<QString, Map*> *map_cache;
|
||||||
|
@ -39,7 +41,7 @@ public:
|
||||||
void appendTextFile(QString path, QString text);
|
void appendTextFile(QString path, QString text);
|
||||||
|
|
||||||
void readMapGroups();
|
void readMapGroups();
|
||||||
void addNewMapToGroup(QString mapName, int groupNum);
|
Map* addNewMapToGroup(QString mapName, int groupNum);
|
||||||
QString getNewMapName();
|
QString getNewMapName();
|
||||||
QString getProjectTitle();
|
QString getProjectTitle();
|
||||||
|
|
||||||
|
@ -98,6 +100,7 @@ private:
|
||||||
QString getMapAssetsFilepath();
|
QString getMapAssetsFilepath();
|
||||||
void saveMapHeader(Map*);
|
void saveMapHeader(Map*);
|
||||||
void saveMapAttributesTable();
|
void saveMapAttributesTable();
|
||||||
|
void updateMapAttributes(Map* map);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROJECT_H
|
#endif // PROJECT_H
|
||||||
|
|
Loading…
Reference in a new issue