use append-and-reuse for bundled assets

This commit is contained in:
Jacques Lucke 2023-01-24 19:23:46 +01:00
parent 3f962b8e28
commit d2fc31f178
4 changed files with 42 additions and 8 deletions

View File

@ -0,0 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup asset_system
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
bool ED_asset_bundle_contains_path(const char *path);
#ifdef __cplusplus
}
#endif

View File

@ -8,6 +8,8 @@
#include "BLI_string_ref.hh"
#include "AS_asset_bundled.h"
namespace blender::asset_system {
StringRefNull bundled_assets_directory_path();

View File

@ -4,6 +4,8 @@
* \ingroup asset_system
*/
#include "BLI_string.h"
#include "BKE_appdir.h"
#include "AS_asset_bundled.hh"
@ -20,3 +22,10 @@ StringRefNull bundled_assets_directory_path()
}
} // namespace blender::asset_system
bool ED_asset_bundle_contains_path(const char *path)
{
const blender::StringRefNull bundled_path =
blender::asset_system::bundled_assets_directory_path();
return BLI_str_startswith(path, bundled_path.c_str());
}

View File

@ -55,6 +55,8 @@
#include "GPU_immediate_util.h"
#include "GPU_state.h"
#include "AS_asset_bundled.h"
#include "filelist.h"
#include "file_intern.h" /* own include */
@ -126,6 +128,16 @@ static void draw_tile_background(const rcti *draw_rect, int colorid, int shade)
UI_draw_roundbox_aa(&draw_rect_fl, true, 5.0f, color);
}
static eFileAssetImportType get_asset_import_type(const SpaceFile *sfile, const char *blend_path)
{
if (ED_asset_bundle_contains_path(blend_path)) {
return FILE_ASSET_IMPORT_APPEND_REUSE;
}
const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
BLI_assert(asset_params != NULL);
return asset_params->import_type;
}
static void file_draw_icon(const SpaceFile *sfile,
uiBlock *block,
const FileDirEntry *file,
@ -165,13 +177,10 @@ static void file_draw_icon(const SpaceFile *sfile,
ImBuf *preview_image = filelist_file_getimage(file);
char blend_path[FILE_MAX_LIBEXTRA];
if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
BLI_assert(asset_params != NULL);
UI_but_drag_set_asset(but,
&(AssetHandle){.file_data = file},
BLI_strdup(blend_path),
asset_params->import_type,
get_asset_import_type(sfile, blend_path),
icon,
preview_image,
UI_DPI_FAC);
@ -558,13 +567,10 @@ static void file_draw_preview(const SpaceFile *sfile,
char blend_path[FILE_MAX_LIBEXTRA];
if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
BLI_assert(asset_params != NULL);
UI_but_drag_set_asset(but,
&(AssetHandle){.file_data = file},
BLI_strdup(blend_path),
asset_params->import_type,
get_asset_import_type(sfile, blend_path),
icon,
imb,
scale);