Refactor: combine insert_keyframe() and insert_key_rna() into a single function #122053

Merged
Nathan Vegdahl merged 49 commits from nathanvegdahl/blender:combine_keying_functions into main 2024-06-11 16:43:08 +02:00
2 changed files with 18 additions and 19 deletions
Showing only changes of commit 82b1c57963 - Show all commits

View File

@ -321,7 +321,6 @@ bool autokeyframe_property(bContext *C,
if (autokeyframe_cfra_can_key(scene, id)) {
ToolSettings *ts = scene->toolsettings;
const eInsertKeyFlags flag = get_autokey_flags(scene);
const std::optional<std::string> path = RNA_path_from_ID_to_property(ptr, prop);
if (only_if_property_keyed) {
/* NOTE: We use rnaindex instead of fcu->array_index,
@ -329,19 +328,21 @@ bool autokeyframe_property(bContext *C,
* E.g., color wheels (see #42567). */
BLI_assert((fcu->array_index == rnaindex) || (rnaindex == -1));
}
CombinedKeyingResult result = insert_key_rna(
bmain,
*id,
(fcu && fcu->grp) ? fcu->grp->name : nullptr,
{{
fcu ? fcu->rna_path : (path ? path->c_str() : nullptr), // Path.
std::nullopt, // Key.
rnaindex == -1 ? std::nullopt : std::optional(rnaindex), // Index.
}},
std::nullopt,
anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),
flag);
const std::string path = fcu ? fcu->rna_path :
RNA_path_from_ID_to_property(ptr, prop).value_or("");
/* NOTE: `rnaindex == -1` is a magic number, meaning either "operate on
* all elements" or "not an array property". */
const std::optional<int> array_index = rnaindex < 0 ? std::nullopt : std::optional(rnaindex);
CombinedKeyingResult result = insert_key_rna(bmain,
*id,
(fcu && fcu->grp) ? fcu->grp->name : nullptr,
{{path, {}, array_index}},
std::nullopt,
anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),
flag);
changed = result.get_count(SingleKeyingResult::SUCCESS) != 0;
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, nullptr);
}

View File

@ -1049,17 +1049,15 @@ static int insert_key_button_exec(bContext *C, wmOperator *op)
group = "Object Transforms";
}
/* Note: an index of -1 is a magic value that indicates either that
* we're operating on all elements of an array property, or that the
* property isn't an array. Here we convert that to simply not
* specifying an index at all. */
/* NOTE: `index == -1` is a magic number, meaning "operate on all elements"
* or "not an array property". */
const std::optional<int> array_index = (all || index < 0) ? std::nullopt :
std::optional(index);
CombinedKeyingResult result = insert_key_rna(bmain,
*ptr.owner_id,
group,
{{path->c_str(), {}, array_index}},
{{*path, {}, array_index}},
std::nullopt,
anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),