Blender V5.0
asset_library_utils.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "BKE_context.hh"
12
13#include "ED_asset_library.hh"
14#include "ED_asset_list.hh"
15#include "ED_asset_shelf.hh"
16
17#include "BLI_listbase.h"
18#include "BLI_string_ref.hh"
19
20#include "DNA_userdef_types.h"
21#include "RNA_access.hh"
22#include "WM_api.hh"
23
24#include "AS_asset_catalog.hh"
25#include "AS_asset_library.hh"
26
27namespace blender::ed::asset {
28
31{
32 asset_system::AssetCatalogService &catalog_service = library.catalog_service();
33 if (asset_system::AssetCatalog *catalog = catalog_service.find_catalog_by_path(path)) {
34 return *catalog;
35 }
36 asset_system::AssetCatalog *new_catalog = catalog_service.create_catalog(path);
37 catalog_service.tag_has_unsaved_changes(new_catalog);
38 return *new_catalog;
39}
40
43{
44 /* Adding multiple catalogs in a path at a time with #AssetCatalogService::create_catalog()
45 * doesn't work; add each potentially new catalog in the hierarchy manually here. */
47 path.iterate_components([&](StringRef component_name, bool /*is_last_component*/) {
48 library_ensure_catalog(library, parent / component_name);
49 parent = parent / component_name;
50 });
51 return *library.catalog_service().find_catalog_by_path(path);
52}
53
55{
56 AssetLibraryReference library_ref{};
57 library_ref.custom_library_index = BLI_findindex(&U.asset_libraries, &user_library);
58 library_ref.type = ASSET_LIBRARY_CUSTOM;
59 return library_ref;
60}
61
62void refresh_asset_library(const bContext *C, const AssetLibraryReference &library_ref)
63{
64 asset::list::clear(&library_ref, C);
65 /* TODO: Should the all library reference be automatically cleared? */
67 asset::list::clear(&all_lib_ref, C);
68}
69
70void refresh_asset_library(const bContext *C, const bUserAssetLibrary &user_library)
71{
73}
74
77{
78 if (std::optional<AssetLibraryReference> library_ref =
79 asset.owner_asset_library().library_reference())
80 {
81 refresh_asset_library(C, *library_ref);
82 }
83}
84
85} // namespace blender::ed::asset
Main runtime representation of an asset.
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
@ ASSET_LIBRARY_CUSTOM
#define C
Definition RandGen.cpp:29
#define U
void iterate_components(ComponentIteratorFn callback) const
AssetCatalog * find_catalog_by_path(const AssetCatalogPath &path) const
AssetCatalog * create_catalog(const AssetCatalogPath &catalog_path)
void tag_has_unsaved_changes(AssetCatalog *edited_catalog=nullptr)
AssetCatalogService & catalog_service() const
AssetLibraryReference all_library_reference()
void clear(const AssetLibraryReference *library_reference, const bContext *C)
void refresh_asset_library(const bContext *C, const AssetLibraryReference &library_ref)
void refresh_asset_library_from_asset(const bContext *C, const blender::asset_system::AssetRepresentation &asset)
AssetLibraryReference user_library_to_library_ref(const bUserAssetLibrary &user_library)
blender::asset_system::AssetCatalog & library_ensure_catalogs_in_path(blender::asset_system::AssetLibrary &library, const blender::asset_system::AssetCatalogPath &path)
static asset_system::AssetCatalog & library_ensure_catalog(asset_system::AssetLibrary &library, const asset_system::AssetCatalogPath &path)