mirror of
https://github.com/huderlem/porymap.git
synced 2026-06-24 16:49:55 -05:00
Move map/layout loaded state to Project
This commit is contained in:
parent
854880f9f8
commit
8dcb66ca52
|
|
@ -68,12 +68,10 @@ public:
|
|||
void setNeedsHealLocation(bool needsHealLocation) { m_needsHealLocation = needsHealLocation; }
|
||||
void setIsPersistedToFile(bool persistedToFile) { m_isPersistedToFile = persistedToFile; }
|
||||
void setHasUnsavedDataChanges(bool unsavedDataChanges) { m_hasUnsavedDataChanges = unsavedDataChanges; }
|
||||
void setLoaded(bool loaded) { m_loaded = loaded; }
|
||||
|
||||
bool needsHealLocation() const { return m_needsHealLocation; }
|
||||
bool isPersistedToFile() const { return m_isPersistedToFile; }
|
||||
bool hasUnsavedDataChanges() const { return m_hasUnsavedDataChanges; }
|
||||
bool loaded() const { return m_loaded; }
|
||||
|
||||
void resetEvents();
|
||||
QList<Event *> getEvents(Event::Group group = Event::Group::None) const;
|
||||
|
|
@ -121,7 +119,6 @@ private:
|
|||
bool m_hasUnsavedDataChanges = false;
|
||||
bool m_needsHealLocation = false;
|
||||
bool m_scriptsLoaded = false;
|
||||
bool m_loaded = false;
|
||||
|
||||
QMap<Event::Group, QList<Event *>> m_events;
|
||||
QSet<Event *> m_ownedEvents; // for memory management
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ public:
|
|||
|
||||
static QString layoutConstantFromName(const QString &name);
|
||||
|
||||
bool loaded = false;
|
||||
bool hasUnsavedDataChanges = false;
|
||||
|
||||
QString id;
|
||||
|
|
|
|||
|
|
@ -92,6 +92,11 @@ public:
|
|||
// Note: This does not guarantee the map is loaded.
|
||||
Map* getMap(const QString &mapName) { return this->maps.value(mapName); }
|
||||
|
||||
bool isMapLoaded(const Map *map) const { return map && isMapLoaded(map->name()); }
|
||||
bool isMapLoaded(const QString &mapName) const { return this->loadedMapNames.contains(mapName); }
|
||||
bool isLayoutLoaded(const Layout *layout) const { return layout && isLayoutLoaded(layout->id); }
|
||||
bool isLayoutLoaded(const QString &layoutId) const { return this->loadedLayoutIds.contains(layoutId); }
|
||||
|
||||
QMap<QString, Tileset*> tilesetCache;
|
||||
Tileset* loadTileset(QString, Tileset *tileset = nullptr);
|
||||
Tileset* getTileset(QString, bool forceLoad = false);
|
||||
|
|
@ -260,6 +265,15 @@ private:
|
|||
QHash<QString, QString> speciesToIconPath;
|
||||
QHash<QString, Map*> maps;
|
||||
|
||||
// Maps/layouts represented in these sets have been fully loaded from the project.
|
||||
// If a valid map name / layout id is not in these sets, a Map / Layout object exists
|
||||
// for it in Project::maps / Project::mapLayouts, but it has been minimally populated
|
||||
// (i.e. for a map layout it only has the data read from layouts.json, none of its assets
|
||||
// have been loaded, and for a map it only has the data needed to identify it in the map
|
||||
// list, none of the rest of its data in map.json).
|
||||
QSet<QString> loadedMapNames;
|
||||
QSet<QString> loadedLayoutIds;
|
||||
|
||||
const QRegularExpression re_gbapalExtension;
|
||||
const QRegularExpression re_bppExtension;
|
||||
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ QString Project::getProjectTitle() const {
|
|||
void Project::clearMaps() {
|
||||
qDeleteAll(this->maps);
|
||||
this->maps.clear();
|
||||
this->loadedMapNames.clear();
|
||||
}
|
||||
|
||||
void Project::clearTilesetCache() {
|
||||
|
|
@ -142,14 +143,15 @@ Map* Project::loadMap(const QString &mapName) {
|
|||
if (!map)
|
||||
return nullptr;
|
||||
|
||||
if (map->loaded())
|
||||
if (isMapLoaded(map))
|
||||
return map;
|
||||
|
||||
if (!(loadMapData(map) && loadMapLayout(map)))
|
||||
return nullptr;
|
||||
|
||||
map->setLoaded(true);
|
||||
this->loadedMapNames.insert(mapName);
|
||||
emit mapLoaded(map);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
@ -393,14 +395,14 @@ Layout *Project::createNewLayout(const Layout::Settings &settings, const Layout
|
|||
}
|
||||
|
||||
// No need for a full load, we already have all the blockdata.
|
||||
layout->loaded = loadLayoutTilesets(layout);
|
||||
if (!layout->loaded) {
|
||||
if (!loadLayoutTilesets(layout)) {
|
||||
delete layout;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
this->mapLayouts.insert(layout->id, layout);
|
||||
this->layoutIds.append(layout->id);
|
||||
this->loadedLayoutIds.insert(layout->id);
|
||||
|
||||
emit layoutCreated(layout);
|
||||
|
||||
|
|
@ -408,14 +410,14 @@ Layout *Project::createNewLayout(const Layout::Settings &settings, const Layout
|
|||
}
|
||||
|
||||
bool Project::loadLayout(Layout *layout) {
|
||||
if (!layout->loaded) {
|
||||
if (!isLayoutLoaded(layout)) {
|
||||
// Force these to run even if one fails
|
||||
bool loadedTilesets = loadLayoutTilesets(layout);
|
||||
bool loadedBlockdata = loadBlockdata(layout);
|
||||
bool loadedBorder = loadLayoutBorder(layout);
|
||||
|
||||
if (loadedTilesets && loadedBlockdata && loadedBorder) {
|
||||
layout->loaded = true;
|
||||
this->loadedLayoutIds.insert(layout->id);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -448,6 +450,7 @@ void Project::clearMapLayouts() {
|
|||
this->mapLayoutsMaster.clear();
|
||||
this->layoutIds.clear();
|
||||
this->layoutIdsMaster.clear();
|
||||
this->loadedLayoutIds.clear();
|
||||
}
|
||||
|
||||
bool Project::readMapLayouts() {
|
||||
|
|
@ -1115,7 +1118,7 @@ void Project::saveAll() {
|
|||
}
|
||||
|
||||
void Project::saveMap(Map *map, bool skipLayout) {
|
||||
if (!map || !map->loaded()) return;
|
||||
if (!map || !isMapLoaded(map)) return;
|
||||
|
||||
// Create/Modify a few collateral files for brand new maps.
|
||||
const QString folderPath = projectConfig.getFilePath(ProjectFilePath::data_map_folders) + map->name();
|
||||
|
|
@ -1255,7 +1258,7 @@ void Project::saveMap(Map *map, bool skipLayout) {
|
|||
}
|
||||
|
||||
void Project::saveLayout(Layout *layout) {
|
||||
if (!layout || !layout->loaded)
|
||||
if (!layout || !isLayoutLoaded(layout))
|
||||
return;
|
||||
|
||||
if (!layout->newFolderPath.isEmpty()) {
|
||||
|
|
@ -1912,10 +1915,8 @@ bool Project::isIdentifierUnique(const QString &identifier) const {
|
|||
if (this->encounterGroupLabels.contains(identifier))
|
||||
return false;
|
||||
// Check event IDs
|
||||
for (const auto &map : this->maps) {
|
||||
if (!map->loaded()) continue;
|
||||
auto events = map->getEvents();
|
||||
for (const auto &event : events) {
|
||||
for (const auto &mapName : this->loadedMapNames) {
|
||||
for (const auto &event : this->maps.value(mapName)->getEvents()) {
|
||||
QString idName = event->getIdName();
|
||||
if (!idName.isEmpty() && idName == identifier)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ QVariant MapListModel::data(const QModelIndex &index, int role) const {
|
|||
return this->mapOpenedIcon;
|
||||
|
||||
const Map* map = this->project->getMap(name);
|
||||
if (!map || !map->loaded())
|
||||
if (!this->project->isMapLoaded(map))
|
||||
return this->mapGrayIcon;
|
||||
return map->hasUnsavedChanges() ? this->mapEditedIcon : this->mapIcon;
|
||||
} else if (type == this->folderTypeName) {
|
||||
|
|
@ -510,7 +510,7 @@ QVariant LayoutTreeModel::data(const QModelIndex &index, int role) const {
|
|||
return this->mapOpenedIcon;
|
||||
|
||||
const Layout* layout = this->project->mapLayouts.value(name);
|
||||
if (!layout || !layout->loaded)
|
||||
if (!this->project->isLayoutLoaded(layout))
|
||||
return this->mapGrayIcon;
|
||||
return layout->hasUnsavedChanges() ? this->mapEditedIcon : this->mapIcon;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user