Assets: Add Author field to asset metadata

This is information you'd typically want to be visible in the UI. It's optional
of course, so if not relevant, it can just remain unset.
This commit is contained in:
Julian Eisel 2021-10-25 13:48:48 +02:00
parent e7bea3fb6e
commit 4100a79219
4 changed files with 52 additions and 0 deletions

View File

@ -734,6 +734,7 @@ class ASSETBROWSER_PT_metadata(asset_utils.AssetBrowserPanel, Panel):
row.operator("asset.open_containing_blend_file", text="", icon='TOOL_SETTINGS')
layout.prop(asset_file_handle.asset_data, "description")
layout.prop(asset_file_handle.asset_data, "author")
class ASSETBROWSER_PT_metadata_preview(asset_utils.AssetMetaDataPanel, Panel):

View File

@ -53,6 +53,7 @@ void BKE_asset_metadata_free(AssetMetaData **asset_data)
if ((*asset_data)->properties) {
IDP_FreeProperty((*asset_data)->properties);
}
MEM_SAFE_FREE((*asset_data)->author);
MEM_SAFE_FREE((*asset_data)->description);
BLI_freelistN(&(*asset_data)->tags);
@ -158,6 +159,9 @@ void BKE_asset_metadata_write(BlendWriter *writer, AssetMetaData *asset_data)
IDP_BlendWrite(writer, asset_data->properties);
}
if (asset_data->author) {
BLO_write_string(writer, asset_data->author);
}
if (asset_data->description) {
BLO_write_string(writer, asset_data->description);
}
@ -175,6 +179,7 @@ void BKE_asset_metadata_read(BlendDataReader *reader, AssetMetaData *asset_data)
IDP_BlendDataRead(reader, &asset_data->properties);
}
BLO_read_data_address(reader, &asset_data->author);
BLO_read_data_address(reader, &asset_data->description);
BLO_read_list(reader, &asset_data->tags);
BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags);

View File

@ -72,8 +72,12 @@ typedef struct AssetMetaData {
* #catalog_id is updated. */
char catalog_simple_name[64]; /* MAX_NAME */
/** Optional name of the author for display in the UI. Dynamic length. */
char *author;
/** Optional description of this asset for display in the UI. Dynamic length. */
char *description;
/** User defined tags for this asset. The asset manager uses these for filtering, but how they
* function exactly (e.g. how they are registered to provide a list of searchable available tags)
* is up to the asset-engine. */

View File

@ -139,6 +139,40 @@ static IDProperty **rna_AssetMetaData_idprops(PointerRNA *ptr)
return &asset_data->properties;
}
static void rna_AssetMetaData_author_get(PointerRNA *ptr, char *value)
{
AssetMetaData *asset_data = ptr->data;
if (asset_data->author) {
strcpy(value, asset_data->author);
}
else {
value[0] = '\0';
}
}
static int rna_AssetMetaData_author_length(PointerRNA *ptr)
{
AssetMetaData *asset_data = ptr->data;
return asset_data->author ? strlen(asset_data->author) : 0;
}
static void rna_AssetMetaData_author_set(PointerRNA *ptr, const char *value)
{
AssetMetaData *asset_data = ptr->data;
if (asset_data->author) {
MEM_freeN(asset_data->author);
}
if (value[0]) {
asset_data->author = BLI_strdup(value);
}
else {
asset_data->author = NULL;
}
}
static void rna_AssetMetaData_description_get(PointerRNA *ptr, char *value)
{
AssetMetaData *asset_data = ptr->data;
@ -347,6 +381,14 @@ static void rna_def_asset_data(BlenderRNA *brna)
RNA_def_struct_idprops_func(srna, "rna_AssetMetaData_idprops");
RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES); /* Mandatory! */
prop = RNA_def_property(srna, "author", PROP_STRING, PROP_NONE);
RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
RNA_def_property_string_funcs(prop,
"rna_AssetMetaData_author_get",
"rna_AssetMetaData_author_length",
"rna_AssetMetaData_author_set");
RNA_def_property_ui_text(prop, "Author", "Name of the creator of the asset");
prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
RNA_def_property_string_funcs(prop,