Refactor: Remove asset library reference in node add menu code

The asset library reference isn't needed anymore for importing assets
since ccc9eef1b9. So it doesn't need to be set in the add menu context,
which simplifies code a bit.
This commit is contained in:
Julian Eisel
2023-06-14 14:51:22 +02:00
parent 345d4087b7
commit 8783038a38
2 changed files with 11 additions and 22 deletions

View File

@@ -47,14 +47,10 @@ static void node_add_menu_assets_listen_fn(const wmRegionListenerParams *params)
}
}
struct LibraryAsset {
AssetLibraryReference library_ref;
asset_system::AssetRepresentation &asset;
};
struct AssetItemTree {
asset_system::AssetCatalogTree catalogs;
MultiValueMap<asset_system::AssetCatalogPath, LibraryAsset> assets_per_path;
MultiValueMap<asset_system::AssetCatalogPath, asset_system::AssetRepresentation *>
assets_per_path;
};
static AssetLibraryReference all_library_reference()
@@ -106,7 +102,8 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree *node
}
/* Find all the matching node group assets for every catalog path. */
MultiValueMap<asset_system::AssetCatalogPath, LibraryAsset> assets_per_path;
MultiValueMap<asset_system::AssetCatalogPath, asset_system::AssetRepresentation *>
assets_per_path;
AssetFilterSettings type_filter{};
type_filter.id_types = FILTER_ID_NT;
@@ -139,7 +136,7 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree *node
if (catalog == nullptr) {
return true;
}
assets_per_path.add(catalog->path, LibraryAsset{all_library_ref, asset});
assets_per_path.add(catalog->path, &asset);
return true;
});
@@ -182,29 +179,25 @@ static void node_add_catalog_assets_draw(const bContext *C, Menu *menu)
const asset_system::AssetCatalogPath &menu_path =
*static_cast<const asset_system::AssetCatalogPath *>(menu_path_ptr.data);
const Span<LibraryAsset> asset_items = tree.assets_per_path.lookup(menu_path);
const Span<asset_system::AssetRepresentation *> assets = tree.assets_per_path.lookup(menu_path);
asset_system::AssetCatalogTreeItem *catalog_item = tree.catalogs.find_item(menu_path);
BLI_assert(catalog_item != nullptr);
if (asset_items.is_empty() && !catalog_item->has_children()) {
if (assets.is_empty() && !catalog_item->has_children()) {
return;
}
uiLayout *layout = menu->layout;
uiItemS(layout);
for (const LibraryAsset &item : asset_items) {
for (const asset_system::AssetRepresentation *asset : assets) {
uiLayout *col = uiLayoutColumn(layout, false);
PointerRNA asset_ptr{nullptr, &RNA_AssetRepresentation, &item.asset};
PointerRNA asset_ptr{
nullptr, &RNA_AssetRepresentation, const_cast<asset_system::AssetRepresentation *>(asset)};
uiLayoutSetContextPointer(col, "asset", &asset_ptr);
PointerRNA library_ptr{&screen.id,
&RNA_AssetLibraryReference,
const_cast<AssetLibraryReference *>(&item.library_ref)};
uiLayoutSetContextPointer(col, "asset_library_ref", &library_ptr);
uiItemO(col, IFACE_(item.asset.get_name().c_str()), ICON_NONE, "NODE_OT_add_group_asset");
uiItemO(col, IFACE_(asset->get_name().c_str()), ICON_NONE, "NODE_OT_add_group_asset");
}
asset_system::AssetLibrary *all_library = get_all_library_once_available();

View File

@@ -427,10 +427,6 @@ static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEven
ARegion &region = *CTX_wm_region(C);
SpaceNode &snode = *CTX_wm_space_node(C);
const AssetLibraryReference *library_ref = CTX_wm_asset_library_ref(C);
if (!library_ref) {
return OPERATOR_CANCELLED;
}
const AssetRepresentation *asset = CTX_wm_asset(C);
if (!asset) {
return OPERATOR_CANCELLED;