Blender V5.3
preferences_on_disk_library.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
9#include "BLI_assert.hh"
10#include "BLI_listbase.hh"
11
12#include "BKE_preferences.h"
13
14#include "DNA_userdef_types.h"
15
16#include "common.hh"
18
19namespace blender::asset_system {
20
30
31std::optional<AssetLibraryReference> PreferencesOnDiskAssetLibrary::library_reference() const
32{
33 const bUserAssetLibrary *library_definition = this->user_asset_library();
34 if (!library_definition) {
35 return {};
36 }
37 const int index = BLI_findindex(&U.asset_libraries, library_definition);
38 if (index == -1) {
39 /* Should have been caught by the #user_asset_library() call above already. */
41 return {};
42 }
43
44 AssetLibraryReference library_ref{};
45 library_ref.type = ASSET_LIBRARY_CUSTOM;
46 library_ref.custom_library_index = index;
47 return library_ref;
48}
49
51{
52 return user_library_.user_asset_library();
53}
54
55std::optional<eAssetImportMethod> PreferencesOnDiskAssetLibrary::import_method() const
56{
57 const bUserAssetLibrary *library_definition = this->user_asset_library();
58 if (!library_definition) {
59 return {};
60 }
61
62 return eAssetImportMethod(library_definition->import_method);
63}
64
66{
67 const bUserAssetLibrary *library_definition = this->user_asset_library();
68 if (!library_definition) {
69 return false;
70 }
71
72 return (library_definition->flag & ASSET_LIBRARY_RELATIVE_PATH) != 0;
73}
74
76{
77 const bUserAssetLibrary *library_definition = this->user_asset_library();
78 if (!library_definition) {
79 return false;
80 }
81
82 return BKE_preferences_asset_library_is_available(&U, library_definition);
83}
84
85} // namespace blender::asset_system
#define BLI_assert_unreachable()
OnDiskAssetLibrary(eAssetLibraryType library_type, StringRef name, StringRef root_path, bool is_read_only)
PreferencesOnDiskAssetLibrary(const bUserAssetLibrary &user_asset_library)
const bUserAssetLibrary * user_asset_library() const override
std::optional< eAssetImportMethod > import_method() const override
std::optional< AssetLibraryReference > library_reference() const override
UserDef U
Definition blender.cc:58
@ ASSET_LIBRARY_RELATIVE_PATH
@ ASSET_LIBRARY_CUSTOM
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
bool BKE_preferences_asset_library_is_available(const struct UserDef *userdef, const struct bUserAssetLibrary *library) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT