UI: Asset Shelf (Experimental Feature) #104831
|
@ -54,7 +54,7 @@ struct ::AssetLibrary *AS_asset_library_load(const char *name, const char *libra
|
|||
lib = service->get_asset_library_current_file(name);
|
||||
}
|
||||
else {
|
||||
lib = service->get_asset_library_on_disk(ASSET_LIBRARY_CUSTOM, name, library_path);
|
||||
lib = service->get_asset_library_on_disk_custom(name, library_path);
|
||||
}
|
||||
return reinterpret_cast<struct ::AssetLibrary *>(lib);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ AssetLibrary *AssetLibraryService::get_asset_library(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
AssetLibrary *library = get_asset_library_on_disk(type, "Essentials", root_path);
|
||||
AssetLibrary *library = get_asset_library_on_disk_builtin(type, root_path);
|
||||
library->import_method_ = ASSET_IMPORT_APPEND_REUSE;
|
||||
|
||||
return library;
|
||||
|
@ -81,7 +81,7 @@ AssetLibrary *AssetLibraryService::get_asset_library(
|
|||
/* File wasn't saved yet. */
|
||||
return get_asset_library_current_file("Current File");
|
||||
}
|
||||
return get_asset_library_on_disk(type, "Current File", root_path);
|
||||
return get_asset_library_on_disk_builtin(type, root_path);
|
||||
}
|
||||
case ASSET_LIBRARY_ALL:
|
||||
return get_asset_library_all("All", bmain);
|
||||
|
@ -97,7 +97,7 @@ AssetLibrary *AssetLibraryService::get_asset_library(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
AssetLibrary *library = get_asset_library_on_disk(type, custom_library->name, root_path);
|
||||
AssetLibrary *library = get_asset_library_on_disk_custom(custom_library->name, root_path);
|
||||
library->import_method_ = eAssetImportMethod(custom_library->import_method);
|
||||
library->may_override_import_method_ = true;
|
||||
|
||||
|
@ -140,6 +140,24 @@ AssetLibrary *AssetLibraryService::get_asset_library_on_disk(eAssetLibraryType l
|
|||
return lib;
|
||||
}
|
||||
|
||||
AssetLibrary *AssetLibraryService::get_asset_library_on_disk_custom(StringRef name,
|
||||
StringRefNull root_path)
|
||||
{
|
||||
return get_asset_library_on_disk(ASSET_LIBRARY_CUSTOM, name, root_path);
|
||||
}
|
||||
|
||||
AssetLibrary *AssetLibraryService::get_asset_library_on_disk_builtin(eAssetLibraryType type,
|
||||
StringRefNull root_path)
|
||||
{
|
||||
BLI_assert_msg(
|
||||
type != ASSET_LIBRARY_CUSTOM,
|
||||
"Use `get_asset_library_on_disk_custom()` for libraries of type `ASSET_LIBRARY_CUSTOM`");
|
||||
|
||||
/* Builtin asset libraries don't need a name, the #eAssetLibraryType is enough to identify them
|
||||
* (and doesn't change, unlike the name). */
|
||||
return get_asset_library_on_disk(type, {}, root_path);
|
||||
}
|
||||
|
||||
AssetLibrary *AssetLibraryService::get_asset_library_current_file(StringRef name)
|
||||
{
|
||||
if (current_file_library_) {
|
||||
|
|
|
@ -65,12 +65,11 @@ class AssetLibraryService {
|
|||
AssetLibrary *get_asset_library(const Main *bmain,
|
||||
const AssetLibraryReference &library_reference);
|
||||
|
||||
/**
|
||||
* Get the given asset library. Opens it (i.e. creates a new AssetLibrary instance) if necessary.
|
||||
*/
|
||||
AssetLibrary *get_asset_library_on_disk(eAssetLibraryType library_type,
|
||||
StringRef name,
|
||||
StringRefNull top_level_directory);
|
||||
/** Get an asset library of type #ASSET_LIBRARY_CUSTOM. */
|
||||
AssetLibrary *get_asset_library_on_disk_custom(StringRef name, StringRefNull root_path);
|
||||
/** Get a builtin (not user defined) asset library. I.e. a library that is **not** of type
|
||||
* #ASSET_LIBRARY_CUSTOM. */
|
||||
AssetLibrary *get_asset_library_on_disk_builtin(eAssetLibraryType type, StringRefNull root_path);
|
||||
|
||||
/** Get the "Current File" asset library. */
|
||||
AssetLibrary *get_asset_library_current_file(StringRef name);
|
||||
|
@ -89,6 +88,12 @@ class AssetLibraryService {
|
|||
/** Allocate a new instance of the service and assign it to `instance_`. */
|
||||
static void allocate_service_instance();
|
||||
|
||||
/**
|
||||
* Get the given asset library. Opens it (i.e. creates a new AssetLibrary instance) if necessary.
|
||||
*/
|
||||
AssetLibrary *get_asset_library_on_disk(eAssetLibraryType library_type,
|
||||
StringRef name,
|
||||
StringRefNull top_level_directory);
|
||||
/**
|
||||
* Ensure the AssetLibraryService instance is destroyed before a new blend file is loaded.
|
||||
* This makes memory management simple, and ensures a fresh start for every blend file. */
|
||||
|
|
|
@ -95,13 +95,11 @@ TEST_F(AssetLibraryServiceTest, library_pointers)
|
|||
|
||||
const std::string lib_name_on_disk = std::string(__func__) + " on disk";
|
||||
const std::string lib_name_curfile = std::string(__func__) + " current file";
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk(
|
||||
ASSET_LIBRARY_CUSTOM, lib_name_on_disk, asset_library_root_);
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk_custom(lib_name_on_disk,
|
||||
asset_library_root_);
|
||||
AssetLibrary *const curfile_lib = service->get_asset_library_current_file(lib_name_curfile);
|
||||
|
||||
EXPECT_EQ(lib,
|
||||
service->get_asset_library_on_disk(
|
||||
ASSET_LIBRARY_CUSTOM, lib_name_on_disk, asset_library_root_))
|
||||
EXPECT_EQ(lib, service->get_asset_library_on_disk_custom(lib_name_on_disk, asset_library_root_))
|
||||
<< "Calling twice without destroying in between should return the same instance.";
|
||||
EXPECT_EQ(curfile_lib, service->get_asset_library_current_file(lib_name_curfile))
|
||||
<< "Calling twice without destroying in between should return the same instance.";
|
||||
|
@ -118,8 +116,8 @@ TEST_F(AssetLibraryServiceTest, library_from_reference)
|
|||
const std::string lib_name_on_disk = std::string(__func__) + " on disk";
|
||||
const std::string lib_name_curfile = std::string(__func__) + " current file";
|
||||
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk(
|
||||
ASSET_LIBRARY_CUSTOM, lib_name_on_disk, asset_library_root_);
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk_custom(lib_name_on_disk,
|
||||
asset_library_root_);
|
||||
AssetLibrary *const curfile_lib = service->get_asset_library_current_file(lib_name_curfile);
|
||||
|
||||
AssetLibraryReference ref{};
|
||||
|
@ -154,20 +152,19 @@ TEST_F(AssetLibraryServiceTest, library_path_trailing_slashes)
|
|||
|
||||
BLI_path_slash_ensure(asset_lib_with_slash, PATH_MAX);
|
||||
|
||||
AssetLibrary *const lib_no_slash = service->get_asset_library_on_disk(
|
||||
ASSET_LIBRARY_CUSTOM, __func__, asset_lib_no_slash);
|
||||
AssetLibrary *const lib_no_slash = service->get_asset_library_on_disk_custom(__func__,
|
||||
asset_lib_no_slash);
|
||||
|
||||
EXPECT_EQ(
|
||||
lib_no_slash,
|
||||
service->get_asset_library_on_disk(ASSET_LIBRARY_CUSTOM, __func__, asset_lib_with_slash))
|
||||
EXPECT_EQ(lib_no_slash,
|
||||
service->get_asset_library_on_disk_custom(__func__, asset_lib_with_slash))
|
||||
<< "With or without trailing slash shouldn't matter.";
|
||||
}
|
||||
|
||||
TEST_F(AssetLibraryServiceTest, catalogs_loaded)
|
||||
{
|
||||
AssetLibraryService *const service = AssetLibraryService::get();
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk(
|
||||
ASSET_LIBRARY_CUSTOM, __func__, asset_library_root_);
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk_custom(__func__,
|
||||
asset_library_root_);
|
||||
AssetCatalogService *const cat_service = lib->catalog_service.get();
|
||||
|
||||
const bUUID UUID_POSES_ELLIE("df60e1f6-2259-475b-93d9-69a1b4a8db78");
|
||||
|
@ -181,8 +178,8 @@ TEST_F(AssetLibraryServiceTest, has_any_unsaved_catalogs)
|
|||
EXPECT_FALSE(service->has_any_unsaved_catalogs())
|
||||
<< "Empty AssetLibraryService should have no unsaved catalogs";
|
||||
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk(
|
||||
ASSET_LIBRARY_CUSTOM, __func__, asset_library_root_);
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk_custom(__func__,
|
||||
asset_library_root_);
|
||||
AssetCatalogService *const cat_service = lib->catalog_service.get();
|
||||
EXPECT_FALSE(service->has_any_unsaved_catalogs())
|
||||
<< "Unchanged AssetLibrary should have no unsaved catalogs";
|
||||
|
@ -214,8 +211,7 @@ TEST_F(AssetLibraryServiceTest, has_any_unsaved_catalogs_after_write)
|
|||
ASSERT_EQ(0, BLI_copy(original_cdf_file.c_str(), writable_cdf_file.c_str()));
|
||||
|
||||
AssetLibraryService *const service = AssetLibraryService::get();
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk(
|
||||
ASSET_LIBRARY_CUSTOM, __func__, writable_dir);
|
||||
AssetLibrary *const lib = service->get_asset_library_on_disk_custom(__func__, writable_dir);
|
||||
|
||||
EXPECT_FALSE(service->has_any_unsaved_catalogs())
|
||||
<< "Unchanged AssetLibrary should have no unsaved catalogs";
|
||||
|
|
Loading…
Reference in New Issue