mirror of
https://github.com/huderlem/porymap.git
synced 2026-07-19 00:43:33 -05:00
Combine the 3 QMaps for MAPSEC data
This commit is contained in:
parent
a4508918a1
commit
e94fce0c8d
|
|
@ -56,8 +56,8 @@ public:
|
|||
bool loadLayout(poryjson::Json);
|
||||
bool loadEntries();
|
||||
|
||||
void setEntries(QMap<QString, MapSectionEntry> *entries) { this->region_map_entries = entries; }
|
||||
void setEntries(const QMap<QString, MapSectionEntry> &entries) { *(this->region_map_entries) = entries; }
|
||||
void setEntries(QHash<QString, MapSectionEntry> *entries) { this->region_map_entries = entries; }
|
||||
void setEntries(const QHash<QString, MapSectionEntry> &entries) { *(this->region_map_entries) = entries; }
|
||||
void clearEntries() { this->region_map_entries->clear(); }
|
||||
MapSectionEntry getEntry(QString section);
|
||||
void setEntry(QString section, MapSectionEntry entry);
|
||||
|
|
@ -151,7 +151,7 @@ signals:
|
|||
void mapNeedsDisplaying();
|
||||
|
||||
private:
|
||||
QMap<QString, MapSectionEntry> *region_map_entries = nullptr;
|
||||
QHash<QString, MapSectionEntry> *region_map_entries = nullptr;
|
||||
|
||||
QString alias = "";
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ private:
|
|||
/// ClearEntries
|
||||
class ClearEntries : public QUndoCommand {
|
||||
public:
|
||||
ClearEntries(RegionMap *map, QMap<QString, MapSectionEntry>, QUndoCommand *parent = nullptr);
|
||||
ClearEntries(RegionMap *map, QHash<QString, MapSectionEntry>, QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
|
@ -163,7 +163,7 @@ public:
|
|||
|
||||
private:
|
||||
RegionMap *map;
|
||||
QMap<QString, MapSectionEntry> entries;
|
||||
QHash<QString, MapSectionEntry> entries;
|
||||
};
|
||||
|
||||
#endif // REGIONMAPEDITCOMMANDS_H
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ public:
|
|||
QStringList mapSectionIdNames;
|
||||
QMap<uint32_t, QString> encounterTypeToName;
|
||||
QMap<uint32_t, QString> terrainTypeToName;
|
||||
QMap<QString, MapSectionEntry> regionMapEntries;
|
||||
QMap<QString, QMap<QString, uint16_t>> metatileLabelsMap;
|
||||
QMap<QString, uint16_t> unusedMetatileLabels;
|
||||
QMap<QString, uint32_t> metatileBehaviorMap;
|
||||
|
|
@ -157,7 +156,7 @@ public:
|
|||
|
||||
bool addNewMapsec(const QString &idName, const QString &displayName = QString());
|
||||
void removeMapsec(const QString &idName);
|
||||
QString getMapsecDisplayName(const QString &idName) const { return this->mapSectionDisplayNames.value(idName); }
|
||||
QString getMapsecDisplayName(const QString &idName) const { return this->locationData.value(idName).displayName; }
|
||||
void setMapsecDisplayName(const QString &idName, const QString &displayName);
|
||||
|
||||
bool hasUnsavedChanges();
|
||||
|
|
@ -240,6 +239,9 @@ public:
|
|||
static QString getExistingFilepath(QString filepath);
|
||||
void applyParsedLimits();
|
||||
|
||||
void setRegionMapEntries(const QHash<QString, MapSectionEntry> &entries);
|
||||
QHash<QString, MapSectionEntry> getRegionMapEntries() const;
|
||||
|
||||
static QString getEmptyMapDefineName();
|
||||
static QString getDynamicMapDefineName();
|
||||
static QString getDynamicMapName();
|
||||
|
|
@ -262,8 +264,6 @@ public:
|
|||
static QString getMapGroupPrefix();
|
||||
|
||||
private:
|
||||
QHash<QString, QString> mapSectionDisplayNames;
|
||||
QHash<QString, QJsonObject> mapSectionCustomData;
|
||||
QMap<QString, qint64> modifiedFileTimestamps;
|
||||
QMap<QString, QString> facingDirections;
|
||||
QHash<QString, QString> speciesToIconPath;
|
||||
|
|
@ -298,6 +298,15 @@ private:
|
|||
};
|
||||
QMap<QString, EventGraphics*> eventGraphicsMap;
|
||||
|
||||
// The extra data that can be associated with each MAPSEC name.
|
||||
struct LocationData
|
||||
{
|
||||
MapSectionEntry map;
|
||||
QString displayName;
|
||||
QJsonObject custom;
|
||||
};
|
||||
QHash<QString, LocationData> locationData;
|
||||
|
||||
void updateLayout(Layout *);
|
||||
|
||||
void setNewLayoutBlockdata(Layout *layout);
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ private:
|
|||
void saveConfig();
|
||||
bool loadRegionMapEntries();
|
||||
bool saveRegionMapEntries();
|
||||
QMap<QString, MapSectionEntry> region_map_entries;
|
||||
QHash<QString, MapSectionEntry> region_map_entries;
|
||||
|
||||
bool buildConfigDialog();
|
||||
poryjson::Json configRegionMapDialog();
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ void ResizeTilemap::undo() {
|
|||
|
||||
///
|
||||
|
||||
ClearEntries::ClearEntries(RegionMap *map, QMap<QString, MapSectionEntry> entries, QUndoCommand *parent)
|
||||
ClearEntries::ClearEntries(RegionMap *map, QHash<QString, MapSectionEntry> entries, QUndoCommand *parent)
|
||||
: QUndoCommand(parent) {
|
||||
setText("Clear Entries");
|
||||
|
||||
|
|
|
|||
|
|
@ -712,23 +712,23 @@ void Project::saveRegionMapSections() {
|
|||
|
||||
OrderedJson::array mapSectionArray;
|
||||
for (const auto &idName : this->mapSectionIdNamesSaveOrder) {
|
||||
const LocationData location = this->locationData.value(idName);
|
||||
|
||||
OrderedJson::object mapSectionObj;
|
||||
mapSectionObj["id"] = idName;
|
||||
|
||||
if (this->mapSectionDisplayNames.contains(idName)) {
|
||||
mapSectionObj["name"] = this->mapSectionDisplayNames.value(idName);
|
||||
if (!location.displayName.isEmpty()) {
|
||||
mapSectionObj["name"] = location.displayName;
|
||||
}
|
||||
|
||||
if (this->regionMapEntries.contains(idName)) {
|
||||
MapSectionEntry entry = this->regionMapEntries.value(idName);
|
||||
mapSectionObj["x"] = entry.x;
|
||||
mapSectionObj["y"] = entry.y;
|
||||
mapSectionObj["width"] = entry.width;
|
||||
mapSectionObj["height"] = entry.height;
|
||||
if (location.map.valid) {
|
||||
mapSectionObj["x"] = location.map.x;
|
||||
mapSectionObj["y"] = location.map.y;
|
||||
mapSectionObj["width"] = location.map.width;
|
||||
mapSectionObj["height"] = location.map.height;
|
||||
}
|
||||
|
||||
QJsonObject customData = this->mapSectionCustomData.value(idName);
|
||||
for (auto it = customData.constBegin(); it != customData.constEnd(); it++) {
|
||||
for (auto it = location.custom.constBegin(); it != location.custom.constEnd(); it++) {
|
||||
mapSectionObj[it.key()] = OrderedJson::fromQJsonValue(it.value());
|
||||
}
|
||||
|
||||
|
|
@ -2360,19 +2360,14 @@ bool Project::readFieldmapMasks() {
|
|||
}
|
||||
|
||||
bool Project::readRegionMapSections() {
|
||||
this->locationData.clear();
|
||||
this->mapSectionIdNames.clear();
|
||||
this->mapSectionIdNamesSaveOrder.clear();
|
||||
this->mapSectionDisplayNames.clear();
|
||||
this->regionMapEntries.clear();
|
||||
this->customMapSectionsData = QJsonObject();
|
||||
|
||||
const QString defaultName = getEmptyMapsecName();
|
||||
const QString requiredPrefix = projectConfig.getIdentifier(ProjectIdentifier::define_map_section_prefix);
|
||||
|
||||
// The first of these is the custom data for each individual map section object,
|
||||
// the second is the custom top-level data in the map sections file.
|
||||
// TODO: Clarify this by relocating the various map section data maps to a single class?
|
||||
this->mapSectionCustomData.clear();
|
||||
this->customMapSectionsData = QJsonObject();
|
||||
|
||||
QJsonDocument doc;
|
||||
const QString filepath = projectConfig.getFilePath(ProjectFilePath::json_region_map_entries);
|
||||
QString error;
|
||||
|
|
@ -2410,8 +2405,10 @@ bool Project::readRegionMapSections() {
|
|||
this->mapSectionIdNames.append(idName);
|
||||
this->mapSectionIdNamesSaveOrder.append(idName);
|
||||
|
||||
if (mapSectionObj.contains("name"))
|
||||
this->mapSectionDisplayNames.insert(idName, ParseUtil::jsonToQString(mapSectionObj.take("name")));
|
||||
LocationData location;
|
||||
if (mapSectionObj.contains("name")) {
|
||||
location.displayName = ParseUtil::jsonToQString(mapSectionObj.take("name"));
|
||||
}
|
||||
|
||||
// Map sections may have additional data indicating their position on the region map.
|
||||
// If they have this data, we can add them to the region map entry list.
|
||||
|
|
@ -2424,13 +2421,11 @@ bool Project::readRegionMapSections() {
|
|||
}
|
||||
}
|
||||
if (hasRegionMapData) {
|
||||
MapSectionEntry entry;
|
||||
entry.x = ParseUtil::jsonToInt(mapSectionObj.take("x"));
|
||||
entry.y = ParseUtil::jsonToInt(mapSectionObj.take("y"));
|
||||
entry.width = ParseUtil::jsonToInt(mapSectionObj.take("width"));
|
||||
entry.height = ParseUtil::jsonToInt(mapSectionObj.take("height"));
|
||||
entry.valid = true;
|
||||
this->regionMapEntries[idName] = entry;
|
||||
location.map.x = ParseUtil::jsonToInt(mapSectionObj.take("x"));
|
||||
location.map.y = ParseUtil::jsonToInt(mapSectionObj.take("y"));
|
||||
location.map.width = ParseUtil::jsonToInt(mapSectionObj.take("width"));
|
||||
location.map.height = ParseUtil::jsonToInt(mapSectionObj.take("height"));
|
||||
location.map.valid = true;
|
||||
}
|
||||
|
||||
// Chuck the "name_clone" field, this is only for matching.
|
||||
|
|
@ -2438,9 +2433,9 @@ bool Project::readRegionMapSections() {
|
|||
mapSectionObj.remove("name_clone");
|
||||
|
||||
// Preserve any remaining fields for when we save.
|
||||
if (!mapSectionObj.isEmpty()) {
|
||||
this->mapSectionCustomData[idName] = mapSectionObj;
|
||||
}
|
||||
location.custom = mapSectionObj;
|
||||
|
||||
this->locationData.insert(idName, location);
|
||||
}
|
||||
this->customMapSectionsData = mapSectionsGlobalObj;
|
||||
|
||||
|
|
@ -2453,6 +2448,20 @@ bool Project::readRegionMapSections() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Project::setRegionMapEntries(const QHash<QString, MapSectionEntry> &entries) {
|
||||
for (auto it = entries.constBegin(); it != entries.constEnd(); it++) {
|
||||
this->locationData[it.key()].map = it.value();
|
||||
}
|
||||
}
|
||||
|
||||
QHash<QString, MapSectionEntry> Project::getRegionMapEntries() const {
|
||||
QHash<QString, MapSectionEntry> entries;
|
||||
for (auto it = this->locationData.constBegin(); it != this->locationData.constEnd(); it++) {
|
||||
entries[it.key()] = it.value().map;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
QString Project::getEmptyMapsecName() {
|
||||
return projectConfig.getIdentifier(ProjectIdentifier::define_map_section_prefix) + projectConfig.getIdentifier(ProjectIdentifier::define_map_section_empty);
|
||||
}
|
||||
|
|
@ -2503,9 +2512,9 @@ void Project::removeMapsec(const QString &idName) {
|
|||
}
|
||||
|
||||
void Project::setMapsecDisplayName(const QString &idName, const QString &displayName) {
|
||||
if (this->mapSectionDisplayNames.value(idName) == displayName)
|
||||
if (getMapsecDisplayName(idName) == displayName)
|
||||
return;
|
||||
this->mapSectionDisplayNames[idName] = displayName;
|
||||
this->locationData[idName].displayName = displayName;
|
||||
this->hasUnsavedDataChanges = true;
|
||||
emit mapSectionDisplayNameChanged(idName, displayName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,12 +108,12 @@ void RegionMapEditor::applyUserShortcuts() {
|
|||
}
|
||||
|
||||
bool RegionMapEditor::loadRegionMapEntries() {
|
||||
this->region_map_entries = this->project->regionMapEntries;
|
||||
this->region_map_entries = this->project->getRegionMapEntries();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegionMapEditor::saveRegionMapEntries() {
|
||||
this->project->regionMapEntries = this->region_map_entries;
|
||||
this->project->setRegionMapEntries(this->region_map_entries);
|
||||
this->project->saveRegionMapSections();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user