Cleanup: Getters for asset-handle data
While the asset-handle design is supposed to be temporary (see
35affaa971
), I prefer keeping the fact that it's nothing but a file
entry pointer an implementation detail that is abstracted away. So this
introduces getters for the file data we typically access for
asset-handles.
This commit is contained in:
parent
207df439e1
commit
5a1b1c0ed2
|
@ -544,7 +544,7 @@ static bool poselib_asset_in_context(bContext *C)
|
|||
AssetHandle asset_handle = CTX_wm_asset_handle(C, &asset_handle_valid);
|
||||
|
||||
return (asset_library != NULL) && asset_handle_valid &&
|
||||
(asset_handle.file_data->blentype == ID_AC);
|
||||
(ED_asset_handle_get_id_type(&asset_handle) == ID_AC);
|
||||
}
|
||||
|
||||
/* Poll callback for operators that require existing PoseLib data (with poses) to work. */
|
||||
|
|
|
@ -139,6 +139,26 @@ const char *ED_asset_handle_get_name(const AssetHandle *asset)
|
|||
return asset->file_data->name;
|
||||
}
|
||||
|
||||
AssetMetaData *ED_asset_handle_get_metadata(const AssetHandle *asset)
|
||||
{
|
||||
return asset->file_data->asset_data;
|
||||
}
|
||||
|
||||
ID *ED_asset_handle_get_local_id(const AssetHandle *asset)
|
||||
{
|
||||
return asset->file_data->id;
|
||||
}
|
||||
|
||||
ID_Type ED_asset_handle_get_id_type(const AssetHandle *asset)
|
||||
{
|
||||
return static_cast<ID_Type>(asset->file_data->blentype);
|
||||
}
|
||||
|
||||
int ED_asset_handle_get_preview_icon_id(const AssetHandle *asset)
|
||||
{
|
||||
return asset->file_data->preview_icon_id;
|
||||
}
|
||||
|
||||
void ED_asset_handle_get_full_library_path(const bContext *C,
|
||||
const AssetLibraryReference *asset_library,
|
||||
const AssetHandle *asset,
|
||||
|
|
|
@ -495,7 +495,8 @@ std::string ED_assetlist_asset_filepath_get(const bContext *C,
|
|||
const AssetLibraryReference &library_reference,
|
||||
const AssetHandle &asset_handle)
|
||||
{
|
||||
if (asset_handle.file_data->id || !asset_handle.file_data->asset_data) {
|
||||
if (ED_asset_handle_get_local_id(&asset_handle) ||
|
||||
!ED_asset_handle_get_metadata(&asset_handle)) {
|
||||
return {};
|
||||
}
|
||||
const char *library_path = ED_assetlist_library_path(&library_reference);
|
||||
|
@ -513,11 +514,6 @@ std::string ED_assetlist_asset_filepath_get(const bContext *C,
|
|||
return path;
|
||||
}
|
||||
|
||||
ID *ED_assetlist_asset_local_id_get(const AssetHandle *asset_handle)
|
||||
{
|
||||
return asset_handle->file_data->asset_data ? asset_handle->file_data->id : nullptr;
|
||||
}
|
||||
|
||||
ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle)
|
||||
{
|
||||
ImBuf *imbuf = filelist_file_getimage(asset_handle->file_data);
|
||||
|
|
|
@ -53,7 +53,7 @@ class AssetTemporaryIDConsumer : NonCopyable, NonMovable {
|
|||
|
||||
ID *get_local_id()
|
||||
{
|
||||
return ED_assetlist_asset_local_id_get(&handle_);
|
||||
return ED_asset_handle_get_local_id(&handle_);
|
||||
}
|
||||
|
||||
ID *import_id(const bContext *C,
|
||||
|
|
|
@ -44,6 +44,10 @@ int ED_asset_library_reference_to_enum_value(const struct AssetLibraryReference
|
|||
struct AssetLibraryReference ED_asset_library_reference_from_enum_value(int value);
|
||||
|
||||
const char *ED_asset_handle_get_name(const AssetHandle *asset);
|
||||
AssetMetaData *ED_asset_handle_get_metadata(const AssetHandle *asset);
|
||||
struct ID *ED_asset_handle_get_local_id(const AssetHandle *asset);
|
||||
ID_Type ED_asset_handle_get_id_type(const AssetHandle *asset);
|
||||
int ED_asset_handle_get_preview_icon_id(const AssetHandle *asset);
|
||||
void ED_asset_handle_get_full_library_path(const struct bContext *C,
|
||||
const AssetLibraryReference *asset_library,
|
||||
const AssetHandle *asset,
|
||||
|
@ -69,7 +73,6 @@ void ED_assetlist_storage_tag_main_data_dirty(void);
|
|||
void ED_assetlist_storage_id_remap(struct ID *id_old, struct ID *id_new);
|
||||
void ED_assetlist_storage_exit(void);
|
||||
|
||||
ID *ED_assetlist_asset_local_id_get(const AssetHandle *asset_handle);
|
||||
struct ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle);
|
||||
const char *ED_assetlist_library_path(const struct AssetLibraryReference *library_reference);
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ static void asset_view_item_but_drag_set(uiBut *but,
|
|||
AssetViewListData *list_data,
|
||||
AssetHandle *asset_handle)
|
||||
{
|
||||
ID *id = asset_handle->file_data->id;
|
||||
ID *id = ED_asset_handle_get_local_id(asset_handle);
|
||||
if (id != nullptr) {
|
||||
UI_but_drag_set_id(but, id);
|
||||
return;
|
||||
|
@ -70,7 +70,7 @@ static void asset_view_item_but_drag_set(uiBut *but,
|
|||
BLI_strdup(blend_path),
|
||||
asset_handle->file_data->blentype,
|
||||
FILE_ASSET_IMPORT_APPEND,
|
||||
asset_handle->file_data->preview_icon_id,
|
||||
ED_asset_handle_get_preview_icon_id(asset_handle),
|
||||
imbuf,
|
||||
1.0f);
|
||||
}
|
||||
|
@ -101,8 +101,8 @@ static void asset_view_draw_item(uiList *ui_list,
|
|||
uiBut *but = uiDefIconTextBut(block,
|
||||
UI_BTYPE_PREVIEW_TILE,
|
||||
0,
|
||||
asset_handle->file_data->preview_icon_id,
|
||||
asset_handle->file_data->name,
|
||||
ED_asset_handle_get_preview_icon_id(asset_handle),
|
||||
ED_asset_handle_get_name(asset_handle),
|
||||
0,
|
||||
0,
|
||||
size_x,
|
||||
|
@ -114,7 +114,7 @@ static void asset_view_draw_item(uiList *ui_list,
|
|||
0,
|
||||
"");
|
||||
ui_def_but_icon(but,
|
||||
asset_handle->file_data->preview_icon_id,
|
||||
ED_asset_handle_get_preview_icon_id(asset_handle),
|
||||
/* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */
|
||||
UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
|
||||
if (!ui_list->dyn_data->custom_drag_optype) {
|
||||
|
|
|
@ -156,7 +156,7 @@ static void rna_AssetHandle_get_full_library_path(
|
|||
static PointerRNA rna_AssetHandle_local_id_get(PointerRNA *ptr)
|
||||
{
|
||||
const AssetHandle *asset = ptr->data;
|
||||
ID *id = ED_assetlist_asset_local_id_get(asset);
|
||||
ID *id = ED_asset_handle_get_local_id(asset);
|
||||
return rna_pointer_inherit_refine(ptr, &RNA_ID, id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue