[Bf-blender-cvs] [5a1b1c0ed2e] master: Cleanup: Getters for asset-handle data

Julian Eisel noreply at git.blender.org
Tue Jul 20 21:50:35 CEST 2021


Commit: 5a1b1c0ed2e6d085c93b8afd699407f92cc2d07d
Author: Julian Eisel
Date:   Tue Jul 20 20:58:15 2021 +0200
Branches: master
https://developer.blender.org/rB5a1b1c0ed2e6d085c93b8afd699407f92cc2d07d

Cleanup: Getters for asset-handle data

While the asset-handle design is supposed to be temporary (see
35affaa971cf), 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.

===================================================================

M	source/blender/editors/armature/pose_lib_2.c
M	source/blender/editors/asset/asset_edit.cc
M	source/blender/editors/asset/asset_list.cc
M	source/blender/editors/asset/asset_temp_id_consumer.cc
M	source/blender/editors/include/ED_asset.h
M	source/blender/editors/interface/interface_template_asset_view.cc
M	source/blender/makesrna/intern/rna_asset.c

===================================================================

diff --git a/source/blender/editors/armature/pose_lib_2.c b/source/blender/editors/armature/pose_lib_2.c
index eb091296282..84e49a6f42b 100644
--- a/source/blender/editors/armature/pose_lib_2.c
+++ b/source/blender/editors/armature/pose_lib_2.c
@@ -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. */
diff --git a/source/blender/editors/asset/asset_edit.cc b/source/blender/editors/asset/asset_edit.cc
index f4860737193..c44960f3b5a 100644
--- a/source/blender/editors/asset/asset_edit.cc
+++ b/source/blender/editors/asset/asset_edit.cc
@@ -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,
diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/asset_list.cc
index d9c1c6d862e..3095239b711 100644
--- a/source/blender/editors/asset/asset_list.cc
+++ b/source/blender/editors/asset/asset_list.cc
@@ -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);
diff --git a/source/blender/editors/asset/asset_temp_id_consumer.cc b/source/blender/editors/asset/asset_temp_id_consumer.cc
index 24e1fc86fef..464320fdce9 100644
--- a/source/blender/editors/asset/asset_temp_id_consumer.cc
+++ b/source/blender/editors/asset/asset_temp_id_consumer.cc
@@ -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,
diff --git a/source/blender/editors/include/ED_asset.h b/source/blender/editors/include/ED_asset.h
index 0058c0615c3..4fdee03528d 100644
--- a/source/blender/editors/include/ED_asset.h
+++ b/source/blender/editors/include/ED_asset.h
@@ -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);
 
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
index 5a05813f947..1d8420718bb 100644
--- a/source/blender/editors/interface/interface_template_asset_view.cc
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -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) {
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index d13e05c45e9..06dfe6ce8a8 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -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);
 }



More information about the Bf-blender-cvs mailing list