diff options
author | Julian Eisel <julian@blender.org> | 2020-07-08 22:37:39 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-07-08 22:41:29 +0300 |
commit | 243a59ba6da493f3390ffbaaa52074b8995266f2 (patch) | |
tree | 1ec88f447ef1c29dc39c61e017958a3d05a338e2 /source/blender/blenkernel/intern/asset.c | |
parent | 98ef119dcf9bc5d289ab4d75eb6b2d138b4a2b4d (diff) |
Add custom tag support to assets
Tags are basically a list of strings. We could optimize these in future if
needed. We could also easily add colors or icons for individual tags (e.g. like
on developer.blender.org).
Note that there's no UI for this yet. Functionality is available via Python
though.
Diffstat (limited to 'source/blender/blenkernel/intern/asset.c')
-rw-r--r-- | source/blender/blenkernel/intern/asset.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c index b243b8a50e6..4edf35a686c 100644 --- a/source/blender/blenkernel/intern/asset.c +++ b/source/blender/blenkernel/intern/asset.c @@ -20,6 +20,8 @@ #include <string.h> +#include "BLI_listbase.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #include "BKE_asset.h" @@ -51,6 +53,7 @@ static void asset_free_data(ID *id) BKE_previewimg_free(&asset->preview); MEM_SAFE_FREE(asset->description); + BLI_freelistN(&asset->tags); } static void asset_foreach_id(ID *id, LibraryForeachIDData *data) @@ -77,6 +80,36 @@ IDTypeInfo IDType_ID_AST = { /* foreach_id */ asset_foreach_id, }; +struct CustomTagEnsureResult BKE_asset_tag_ensure(Asset *asset, const char *name) +{ + struct CustomTagEnsureResult result = {.tag = NULL}; + if (!name[0]) { + return result; + } + + CustomTag *tag = BLI_findstring(&asset->tags, name, offsetof(CustomTag, name)); + + if (tag) { + result.tag = tag; + result.is_new = false; + return result; + } + + tag = MEM_mallocN(sizeof(*tag), __func__); + BLI_strncpy(tag->name, name, sizeof(tag->name)); + + BLI_addtail(&asset->tags, tag); + + result.tag = tag; + result.is_new = true; + return result; +} + +void BKE_asset_tag_remove(Asset *asset, CustomTag *tag) +{ + BLI_freelinkN(&asset->tags, tag); +} + AssetData *BKE_asset_data_create(void) { return MEM_callocN(sizeof(AssetData), __func__); |