Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/asset.cc
| Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | void BKE_asset_metadata_catalog_id_set(struct AssetMetaData *asset_data, | ||||
| /* The substr() call is necessary to make copy() copy the first N characters (instead of refusing | /* The substr() call is necessary to make copy() copy the first N characters (instead of refusing | ||||
| * to copy and producing an empty string). */ | * to copy and producing an empty string). */ | ||||
| StringRef trimmed_id = | StringRef trimmed_id = | ||||
| StringRef(catalog_simple_name).trim().substr(0, max_simple_name_length - 1); | StringRef(catalog_simple_name).trim().substr(0, max_simple_name_length - 1); | ||||
| trimmed_id.copy(asset_data->catalog_simple_name, max_simple_name_length); | trimmed_id.copy(asset_data->catalog_simple_name, max_simple_name_length); | ||||
| } | } | ||||
| void BKE_asset_metadata_idprop_ensure(AssetMetaData *asset_data, IDProperty *prop) | |||||
| { | |||||
| if (!asset_data->properties) { | |||||
| IDPropertyTemplate val = {0}; | |||||
| asset_data->properties = IDP_New(IDP_GROUP, &val, "AssetMetaData.properties"); | |||||
| } | |||||
| /* Important: The property may already exist. For now just allow always allow a newly allocated | |||||
| * property, and replace the existing one as a way of updating. */ | |||||
| IDP_ReplaceInGroup(asset_data->properties, prop); | |||||
| } | |||||
| IDProperty *BKE_asset_metadata_idprop_find(const AssetMetaData *asset_data, const char *name) | |||||
| { | |||||
| if (!asset_data->properties) { | |||||
| return nullptr; | |||||
| } | |||||
| return IDP_GetPropertyFromGroup(asset_data->properties, name); | |||||
| } | |||||
| /* Queries -------------------------------------------- */ | /* Queries -------------------------------------------- */ | ||||
| PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *UNUSED(asset_data), | PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *UNUSED(asset_data), | ||||
| const ID *id) | const ID *id) | ||||
| { | { | ||||
| return BKE_previewimg_id_get(id); | return BKE_previewimg_id_get(id); | ||||
| } | } | ||||
| Show All 13 Lines | void BKE_asset_metadata_write(BlendWriter *writer, AssetMetaData *asset_data) | ||||
| LISTBASE_FOREACH (AssetTag *, tag, &asset_data->tags) { | LISTBASE_FOREACH (AssetTag *, tag, &asset_data->tags) { | ||||
| BLO_write_struct(writer, AssetTag, tag); | BLO_write_struct(writer, AssetTag, tag); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_asset_metadata_read(BlendDataReader *reader, AssetMetaData *asset_data) | void BKE_asset_metadata_read(BlendDataReader *reader, AssetMetaData *asset_data) | ||||
| { | { | ||||
| /* asset_data itself has been read already. */ | /* asset_data itself has been read already. */ | ||||
| asset_data->local_type_info = nullptr; | |||||
| if (asset_data->properties) { | if (asset_data->properties) { | ||||
| BLO_read_data_address(reader, &asset_data->properties); | BLO_read_data_address(reader, &asset_data->properties); | ||||
| IDP_BlendDataRead(reader, &asset_data->properties); | IDP_BlendDataRead(reader, &asset_data->properties); | ||||
| } | } | ||||
| BLO_read_data_address(reader, &asset_data->description); | BLO_read_data_address(reader, &asset_data->description); | ||||
| BLO_read_list(reader, &asset_data->tags); | BLO_read_list(reader, &asset_data->tags); | ||||
| BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags); | BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags); | ||||
| } | } | ||||