Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-10-21 16:53:12 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-21 16:53:16 +0300
commit5ccec8ec6bed3e0eda1cffaae565fdfaccd2a6ac (patch)
treeb6f6523e8a3f9e0a9ab1f20171028b03621f026d /source/blender/blenkernel/intern/asset_catalog.cc
parent9a1fce698bc6dd51c66464f9dcccfb89d0432823 (diff)
Asset Catalogs: treat first-loaded catalog as main catalog
When there are multiple catalogs with the same path (so different UUIDs all mapped to the same catalog path), treat the first-loaded one as the main catalog for that path, and the rest as aliases. This ensures that the UUID of a catalog (as chosen in the tree UI and thus interacted with by users) is stable, regardless of whether by some coincidence later another catalog with the same UUID is created.
Diffstat (limited to 'source/blender/blenkernel/intern/asset_catalog.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_catalog.cc25
1 files changed, 21 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc
index aa8f12d0e23..51f8457ebd9 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@ -24,6 +24,7 @@
#include "BLI_fileops.h"
#include "BLI_path_util.h"
+#include "BLI_set.hh"
#include "BLI_string_ref.hh"
#include "DNA_userdef_types.h"
@@ -108,13 +109,23 @@ AssetCatalog *AssetCatalogService::find_catalog(CatalogID catalog_id) const
AssetCatalog *AssetCatalogService::find_catalog_by_path(const AssetCatalogPath &path) const
{
+ /* Use an AssetCatalogOrderedSet to find the 'best' catalog for this path. This will be the first
+ * one loaded from disk, or if that does not exist the one with the lowest UUID. This ensures
+ * stable, predictable results. */
+ MutableAssetCatalogOrderedSet ordered_catalogs;
+
for (const auto &catalog : catalog_collection_->catalogs_.values()) {
if (catalog->path == path) {
- return catalog.get();
+ ordered_catalogs.insert(catalog.get());
}
}
- return nullptr;
+ if (ordered_catalogs.empty()) {
+ return nullptr;
+ }
+
+ MutableAssetCatalogOrderedSet::iterator best_choice_it = ordered_catalogs.begin();
+ return *best_choice_it;
}
AssetCatalogFilter AssetCatalogService::create_catalog_filter(
@@ -309,7 +320,10 @@ std::unique_ptr<AssetCatalogDefinitionFile> AssetCatalogService::parse_catalog_f
auto cdf = std::make_unique<AssetCatalogDefinitionFile>();
cdf->file_path = catalog_definition_file_path;
- auto catalog_parsed_callback = [this, catalog_definition_file_path](
+ /* TODO(Sybren): this might have to move to a higher level when supporting multiple CDFs. */
+ Set<AssetCatalogPath> seen_paths;
+
+ auto catalog_parsed_callback = [this, catalog_definition_file_path, &seen_paths](
std::unique_ptr<AssetCatalog> catalog) {
if (catalog_collection_->catalogs_.contains(catalog->catalog_id)) {
/* TODO(@sybren): apparently another CDF was already loaded. This is not supported yet. */
@@ -319,6 +333,8 @@ std::unique_ptr<AssetCatalogDefinitionFile> AssetCatalogService::parse_catalog_f
return false;
}
+ catalog->flags.is_first_loaded = seen_paths.add(catalog->path);
+
/* The AssetCatalog pointer is now owned by the AssetCatalogService. */
catalog_collection_->catalogs_.add_new(catalog->catalog_id, std::move(catalog));
return true;
@@ -648,7 +664,8 @@ void AssetCatalogTree::insert_item(const AssetCatalog &catalog)
/* If full path of this catalog already exists as parent path of a previously read catalog,
* we can ensure this tree item's UUID is set here. */
- if (is_last_component && BLI_uuid_is_nil(item.catalog_id_)) {
+ if (is_last_component &&
+ (BLI_uuid_is_nil(item.catalog_id_) || catalog.flags.is_first_loaded)) {
item.catalog_id_ = catalog.catalog_id;
}