diff options
author | Bastien Montagne <bastien@blender.org> | 2022-06-08 18:47:45 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-06-08 19:00:42 +0300 |
commit | d62e6f122575a0a8292e731fecebe663589e81ea (patch) | |
tree | b4bd3ea33e9d4c4b266a0bc3d2fe660a08e6be22 | |
parent | 1a71f9d2b8174009d1a79fd555ed33d20dc5c078 (diff) |
RNA nodetree: improve ImageUser path helper.
Refactor the code, and optimize it slightly (no need e.g. to check for
nodes when the nodetree is of a type that cannot have image user nodes).
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 53f207328c9..65a8d8bf24a 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1610,26 +1610,31 @@ static char *rna_Node_path(const PointerRNA *ptr) char *rna_Node_ImageUser_path(const PointerRNA *ptr) { bNodeTree *ntree = (bNodeTree *)ptr->owner_id; - bNode *node; - char name_esc[sizeof(node->name) * 2]; + if (!ELEM(ntree->type, NTREE_SHADER, NTREE_CUSTOM)) { + return NULL; + } - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == SH_NODE_TEX_ENVIRONMENT) { - NodeTexEnvironment *data = node->storage; - if (&data->iuser != ptr->data) { - continue; + for (bNode *node = ntree->nodes.first; node; node = node->next) { + switch (node->type) { + case SH_NODE_TEX_ENVIRONMENT: { + NodeTexEnvironment *data = node->storage; + if (&data->iuser != ptr->data) { + continue; + } + break; } - } - else if (node->type == SH_NODE_TEX_IMAGE) { - NodeTexImage *data = node->storage; - if (&data->iuser != ptr->data) { - continue; + case SH_NODE_TEX_IMAGE: { + NodeTexImage *data = node->storage; + if (&data->iuser != ptr->data) { + continue; + } + break; } - } - else { - continue; + default: + continue; } + char name_esc[sizeof(node->name) * 2]; BLI_str_escape(name_esc, node->name, sizeof(name_esc)); return BLI_sprintfN("nodes[\"%s\"].image_user", name_esc); } |