diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2021-06-14 16:25:08 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2021-06-14 16:25:23 +0300 |
commit | be6fb069fda8e5d8f57c69fa117b9e98a27079dd (patch) | |
tree | 04e24c4ae086e268854967f56b1790ef516c867e | |
parent | e14cc3cd3c132ca2174f08fe958b15a189c72a25 (diff) |
Pose library: simplify temp-loading code
Simplify temp-loading code by removing unnecessary class & function.
No functional changes.
-rw-r--r-- | pose_library/functions.py | 23 | ||||
-rw-r--r-- | pose_library/operators.py | 13 |
2 files changed, 6 insertions, 30 deletions
diff --git a/pose_library/functions.py b/pose_library/functions.py index f4ce9219..c94c9a39 100644 --- a/pose_library/functions.py +++ b/pose_library/functions.py @@ -95,26 +95,3 @@ def has_assets(filepath: Path) -> bool: if data_names: return True return False - - -@dataclasses.dataclass -class AssetLoadInfo: - """Everything you need to temp-load an asset.""" - - file_path: str - asset_name: str - id_type: str - - -def active_asset_load_info( - asset_library: AssetLibraryReference, asset: FileSelectEntry -) -> Optional[AssetLoadInfo]: - asset_lib_path = bpy.types.AssetHandle.get_full_library_path(asset, asset_library) - if asset_lib_path == "": - return None - - return AssetLoadInfo( - asset_lib_path, - asset.name, - asset.id_type, - ) diff --git a/pose_library/operators.py b/pose_library/operators.py index baef87b0..fee94bad 100644 --- a/pose_library/operators.py +++ b/pose_library/operators.py @@ -304,26 +304,25 @@ class PoseAssetUser: def _load_and_use_pose(self, context: Context) -> Set[str]: asset_library = context.asset_library asset = context.asset_file_handle + asset_lib_path = bpy.types.AssetHandle.get_full_library_path(asset, asset_library) - asset_load_info = functions.active_asset_load_info(asset_library, asset) - if not asset_load_info: + if not asset_lib_path: self.report( # type: ignore {"ERROR"}, # TODO: Add some way to get the library name from the library reference (just asset_library.name?). f"Selected asset {asset.name} could not be located inside the asset library", ) return {"CANCELLED"} - if asset_load_info.id_type != 'ACTION': + if asset.id_type != 'ACTION': self.report( # type: ignore {"ERROR"}, - f"Selected asset {asset_load_info.asset_name} is not an Action", + f"Selected asset {asset.name} is not an Action", ) return {"CANCELLED"} with bpy.types.BlendData.temp_data() as temp_data: - str_path = asset_load_info.file_path - with temp_data.libraries.load(str_path) as (data_from, data_to): - data_to.actions = [asset_load_info.asset_name] + with temp_data.libraries.load(asset_lib_path) as (data_from, data_to): + data_to.actions = [asset.name] action: Action = data_to.actions[0] return self.use_pose(context, action) |