reconcileMotionBindings function

List<String> reconcileMotionBindings(
  1. MotionDocument motion
)

The motion half of the binding rule: a key whose value moved off its parameter's default moves the default, and every other key reading that parameter follows. A key reading a parameter that is no longer declared loses the reference in the same edit, reported by group and property, rather than at save. Run by the editor after each mutation.

Implementation

List<String> reconcileMotionBindings(MotionDocument motion) {
  var dropped = <String>[];
  for (var g in motion.groups) {
    for (var e in g.tracks.entries) {
      for (var k in e.value.keys) {
        var name = k.paramRef;
        if (name == null) continue;
        var i = motion.params.indexWhere((p) => p.name == name);
        var decl = i < 0 ? null : motion.params[i];
        var kind = e.value.kind == TrackKind.color
            ? SceneParamKind.color
            : SceneParamKind.number;
        if (decl == null || decl.kind != kind) {
          k.paramRef = null;
          dropped.add('${g.name}.${e.key}');
        } else if (decl.defaultValue != k.value) {
          motion.params[i] = decl.withDefault(k.value);
          for (var other in motion.keysReading(name)) {
            if (!identical(other, k)) other.value = k.value;
          }
        }
      }
    }
  }
  return dropped;
}