Assets: Add further dedicated derived classes for asset libraries

Continuation of bdfb1f6a04. Adds derived classes for the essentials and
preferences asset libraries, to allow specialized classes with a simple
and common interface. This should help untangling the asset library
service code.
This commit is contained in:
Julian Eisel 2024-02-05 20:06:01 +01:00
parent c4f9484c18
commit 3c2366d313
7 changed files with 90 additions and 9 deletions

View File

@ -65,6 +65,7 @@ class AssetLibrary {
*/
std::unique_ptr<AssetStorage> asset_storage_;
protected:
std::optional<eAssetImportMethod> import_method_;
/** Assets owned by this library may be imported with a different method than set in
* #import_method_ above, it's just a default. */

View File

@ -15,10 +15,11 @@ set(SRC
intern/asset_catalog.cc
intern/asset_catalog_path.cc
intern/asset_catalog_tree.cc
intern/asset_essentials_library.cc
intern/asset_identifier.cc
intern/asset_library.cc
intern/asset_library_all.cc
intern/asset_library_essentials.cc
intern/asset_library_from_preferences.cc
intern/asset_library_on_disk.cc
intern/asset_library_runtime.cc
intern/asset_library_service.cc
@ -34,6 +35,8 @@ set(SRC
AS_asset_representation.hh
AS_essentials_library.hh
intern/asset_library_all.hh
intern/asset_library_essentials.hh
intern/asset_library_from_preferences.hh
intern/asset_library_on_disk.hh
intern/asset_library_runtime.hh
intern/asset_library_service.hh

View File

@ -6,14 +6,23 @@
* \ingroup asset_system
*/
#include "BLI_path_util.h"
#include "BKE_appdir.hh"
#include "utils.hh"
#include "AS_essentials_library.hh"
#include "asset_library_essentials.hh"
namespace blender::asset_system {
EssentialsAssetLibrary::EssentialsAssetLibrary()
: OnDiskAssetLibrary(ASSET_LIBRARY_ESSENTIALS,
{},
utils::normalize_directory_path(essentials_directory_path()))
{
import_method_ = ASSET_IMPORT_APPEND_REUSE;
}
StringRefNull essentials_directory_path()
{
static std::string path = []() {

View File

@ -0,0 +1,20 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup asset_system
*/
#pragma once
#include "asset_library_on_disk.hh"
namespace blender::asset_system {
class EssentialsAssetLibrary : public OnDiskAssetLibrary {
public:
EssentialsAssetLibrary();
};
} // namespace blender::asset_system

View File

@ -0,0 +1,18 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup asset_system
*/
#include "asset_library_from_preferences.hh"
namespace blender::asset_system {
PreferencesOnDiskAssetLibrary::PreferencesOnDiskAssetLibrary(StringRef name, StringRef root_path)
: OnDiskAssetLibrary(ASSET_LIBRARY_CUSTOM, name, root_path)
{
}
} // namespace blender::asset_system

View File

@ -0,0 +1,20 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup asset_system
*/
#pragma once
#include "asset_library_on_disk.hh"
namespace blender::asset_system {
class PreferencesOnDiskAssetLibrary : public OnDiskAssetLibrary {
public:
PreferencesOnDiskAssetLibrary(StringRef name = "", StringRef root_path = "");
};
} // namespace blender::asset_system

View File

@ -20,6 +20,8 @@
#include "AS_asset_library.hh"
#include "AS_essentials_library.hh"
#include "asset_library_all.hh"
#include "asset_library_essentials.hh"
#include "asset_library_from_preferences.hh"
#include "asset_library_on_disk.hh"
#include "asset_library_runtime.hh"
#include "asset_library_service.hh"
@ -72,10 +74,7 @@ AssetLibrary *AssetLibraryService::get_asset_library(
return nullptr;
}
AssetLibrary *library = get_asset_library_on_disk_builtin(type, root_path);
library->import_method_ = ASSET_IMPORT_APPEND_REUSE;
return library;
return get_asset_library_on_disk_builtin(type, root_path);
}
case ASSET_LIBRARY_LOCAL: {
/* For the "Current File" library we get the asset library root path based on main. */
@ -132,8 +131,19 @@ AssetLibrary *AssetLibraryService::get_asset_library_on_disk(eAssetLibraryType l
return lib;
}
std::unique_ptr lib_uptr = std::make_unique<OnDiskAssetLibrary>(
library_type, name, normalized_root_path);
std::unique_ptr<OnDiskAssetLibrary> lib_uptr;
switch (library_type) {
case ASSET_LIBRARY_CUSTOM:
lib_uptr = std::make_unique<PreferencesOnDiskAssetLibrary>(name, normalized_root_path);
break;
case ASSET_LIBRARY_ESSENTIALS:
lib_uptr = std::make_unique<EssentialsAssetLibrary>();
break;
default:
lib_uptr = std::make_unique<OnDiskAssetLibrary>(library_type, name, normalized_root_path);
break;
}
AssetLibrary *lib = lib_uptr.get();
lib->load_catalogs();