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
4 changed files with 13 additions and 9 deletions
Showing only changes of commit d830910f59 - Show all commits

View File

@ -334,11 +334,12 @@ bool autokeyframe_property(bContext *C,
/* 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);
const std::optional<std::string> group = (fcu && fcu->grp) ? fcu->grp->name : nullptr;
CombinedKeyingResult result = insert_keyframes(bmain,
*id,
{{path, {}, array_index}},
(fcu && fcu->grp) ? fcu->grp->name : nullptr,
group,
std::nullopt,
anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),

View File

@ -1082,12 +1082,13 @@ static int insert_key_to_keying_set_path(bContext *C,
CombinedKeyingResult combined_result;
for (; array_index < array_length; array_index++) {
if (mode == ModifyKeyMode::INSERT) {
BLI_assert(array_index >= 0);
const std::optional<int> index = array_index >= 0 ? std::optional(array_index) :
std::nullopt;
const std::optional<std::string> group = groupname ? std::optional(groupname) : std::nullopt;
CombinedKeyingResult result = insert_keyframes(bmain,
*keyingset_path->id,
nathanvegdahl marked this conversation as resolved Outdated

might just be me but I find it easier to read if such things are outside the function arguments.

might just be me but I find it easier to read if such things are outside the function arguments.
{{keyingset_path->rna_path, {}, array_index}},
groupname ? std::optional(groupname) :
std::nullopt,
{{keyingset_path->rna_path, {}, index}},
group,
std::nullopt,
anim_eval_context,
keytype,

View File

@ -849,12 +849,13 @@ static void insert_fcurve_key(bAnimContext *ac,
* so it's easier for now to just read the F-Curve directly.
* (TODO: add the full-blown PointerRNA relative parsing case here...)
*/
const std::optional<std::string> channel_group = fcu->grp ? std::optional(fcu->grp->name) :
std::nullopt;
if (ale->id && !ale->owner) {
CombinedKeyingResult result = insert_keyframes(ac->bmain,
*ale->id,
{{fcu->rna_path, {}, fcu->array_index}},
fcu->grp ? std::optional(fcu->grp->name) :
std::nullopt,
channel_group,
std::nullopt,
anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),

View File

@ -205,12 +205,13 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
* If this is set, then it's a driver. If we don't check for this, we'd end
* up adding the keyframes on a new F-Curve in the action data instead.
*/
const std::optional<std::string> channel_group = fcu->grp ? std::optional(fcu->grp->name) :
std::nullopt;
if (ale->id && !ale->owner && !fcu->driver) {
CombinedKeyingResult result = insert_keyframes(ac->bmain,
*ale->id,
{{fcu->rna_path, {}, fcu->array_index}},
fcu->grp ? std::optional(fcu->grp->name) :
std::nullopt,
channel_group,
std::nullopt,
anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),