diff --git a/lib/src/core/core.dart b/lib/src/core/core.dart index dde79c4..efa7fd8 100644 --- a/lib/src/core/core.dart +++ b/lib/src/core/core.dart @@ -57,6 +57,7 @@ abstract class Core { } } +// ignore: avoid_classes_with_only_static_members class InternalCoreHelper { static void markValid(Core object) { object._hasValidated = true; diff --git a/lib/src/generated/animation/keyframe_play_base.dart b/lib/src/generated/animation/keyframe_play_base.dart new file mode 100644 index 0000000..56c02c6 --- /dev/null +++ b/lib/src/generated/animation/keyframe_play_base.dart @@ -0,0 +1,72 @@ +/// Core automatically generated +/// lib/src/generated/animation/keyframe_play_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/animation/keyframe_base.dart'; +import 'package:rive/src/rive_core/animation/keyframe.dart'; + +abstract class KeyFramePlayBase extends KeyFrame { + static const int typeKey = 99; + @override + int get coreType => KeyFramePlayBase.typeKey; + @override + Set get coreTypes => {KeyFramePlayBase.typeKey, KeyFrameBase.typeKey}; + + /// -------------------------------------------------------------------------- + /// NestedPlaybackValue field with key 203. + static const int nestedPlaybackValueInitialValue = 0; + int _nestedPlaybackValue = nestedPlaybackValueInitialValue; + static const int nestedPlaybackValuePropertyKey = 203; + + /// Backing value for NestedPlayback enum. + int get nestedPlaybackValue => _nestedPlaybackValue; + + /// Change the [_nestedPlaybackValue] field value. + /// [nestedPlaybackValueChanged] will be invoked only if the field's value has + /// changed. + set nestedPlaybackValue(int value) { + if (_nestedPlaybackValue == value) { + return; + } + int from = _nestedPlaybackValue; + _nestedPlaybackValue = value; + if (hasValidated) { + nestedPlaybackValueChanged(from, value); + } + } + + void nestedPlaybackValueChanged(int from, int to); + + /// -------------------------------------------------------------------------- + /// ReferenceTime field with key 204. + static const int referenceTimeInitialValue = 0; + int _referenceTime = referenceTimeInitialValue; + static const int referenceTimePropertyKey = 204; + + /// Represents time value to play/stop at, note that depending on + /// playbackValue this could also be a percentage. + int get referenceTime => _referenceTime; + + /// Change the [_referenceTime] field value. + /// [referenceTimeChanged] will be invoked only if the field's value has + /// changed. + set referenceTime(int value) { + if (_referenceTime == value) { + return; + } + int from = _referenceTime; + _referenceTime = value; + if (hasValidated) { + referenceTimeChanged(from, value); + } + } + + void referenceTimeChanged(int from, int to); + + @override + void copy(covariant KeyFramePlayBase source) { + super.copy(source); + _nestedPlaybackValue = source._nestedPlaybackValue; + _referenceTime = source._referenceTime; + } +} diff --git a/lib/src/generated/animation/nested_linear_animation_base.dart b/lib/src/generated/animation/nested_linear_animation_base.dart new file mode 100644 index 0000000..7cc3bd6 --- /dev/null +++ b/lib/src/generated/animation/nested_linear_animation_base.dart @@ -0,0 +1,51 @@ +/// Core automatically generated +/// lib/src/generated/animation/nested_linear_animation_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/nested_animation_base.dart'; +import 'package:rive/src/rive_core/animation/linear_animation.dart'; +import 'package:rive/src/rive_core/nested_animation.dart'; + +abstract class NestedLinearAnimationBase + extends NestedAnimation { + static const int typeKey = 97; + @override + int get coreType => NestedLinearAnimationBase.typeKey; + @override + Set get coreTypes => { + NestedLinearAnimationBase.typeKey, + NestedAnimationBase.typeKey, + ComponentBase.typeKey + }; + + /// -------------------------------------------------------------------------- + /// Mix field with key 200. + static const double mixInitialValue = 1; + double _mix = mixInitialValue; + static const int mixPropertyKey = 200; + + /// Value to mix the animation in. + double get mix => _mix; + + /// Change the [_mix] field value. + /// [mixChanged] will be invoked only if the field's value has changed. + set mix(double value) { + if (_mix == value) { + return; + } + double from = _mix; + _mix = value; + if (hasValidated) { + mixChanged(from, value); + } + } + + void mixChanged(double from, double to); + + @override + void copy(covariant NestedLinearAnimationBase source) { + super.copy(source); + _mix = source._mix; + } +} diff --git a/lib/src/generated/animation/nested_remap_animation_base.dart b/lib/src/generated/animation/nested_remap_animation_base.dart new file mode 100644 index 0000000..00a4a5b --- /dev/null +++ b/lib/src/generated/animation/nested_remap_animation_base.dart @@ -0,0 +1,51 @@ +/// Core automatically generated +/// lib/src/generated/animation/nested_remap_animation_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/animation/nested_linear_animation_base.dart'; +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/nested_animation_base.dart'; +import 'package:rive/src/rive_core/animation/nested_linear_animation.dart'; + +abstract class NestedRemapAnimationBase extends NestedLinearAnimation { + static const int typeKey = 98; + @override + int get coreType => NestedRemapAnimationBase.typeKey; + @override + Set get coreTypes => { + NestedRemapAnimationBase.typeKey, + NestedLinearAnimationBase.typeKey, + NestedAnimationBase.typeKey, + ComponentBase.typeKey + }; + + /// -------------------------------------------------------------------------- + /// Time field with key 202. + static const double timeInitialValue = 0.0; + double _time = timeInitialValue; + static const int timePropertyKey = 202; + + /// Time value in seconds for the nested linear animation. + double get time => _time; + + /// Change the [_time] field value. + /// [timeChanged] will be invoked only if the field's value has changed. + set time(double value) { + if (_time == value) { + return; + } + double from = _time; + _time = value; + if (hasValidated) { + timeChanged(from, value); + } + } + + void timeChanged(double from, double to); + + @override + void copy(covariant NestedRemapAnimationBase source) { + super.copy(source); + _time = source._time; + } +} diff --git a/lib/src/generated/animation/nested_simple_animation_base.dart b/lib/src/generated/animation/nested_simple_animation_base.dart new file mode 100644 index 0000000..92bd5a8 --- /dev/null +++ b/lib/src/generated/animation/nested_simple_animation_base.dart @@ -0,0 +1,76 @@ +/// Core automatically generated +/// lib/src/generated/animation/nested_simple_animation_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/animation/nested_linear_animation_base.dart'; +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/nested_animation_base.dart'; +import 'package:rive/src/rive_core/animation/nested_linear_animation.dart'; + +abstract class NestedSimpleAnimationBase extends NestedLinearAnimation { + static const int typeKey = 96; + @override + int get coreType => NestedSimpleAnimationBase.typeKey; + @override + Set get coreTypes => { + NestedSimpleAnimationBase.typeKey, + NestedLinearAnimationBase.typeKey, + NestedAnimationBase.typeKey, + ComponentBase.typeKey + }; + + /// -------------------------------------------------------------------------- + /// Speed field with key 199. + static const double speedInitialValue = 1; + double _speed = speedInitialValue; + static const int speedPropertyKey = 199; + + /// Speed to play the nested animation at. + double get speed => _speed; + + /// Change the [_speed] field value. + /// [speedChanged] will be invoked only if the field's value has changed. + set speed(double value) { + if (_speed == value) { + return; + } + double from = _speed; + _speed = value; + if (hasValidated) { + speedChanged(from, value); + } + } + + void speedChanged(double from, double to); + + /// -------------------------------------------------------------------------- + /// IsPlaying field with key 201. + static const bool isPlayingInitialValue = false; + bool _isPlaying = isPlayingInitialValue; + static const int isPlayingPropertyKey = 201; + + /// Enumerated backing value for playback state. + bool get isPlaying => _isPlaying; + + /// Change the [_isPlaying] field value. + /// [isPlayingChanged] will be invoked only if the field's value has changed. + set isPlaying(bool value) { + if (_isPlaying == value) { + return; + } + bool from = _isPlaying; + _isPlaying = value; + if (hasValidated) { + isPlayingChanged(from, value); + } + } + + void isPlayingChanged(bool from, bool to); + + @override + void copy(covariant NestedSimpleAnimationBase source) { + super.copy(source); + _speed = source._speed; + _isPlaying = source._isPlaying; + } +} diff --git a/lib/src/generated/animation/nested_state_machine_base.dart b/lib/src/generated/animation/nested_state_machine_base.dart new file mode 100644 index 0000000..c76b305 --- /dev/null +++ b/lib/src/generated/animation/nested_state_machine_base.dart @@ -0,0 +1,20 @@ +/// Core automatically generated +/// lib/src/generated/animation/nested_state_machine_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/nested_animation_base.dart'; +import 'package:rive/src/rive_core/animation/state_machine.dart'; +import 'package:rive/src/rive_core/nested_animation.dart'; + +abstract class NestedStateMachineBase extends NestedAnimation { + static const int typeKey = 95; + @override + int get coreType => NestedStateMachineBase.typeKey; + @override + Set get coreTypes => { + NestedStateMachineBase.typeKey, + NestedAnimationBase.typeKey, + ComponentBase.typeKey + }; +} diff --git a/lib/src/generated/nested_animation_base.dart b/lib/src/generated/nested_animation_base.dart new file mode 100644 index 0000000..65eed28 --- /dev/null +++ b/lib/src/generated/nested_animation_base.dart @@ -0,0 +1,45 @@ +/// Core automatically generated lib/src/generated/nested_animation_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/rive_core/component.dart'; + +abstract class NestedAnimationBase extends Component { + static const int typeKey = 93; + @override + int get coreType => NestedAnimationBase.typeKey; + @override + Set get coreTypes => + {NestedAnimationBase.typeKey, ComponentBase.typeKey}; + + /// -------------------------------------------------------------------------- + /// AnimationId field with key 198. + static const int animationIdInitialValue = -1; + int _animationId = animationIdInitialValue; + static const int animationIdPropertyKey = 198; + + /// Identifier used to track the animation in the nested artboard. + int get animationId => _animationId; + + /// Change the [_animationId] field value. + /// [animationIdChanged] will be invoked only if the field's value has + /// changed. + set animationId(int value) { + if (_animationId == value) { + return; + } + int from = _animationId; + _animationId = value; + if (hasValidated) { + animationIdChanged(from, value); + } + } + + void animationIdChanged(int from, int to); + + @override + void copy(covariant NestedAnimationBase source) { + super.copy(source); + _animationId = source._animationId; + } +} diff --git a/lib/src/generated/rive_core_context.dart b/lib/src/generated/rive_core_context.dart index b4d4fed..1989b9a 100644 --- a/lib/src/generated/rive_core_context.dart +++ b/lib/src/generated/rive_core_context.dart @@ -25,6 +25,10 @@ import 'package:rive/src/generated/animation/keyframe_color_base.dart'; import 'package:rive/src/generated/animation/keyframe_double_base.dart'; import 'package:rive/src/generated/animation/keyframe_id_base.dart'; import 'package:rive/src/generated/animation/linear_animation_base.dart'; +import 'package:rive/src/generated/animation/nested_linear_animation_base.dart'; +import 'package:rive/src/generated/animation/nested_remap_animation_base.dart'; +import 'package:rive/src/generated/animation/nested_simple_animation_base.dart'; +import 'package:rive/src/generated/animation/nested_state_machine_base.dart'; import 'package:rive/src/generated/animation/state_machine_base.dart'; import 'package:rive/src/generated/animation/state_machine_bool_base.dart'; import 'package:rive/src/generated/animation/state_machine_component_base.dart'; @@ -60,6 +64,7 @@ import 'package:rive/src/generated/constraints/translation_constraint_base.dart' import 'package:rive/src/generated/draw_rules_base.dart'; import 'package:rive/src/generated/draw_target_base.dart'; import 'package:rive/src/generated/drawable_base.dart'; +import 'package:rive/src/generated/nested_animation_base.dart'; import 'package:rive/src/generated/nested_artboard_base.dart'; import 'package:rive/src/generated/node_base.dart'; import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; @@ -105,6 +110,9 @@ import 'package:rive/src/rive_core/animation/keyframe_color.dart'; import 'package:rive/src/rive_core/animation/keyframe_double.dart'; import 'package:rive/src/rive_core/animation/keyframe_id.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; +import 'package:rive/src/rive_core/animation/nested_remap_animation.dart'; +import 'package:rive/src/rive_core/animation/nested_simple_animation.dart'; +import 'package:rive/src/rive_core/animation/nested_state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_bool.dart'; import 'package:rive/src/rive_core/animation/state_machine_layer.dart'; @@ -174,6 +182,12 @@ class RiveCoreContext { return Node(); case NestedArtboardBase.typeKey: return NestedArtboard(); + case AnimationBase.typeKey: + return Animation(); + case LinearAnimationBase.typeKey: + return LinearAnimation(); + case NestedSimpleAnimationBase.typeKey: + return NestedSimpleAnimation(); case AnimationStateBase.typeKey: return AnimationState(); case KeyedObjectBase.typeKey: @@ -196,8 +210,6 @@ class RiveCoreContext { return AnyState(); case StateMachineLayerBase.typeKey: return StateMachineLayer(); - case AnimationBase.typeKey: - return Animation(); case CubicInterpolatorBase.typeKey: return CubicInterpolator(); case StateTransitionBase.typeKey: @@ -210,18 +222,20 @@ class RiveCoreContext { return StateMachine(); case EntryStateBase.typeKey: return EntryState(); - case LinearAnimationBase.typeKey: - return LinearAnimation(); case StateMachineTriggerBase.typeKey: return StateMachineTrigger(); case BlendStateDirectBase.typeKey: return BlendStateDirect(); + case NestedStateMachineBase.typeKey: + return NestedStateMachine(); case ExitStateBase.typeKey: return ExitState(); case BlendAnimation1DBase.typeKey: return BlendAnimation1D(); case BlendState1DBase.typeKey: return BlendState1D(); + case NestedRemapAnimationBase.typeKey: + return NestedRemapAnimation(); case TransitionBoolConditionBase.typeKey: return TransitionBoolCondition(); case BlendStateTransitionBase.typeKey: @@ -466,6 +480,66 @@ class RiveCoreContext { object.artboardId = value; } break; + case NestedAnimationBase.animationIdPropertyKey: + if (object is NestedAnimationBase && value is int) { + object.animationId = value; + } + break; + case AnimationBase.namePropertyKey: + if (object is AnimationBase && value is String) { + object.name = value; + } + break; + case LinearAnimationBase.fpsPropertyKey: + if (object is LinearAnimationBase && value is int) { + object.fps = value; + } + break; + case LinearAnimationBase.durationPropertyKey: + if (object is LinearAnimationBase && value is int) { + object.duration = value; + } + break; + case LinearAnimationBase.speedPropertyKey: + if (object is LinearAnimationBase && value is double) { + object.speed = value; + } + break; + case LinearAnimationBase.loopValuePropertyKey: + if (object is LinearAnimationBase && value is int) { + object.loopValue = value; + } + break; + case LinearAnimationBase.workStartPropertyKey: + if (object is LinearAnimationBase && value is int) { + object.workStart = value; + } + break; + case LinearAnimationBase.workEndPropertyKey: + if (object is LinearAnimationBase && value is int) { + object.workEnd = value; + } + break; + case LinearAnimationBase.enableWorkAreaPropertyKey: + if (object is LinearAnimationBase && value is bool) { + object.enableWorkArea = value; + } + break; + case NestedLinearAnimationBase.mixPropertyKey: + if (object is NestedLinearAnimationBase && value is double) { + object.mix = value; + } + break; + case NestedSimpleAnimationBase.speedPropertyKey: + if (object is NestedSimpleAnimationBase && value is double) { + object.speed = value; + } + break; + case NestedSimpleAnimationBase.isPlayingPropertyKey: + if (object is NestedSimpleAnimationBase && value is bool) { + object.isPlaying = value; + } + break; case AnimationStateBase.animationIdPropertyKey: if (object is AnimationStateBase && value is int) { object.animationId = value; @@ -541,11 +615,6 @@ class RiveCoreContext { object.value = value; } break; - case AnimationBase.namePropertyKey: - if (object is AnimationBase && value is String) { - object.name = value; - } - break; case CubicInterpolatorBase.x1PropertyKey: if (object is CubicInterpolatorBase && value is double) { object.x1 = value; @@ -596,41 +665,6 @@ class RiveCoreContext { object.value = value; } break; - case LinearAnimationBase.fpsPropertyKey: - if (object is LinearAnimationBase && value is int) { - object.fps = value; - } - break; - case LinearAnimationBase.durationPropertyKey: - if (object is LinearAnimationBase && value is int) { - object.duration = value; - } - break; - case LinearAnimationBase.speedPropertyKey: - if (object is LinearAnimationBase && value is double) { - object.speed = value; - } - break; - case LinearAnimationBase.loopValuePropertyKey: - if (object is LinearAnimationBase && value is int) { - object.loopValue = value; - } - break; - case LinearAnimationBase.workStartPropertyKey: - if (object is LinearAnimationBase && value is int) { - object.workStart = value; - } - break; - case LinearAnimationBase.workEndPropertyKey: - if (object is LinearAnimationBase && value is int) { - object.workEnd = value; - } - break; - case LinearAnimationBase.enableWorkAreaPropertyKey: - if (object is LinearAnimationBase && value is bool) { - object.enableWorkArea = value; - } - break; case BlendAnimation1DBase.valuePropertyKey: if (object is BlendAnimation1DBase && value is double) { object.value = value; @@ -641,6 +675,11 @@ class RiveCoreContext { object.inputId = value; } break; + case NestedRemapAnimationBase.timePropertyKey: + if (object is NestedRemapAnimationBase && value is double) { + object.time = value; + } + break; case BlendStateTransitionBase.exitBlendAnimationIdPropertyKey: if (object is BlendStateTransitionBase && value is int) { object.exitBlendAnimationId = value; @@ -1047,8 +1086,8 @@ class RiveCoreContext { static CoreFieldType? coreType(int propertyKey) { switch (propertyKey) { case ComponentBase.namePropertyKey: - case StateMachineComponentBase.namePropertyKey: case AnimationBase.namePropertyKey: + case StateMachineComponentBase.namePropertyKey: return stringType; case ComponentBase.parentIdPropertyKey: case DrawTargetBase.drawableIdPropertyKey: @@ -1062,6 +1101,12 @@ class RiveCoreContext { case DrawableBase.blendModeValuePropertyKey: case DrawableBase.drawableFlagsPropertyKey: case NestedArtboardBase.artboardIdPropertyKey: + case NestedAnimationBase.animationIdPropertyKey: + case LinearAnimationBase.fpsPropertyKey: + case LinearAnimationBase.durationPropertyKey: + case LinearAnimationBase.loopValuePropertyKey: + case LinearAnimationBase.workStartPropertyKey: + case LinearAnimationBase.workEndPropertyKey: case AnimationStateBase.animationIdPropertyKey: case KeyedObjectBase.objectIdPropertyKey: case BlendAnimationBase.animationIdPropertyKey: @@ -1077,11 +1122,6 @@ class RiveCoreContext { case StateTransitionBase.flagsPropertyKey: case StateTransitionBase.durationPropertyKey: case StateTransitionBase.exitTimePropertyKey: - case LinearAnimationBase.fpsPropertyKey: - case LinearAnimationBase.durationPropertyKey: - case LinearAnimationBase.loopValuePropertyKey: - case LinearAnimationBase.workStartPropertyKey: - case LinearAnimationBase.workEndPropertyKey: case BlendState1DBase.inputIdPropertyKey: case BlendStateTransitionBase.exitBlendAnimationIdPropertyKey: case StrokeBase.capPropertyKey: @@ -1115,6 +1155,9 @@ class RiveCoreContext { case TransformComponentBase.scaleYPropertyKey: case NodeBase.xPropertyKey: case NodeBase.yPropertyKey: + case LinearAnimationBase.speedPropertyKey: + case NestedLinearAnimationBase.mixPropertyKey: + case NestedSimpleAnimationBase.speedPropertyKey: case StateMachineNumberBase.valuePropertyKey: case TransitionNumberConditionBase.valuePropertyKey: case CubicInterpolatorBase.x1PropertyKey: @@ -1122,8 +1165,8 @@ class RiveCoreContext { case CubicInterpolatorBase.x2PropertyKey: case CubicInterpolatorBase.y2PropertyKey: case KeyFrameDoubleBase.valuePropertyKey: - case LinearAnimationBase.speedPropertyKey: case BlendAnimation1DBase.valuePropertyKey: + case NestedRemapAnimationBase.timePropertyKey: case LinearGradientBase.startXPropertyKey: case LinearGradientBase.startYPropertyKey: case LinearGradientBase.endXPropertyKey: @@ -1186,8 +1229,9 @@ class RiveCoreContext { case TransformComponentConstraintYBase.minYPropertyKey: case TransformComponentConstraintYBase.maxYPropertyKey: case IKConstraintBase.invertDirectionPropertyKey: - case KeyFrameBoolBase.valuePropertyKey: case LinearAnimationBase.enableWorkAreaPropertyKey: + case NestedSimpleAnimationBase.isPlayingPropertyKey: + case KeyFrameBoolBase.valuePropertyKey: case StateMachineBoolBase.valuePropertyKey: case ShapePaintBase.isVisiblePropertyKey: case StrokeBase.transformAffectsStrokePropertyKey: @@ -1209,10 +1253,10 @@ class RiveCoreContext { switch (propertyKey) { case ComponentBase.namePropertyKey: return (object as ComponentBase).name; - case StateMachineComponentBase.namePropertyKey: - return (object as StateMachineComponentBase).name; case AnimationBase.namePropertyKey: return (object as AnimationBase).name; + case StateMachineComponentBase.namePropertyKey: + return (object as StateMachineComponentBase).name; } return ''; } @@ -1243,6 +1287,18 @@ class RiveCoreContext { return (object as DrawableBase).drawableFlags; case NestedArtboardBase.artboardIdPropertyKey: return (object as NestedArtboardBase).artboardId; + case NestedAnimationBase.animationIdPropertyKey: + return (object as NestedAnimationBase).animationId; + case LinearAnimationBase.fpsPropertyKey: + return (object as LinearAnimationBase).fps; + case LinearAnimationBase.durationPropertyKey: + return (object as LinearAnimationBase).duration; + case LinearAnimationBase.loopValuePropertyKey: + return (object as LinearAnimationBase).loopValue; + case LinearAnimationBase.workStartPropertyKey: + return (object as LinearAnimationBase).workStart; + case LinearAnimationBase.workEndPropertyKey: + return (object as LinearAnimationBase).workEnd; case AnimationStateBase.animationIdPropertyKey: return (object as AnimationStateBase).animationId; case KeyedObjectBase.objectIdPropertyKey: @@ -1273,16 +1329,6 @@ class RiveCoreContext { return (object as StateTransitionBase).duration; case StateTransitionBase.exitTimePropertyKey: return (object as StateTransitionBase).exitTime; - case LinearAnimationBase.fpsPropertyKey: - return (object as LinearAnimationBase).fps; - case LinearAnimationBase.durationPropertyKey: - return (object as LinearAnimationBase).duration; - case LinearAnimationBase.loopValuePropertyKey: - return (object as LinearAnimationBase).loopValue; - case LinearAnimationBase.workStartPropertyKey: - return (object as LinearAnimationBase).workStart; - case LinearAnimationBase.workEndPropertyKey: - return (object as LinearAnimationBase).workEnd; case BlendState1DBase.inputIdPropertyKey: return (object as BlendState1DBase).inputId; case BlendStateTransitionBase.exitBlendAnimationIdPropertyKey: @@ -1353,6 +1399,12 @@ class RiveCoreContext { return (object as NodeBase).x; case NodeBase.yPropertyKey: return (object as NodeBase).y; + case LinearAnimationBase.speedPropertyKey: + return (object as LinearAnimationBase).speed; + case NestedLinearAnimationBase.mixPropertyKey: + return (object as NestedLinearAnimationBase).mix; + case NestedSimpleAnimationBase.speedPropertyKey: + return (object as NestedSimpleAnimationBase).speed; case StateMachineNumberBase.valuePropertyKey: return (object as StateMachineNumberBase).value; case TransitionNumberConditionBase.valuePropertyKey: @@ -1367,10 +1419,10 @@ class RiveCoreContext { return (object as CubicInterpolatorBase).y2; case KeyFrameDoubleBase.valuePropertyKey: return (object as KeyFrameDoubleBase).value; - case LinearAnimationBase.speedPropertyKey: - return (object as LinearAnimationBase).speed; case BlendAnimation1DBase.valuePropertyKey: return (object as BlendAnimation1DBase).value; + case NestedRemapAnimationBase.timePropertyKey: + return (object as NestedRemapAnimationBase).time; case LinearGradientBase.startXPropertyKey: return (object as LinearGradientBase).startX; case LinearGradientBase.startYPropertyKey: @@ -1499,10 +1551,12 @@ class RiveCoreContext { return (object as TransformComponentConstraintYBase).maxY; case IKConstraintBase.invertDirectionPropertyKey: return (object as IKConstraintBase).invertDirection; - case KeyFrameBoolBase.valuePropertyKey: - return (object as KeyFrameBoolBase).value; case LinearAnimationBase.enableWorkAreaPropertyKey: return (object as LinearAnimationBase).enableWorkArea; + case NestedSimpleAnimationBase.isPlayingPropertyKey: + return (object as NestedSimpleAnimationBase).isPlaying; + case KeyFrameBoolBase.valuePropertyKey: + return (object as KeyFrameBoolBase).value; case StateMachineBoolBase.valuePropertyKey: return (object as StateMachineBoolBase).value; case ShapePaintBase.isVisiblePropertyKey: @@ -1540,13 +1594,13 @@ class RiveCoreContext { object.name = value; } break; - case StateMachineComponentBase.namePropertyKey: - if (object is StateMachineComponentBase) { + case AnimationBase.namePropertyKey: + if (object is AnimationBase) { object.name = value; } break; - case AnimationBase.namePropertyKey: - if (object is AnimationBase) { + case StateMachineComponentBase.namePropertyKey: + if (object is StateMachineComponentBase) { object.name = value; } break; @@ -1615,6 +1669,36 @@ class RiveCoreContext { object.artboardId = value; } break; + case NestedAnimationBase.animationIdPropertyKey: + if (object is NestedAnimationBase) { + object.animationId = value; + } + break; + case LinearAnimationBase.fpsPropertyKey: + if (object is LinearAnimationBase) { + object.fps = value; + } + break; + case LinearAnimationBase.durationPropertyKey: + if (object is LinearAnimationBase) { + object.duration = value; + } + break; + case LinearAnimationBase.loopValuePropertyKey: + if (object is LinearAnimationBase) { + object.loopValue = value; + } + break; + case LinearAnimationBase.workStartPropertyKey: + if (object is LinearAnimationBase) { + object.workStart = value; + } + break; + case LinearAnimationBase.workEndPropertyKey: + if (object is LinearAnimationBase) { + object.workEnd = value; + } + break; case AnimationStateBase.animationIdPropertyKey: if (object is AnimationStateBase) { object.animationId = value; @@ -1690,31 +1774,6 @@ class RiveCoreContext { object.exitTime = value; } break; - case LinearAnimationBase.fpsPropertyKey: - if (object is LinearAnimationBase) { - object.fps = value; - } - break; - case LinearAnimationBase.durationPropertyKey: - if (object is LinearAnimationBase) { - object.duration = value; - } - break; - case LinearAnimationBase.loopValuePropertyKey: - if (object is LinearAnimationBase) { - object.loopValue = value; - } - break; - case LinearAnimationBase.workStartPropertyKey: - if (object is LinearAnimationBase) { - object.workStart = value; - } - break; - case LinearAnimationBase.workEndPropertyKey: - if (object is LinearAnimationBase) { - object.workEnd = value; - } - break; case BlendState1DBase.inputIdPropertyKey: if (object is BlendState1DBase) { object.inputId = value; @@ -1880,6 +1939,21 @@ class RiveCoreContext { object.y = value; } break; + case LinearAnimationBase.speedPropertyKey: + if (object is LinearAnimationBase) { + object.speed = value; + } + break; + case NestedLinearAnimationBase.mixPropertyKey: + if (object is NestedLinearAnimationBase) { + object.mix = value; + } + break; + case NestedSimpleAnimationBase.speedPropertyKey: + if (object is NestedSimpleAnimationBase) { + object.speed = value; + } + break; case StateMachineNumberBase.valuePropertyKey: if (object is StateMachineNumberBase) { object.value = value; @@ -1915,16 +1989,16 @@ class RiveCoreContext { object.value = value; } break; - case LinearAnimationBase.speedPropertyKey: - if (object is LinearAnimationBase) { - object.speed = value; - } - break; case BlendAnimation1DBase.valuePropertyKey: if (object is BlendAnimation1DBase) { object.value = value; } break; + case NestedRemapAnimationBase.timePropertyKey: + if (object is NestedRemapAnimationBase) { + object.time = value; + } + break; case LinearGradientBase.startXPropertyKey: if (object is LinearGradientBase) { object.startX = value; @@ -2235,16 +2309,21 @@ class RiveCoreContext { object.invertDirection = value; } break; - case KeyFrameBoolBase.valuePropertyKey: - if (object is KeyFrameBoolBase) { - object.value = value; - } - break; case LinearAnimationBase.enableWorkAreaPropertyKey: if (object is LinearAnimationBase) { object.enableWorkArea = value; } break; + case NestedSimpleAnimationBase.isPlayingPropertyKey: + if (object is NestedSimpleAnimationBase) { + object.isPlaying = value; + } + break; + case KeyFrameBoolBase.valuePropertyKey: + if (object is KeyFrameBoolBase) { + object.value = value; + } + break; case StateMachineBoolBase.valuePropertyKey: if (object is StateMachineBoolBase) { object.value = value; diff --git a/lib/src/rive.dart b/lib/src/rive.dart index 2d1ea94..821ddf4 100644 --- a/lib/src/rive.dart +++ b/lib/src/rive.dart @@ -68,11 +68,6 @@ class Rive extends LeafRenderObjectWidget { ..artboardSize = Size(artboard.width, artboard.height) ..useArtboardSize = useArtboardSize; } - - @override - void didUnmountRenderObject(covariant RiveRenderObject renderObject) { - renderObject.dispose(); - } } class RiveRenderObject extends RiveRenderBox { @@ -93,7 +88,9 @@ class RiveRenderObject extends RiveRenderBox { markNeedsLayout(); } + @override void dispose() { + super.dispose(); _artboard.redraw.removeListener(scheduleRepaint); } @@ -105,7 +102,8 @@ class RiveRenderObject extends RiveRenderBox { } @override - bool advance(double elapsedSeconds) => _artboard.advance(elapsedSeconds); + bool advance(double elapsedSeconds) => + _artboard.advance(elapsedSeconds, nested: true); @override void beforeDraw(Canvas canvas, Offset offset) { diff --git a/lib/src/rive_core/animation/animation.dart b/lib/src/rive_core/animation/animation.dart index 0fabb31..a56dbcb 100644 --- a/lib/src/rive_core/animation/animation.dart +++ b/lib/src/rive_core/animation/animation.dart @@ -1,7 +1,7 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/animation_base.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/animation_base.dart'; export 'package:rive/src/generated/animation/animation_base.dart'; class Animation extends AnimationBase { diff --git a/lib/src/rive_core/animation/animation_state.dart b/lib/src/rive_core/animation/animation_state.dart index f0805fa..e6d6303 100644 --- a/lib/src/rive_core/animation/animation_state.dart +++ b/lib/src/rive_core/animation/animation_state.dart @@ -1,9 +1,10 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/animation_state_base.dart'; import 'package:rive/src/rive_core/animation/animation_state_instance.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/animation_state_base.dart'; + export 'package:rive/src/generated/animation/animation_state_base.dart'; class AnimationState extends AnimationStateBase { diff --git a/lib/src/rive_core/animation/any_state.dart b/lib/src/rive_core/animation/any_state.dart index d1d2376..19fb579 100644 --- a/lib/src/rive_core/animation/any_state.dart +++ b/lib/src/rive_core/animation/any_state.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/generated/animation/any_state_base.dart'; +import 'package:rive/src/rive_core/animation/state_instance.dart'; + export 'package:rive/src/generated/animation/any_state_base.dart'; class AnyState extends AnyStateBase { diff --git a/lib/src/rive_core/animation/blend_animation.dart b/lib/src/rive_core/animation/blend_animation.dart index 3b0fee1..786cf3b 100644 --- a/lib/src/rive_core/animation/blend_animation.dart +++ b/lib/src/rive_core/animation/blend_animation.dart @@ -1,9 +1,10 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/blend_animation_base.dart'; +import 'package:rive/src/generated/artboard_base.dart'; import 'package:rive/src/rive_core/animation/layer_state.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/blend_animation_base.dart'; -import 'package:rive/src/generated/artboard_base.dart'; + export 'package:rive/src/generated/animation/blend_animation_base.dart'; abstract class BlendAnimation extends BlendAnimationBase { diff --git a/lib/src/rive_core/animation/blend_animation_direct.dart b/lib/src/rive_core/animation/blend_animation_direct.dart index 8fe9e8e..6771a85 100644 --- a/lib/src/rive_core/animation/blend_animation_direct.dart +++ b/lib/src/rive_core/animation/blend_animation_direct.dart @@ -1,7 +1,8 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/blend_animation_direct_base.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_number.dart'; -import 'package:rive/src/generated/animation/blend_animation_direct_base.dart'; + export 'package:rive/src/generated/animation/blend_animation_direct_base.dart'; class BlendAnimationDirect extends BlendAnimationDirectBase { diff --git a/lib/src/rive_core/animation/blend_state.dart b/lib/src/rive_core/animation/blend_state.dart index 2fe958c..91d74cb 100644 --- a/lib/src/rive_core/animation/blend_state.dart +++ b/lib/src/rive_core/animation/blend_state.dart @@ -1,6 +1,7 @@ import 'package:rive/src/core/core.dart'; -import 'package:rive/src/rive_core/animation/blend_animation.dart'; import 'package:rive/src/generated/animation/blend_state_base.dart'; +import 'package:rive/src/rive_core/animation/blend_animation.dart'; + export 'package:rive/src/generated/animation/blend_state_base.dart'; // diff --git a/lib/src/rive_core/animation/blend_state_1d.dart b/lib/src/rive_core/animation/blend_state_1d.dart index 4ec0589..dce4a42 100644 --- a/lib/src/rive_core/animation/blend_state_1d.dart +++ b/lib/src/rive_core/animation/blend_state_1d.dart @@ -1,9 +1,10 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/blend_state_1d_base.dart'; import 'package:rive/src/rive_core/animation/blend_state_1d_instance.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_number.dart'; -import 'package:rive/src/generated/animation/blend_state_1d_base.dart'; + export 'package:rive/src/generated/animation/blend_state_1d_base.dart'; class BlendState1D extends BlendState1DBase { diff --git a/lib/src/rive_core/animation/blend_state_direct.dart b/lib/src/rive_core/animation/blend_state_direct.dart index 07c2bdf..4abc4cf 100644 --- a/lib/src/rive_core/animation/blend_state_direct.dart +++ b/lib/src/rive_core/animation/blend_state_direct.dart @@ -1,6 +1,6 @@ +import 'package:rive/src/generated/animation/blend_state_direct_base.dart'; import 'package:rive/src/rive_core/animation/blend_state_direct_instance.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; -import 'package:rive/src/generated/animation/blend_state_direct_base.dart'; export 'package:rive/src/generated/animation/blend_state_direct_base.dart'; diff --git a/lib/src/rive_core/animation/blend_state_instance.dart b/lib/src/rive_core/animation/blend_state_instance.dart index 6076f16..d25e594 100644 --- a/lib/src/rive_core/animation/blend_state_instance.dart +++ b/lib/src/rive_core/animation/blend_state_instance.dart @@ -1,7 +1,7 @@ import 'dart:collection'; -import 'package:rive/src/core/core.dart'; import 'package:flutter/foundation.dart'; +import 'package:rive/src/core/core.dart'; import 'package:rive/src/rive_core/animation/blend_animation.dart'; import 'package:rive/src/rive_core/animation/blend_state.dart'; import 'package:rive/src/rive_core/animation/linear_animation_instance.dart'; diff --git a/lib/src/rive_core/animation/blend_state_transition.dart b/lib/src/rive_core/animation/blend_state_transition.dart index 6b76d5c..d76c7d0 100644 --- a/lib/src/rive_core/animation/blend_state_transition.dart +++ b/lib/src/rive_core/animation/blend_state_transition.dart @@ -1,10 +1,11 @@ +import 'package:rive/src/generated/animation/blend_state_transition_base.dart'; import 'package:rive/src/rive_core/animation/blend_animation.dart'; import 'package:rive/src/rive_core/animation/blend_state_instance.dart'; import 'package:rive/src/rive_core/animation/layer_state.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/animation/linear_animation_instance.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; -import 'package:rive/src/generated/animation/blend_state_transition_base.dart'; + export 'package:rive/src/generated/animation/blend_state_transition_base.dart'; class BlendStateTransition extends BlendStateTransitionBase { diff --git a/lib/src/rive_core/animation/cubic_interpolator.dart b/lib/src/rive_core/animation/cubic_interpolator.dart index 8216745..0e69d9c 100644 --- a/lib/src/rive_core/animation/cubic_interpolator.dart +++ b/lib/src/rive_core/animation/cubic_interpolator.dart @@ -1,9 +1,9 @@ import 'dart:typed_data'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/cubic_interpolator_base.dart'; import 'package:rive/src/rive_core/animation/interpolator.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/cubic_interpolator_base.dart'; const int newtonIterations = 4; diff --git a/lib/src/rive_core/animation/entry_state.dart b/lib/src/rive_core/animation/entry_state.dart index d868ef3..ed64e4f 100644 --- a/lib/src/rive_core/animation/entry_state.dart +++ b/lib/src/rive_core/animation/entry_state.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/generated/animation/entry_state_base.dart'; +import 'package:rive/src/rive_core/animation/state_instance.dart'; + export 'package:rive/src/generated/animation/entry_state_base.dart'; class EntryState extends EntryStateBase { diff --git a/lib/src/rive_core/animation/exit_state.dart b/lib/src/rive_core/animation/exit_state.dart index fabdec2..5e65ef7 100644 --- a/lib/src/rive_core/animation/exit_state.dart +++ b/lib/src/rive_core/animation/exit_state.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/generated/animation/exit_state_base.dart'; +import 'package:rive/src/rive_core/animation/state_instance.dart'; + export 'package:rive/src/generated/animation/exit_state_base.dart'; class ExitState extends ExitStateBase { diff --git a/lib/src/rive_core/animation/keyed_object.dart b/lib/src/rive_core/animation/keyed_object.dart index 5778cf7..87587c8 100644 --- a/lib/src/rive_core/animation/keyed_object.dart +++ b/lib/src/rive_core/animation/keyed_object.dart @@ -1,11 +1,11 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; -import 'package:rive/src/rive_core/animation/keyed_property.dart'; -import 'package:rive/src/rive_core/component.dart'; - import 'package:rive/src/generated/animation/keyed_object_base.dart'; +import 'package:rive/src/rive_core/animation/keyed_property.dart'; + import 'linear_animation.dart'; + export 'package:rive/src/generated/animation/keyed_object_base.dart'; class KeyedObject extends KeyedObjectBase { @@ -20,20 +20,6 @@ class KeyedObject extends KeyedObjectBase { @override void onAdded() {} - @override - bool validate() { - if (!super.validate()) { - return false; - } - - var component = context.resolve(objectId); - if (component == null) { - return false; - } - - return true; - } - @override void onRemoved() { super.onRemoved(); @@ -61,6 +47,7 @@ class KeyedObject extends KeyedObjectBase { return false; } _keyedProperties[property.propertyKey] = property; + return true; } @@ -75,6 +62,7 @@ class KeyedObject extends KeyedObjectBase { } // assert(removed == null || removed == property, // '$removed was not $property or null'); + return removed != null; } diff --git a/lib/src/rive_core/animation/keyed_property.dart b/lib/src/rive_core/animation/keyed_property.dart index 13e3f07..3c941cf 100644 --- a/lib/src/rive_core/animation/keyed_property.dart +++ b/lib/src/rive_core/animation/keyed_property.dart @@ -1,8 +1,8 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/keyed_property_base.dart'; import 'package:rive/src/rive_core/animation/keyed_object.dart'; import 'package:rive/src/rive_core/animation/keyframe.dart'; -import 'package:rive/src/generated/animation/keyed_property_base.dart'; export 'package:rive/src/generated/animation/keyed_property_base.dart'; abstract class KeyFrameInterface { @@ -11,7 +11,7 @@ abstract class KeyFrameInterface { class KeyFrameList { List _keyframes = []; - Iterable get keyframes => _keyframes; + List get keyframes => _keyframes; set keyframes(Iterable frames) => _keyframes = frames.toList(); /// Get the keyframe immediately following the provided one. diff --git a/lib/src/rive_core/animation/keyframe.dart b/lib/src/rive_core/animation/keyframe.dart index 9d82a62..f777eb4 100644 --- a/lib/src/rive_core/animation/keyframe.dart +++ b/lib/src/rive_core/animation/keyframe.dart @@ -1,11 +1,10 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/keyframe_base.dart'; import 'package:rive/src/rive_core/animation/interpolator.dart'; import 'package:rive/src/rive_core/animation/keyed_property.dart'; import 'package:rive/src/rive_core/animation/keyframe_interpolation.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; -import 'package:rive/src/generated/animation/keyframe_base.dart'; - export 'package:rive/src/generated/animation/keyframe_base.dart'; abstract class KeyFrame extends KeyFrameBase diff --git a/lib/src/rive_core/animation/layer_state.dart b/lib/src/rive_core/animation/layer_state.dart index 7f3a1fb..af59609 100644 --- a/lib/src/rive_core/animation/layer_state.dart +++ b/lib/src/rive_core/animation/layer_state.dart @@ -1,8 +1,9 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/layer_state_base.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/rive_core/animation/state_machine_layer.dart'; import 'package:rive/src/rive_core/animation/state_transition.dart'; -import 'package:rive/src/generated/animation/layer_state_base.dart'; + export 'package:rive/src/generated/animation/layer_state_base.dart'; abstract class LayerState extends LayerStateBase { diff --git a/lib/src/rive_core/animation/linear_animation.dart b/lib/src/rive_core/animation/linear_animation.dart index b774e5e..772b9fa 100644 --- a/lib/src/rive_core/animation/linear_animation.dart +++ b/lib/src/rive_core/animation/linear_animation.dart @@ -1,10 +1,11 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/linear_animation_base.dart'; import 'package:rive/src/rive_core/animation/keyed_object.dart'; import 'package:rive/src/rive_core/animation/loop.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/linear_animation_base.dart'; + export 'package:rive/src/generated/animation/linear_animation_base.dart'; class LinearAnimation extends LinearAnimationBase { @@ -78,6 +79,27 @@ class LinearAnimation extends LinearAnimationBase { @override void workStartChanged(int from, int to) {} + /// Returns the end time of the animation in seconds + double get endTime => (enableWorkArea ? workEnd : duration).toDouble() / fps; + + /// Returns the start time of the animation in seconds + double get startTime => (enableWorkArea ? workStart : 0).toDouble() / fps; + + /// Convert a global clock to local seconds (takes into consideration work + /// area start/end, speed, looping). + double globalToLocalTime(double seconds) { + switch (loop) { + case Loop.oneShot: + return seconds + startTime; + case Loop.loop: + return seconds % (endTime - startTime) + startTime; + case Loop.pingPong: + var localTime = seconds % (endTime - startTime); + var direction = (seconds ~/ (endTime - startTime)) % 2; + return direction == 0 ? localTime + startTime : endTime - localTime; + } + } + @override bool import(ImportStack stack) { var artboardImporter = stack.latest(ArtboardBase.typeKey); diff --git a/lib/src/rive_core/animation/linear_animation_instance.dart b/lib/src/rive_core/animation/linear_animation_instance.dart index 49201ce..8569a5e 100644 --- a/lib/src/rive_core/animation/linear_animation_instance.dart +++ b/lib/src/rive_core/animation/linear_animation_instance.dart @@ -1,9 +1,12 @@ +import 'package:rive/src/core/core.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/animation/loop.dart'; class LinearAnimationInstance { final LinearAnimation animation; + double _time = 0; + double _lastTime = 0; double _totalTime = 0; double _lastTotalTime = 0; int _direction = 1; @@ -18,7 +21,9 @@ class LinearAnimationInstance { LinearAnimationInstance(this.animation) : _time = (animation.enableWorkArea ? animation.workStart : 0).toDouble() / - animation.fps; + animation.fps { + _lastTime = _time; + } /// Note that when time is set, the direction will be changed to 1 set time(double value) { @@ -28,7 +33,7 @@ class LinearAnimationInstance { // Make sure to keep last and total in relative lockstep so state machines // can track change even when setting time. var diff = _totalTime - _lastTotalTime; - _time = _totalTime = value; + _lastTime = _time = _totalTime = value; _lastTotalTime = _totalTime - diff; _direction = 1; } @@ -36,39 +41,40 @@ class LinearAnimationInstance { /// Returns the current time position of the animation in seconds double get time => _time; + /// Returns the time the position was at when the previous advance was called. + double get lastTime => _lastTime; + /// Direction should only be +1 or -1 set direction(int value) => _direction = value == -1 ? -1 : 1; /// Returns the animation's play direction: 1 for forwards, -1 for backwards int get direction => _direction; - /// Returns the end time of the animation in seconds - double get endTime => - (animation.enableWorkArea ? animation.workEnd : animation.duration) - .toDouble() / - animation.fps; - - /// Returns the start time of the animation in seconds - double get startTime => - (animation.enableWorkArea ? animation.workStart : 0).toDouble() / - animation.fps; - - double get progress => (_time - startTime) / (endTime - startTime); + double get progress => + (_time - animation.startTime) / (animation.endTime - animation.startTime); /// Resets the animation to the starting frame - void reset() => _time = startTime; + void reset() => _time = animation.startTime; /// Whether the controller driving this animation should keep requesting /// frames be drawn. bool get keepGoing => animation.loop != Loop.oneShot || !_didLoop; + /// Apply the changes incurred during advance, also automatically fires any + /// accrued events. + void apply(CoreContext core, {double mix = 1}) { + animation.apply(time, coreContext: core, mix: mix); + } + bool advance(double elapsedSeconds) { var deltaSeconds = elapsedSeconds * animation.speed * _direction; _lastTotalTime = _totalTime; _totalTime += deltaSeconds; + _lastTime = _time; _time += deltaSeconds; double frames = _time * animation.fps; + var fps = animation.fps; var start = animation.enableWorkArea ? animation.workStart : 0; var end = animation.enableWorkArea ? animation.workEnd : animation.duration; @@ -82,18 +88,18 @@ class LinearAnimationInstance { case Loop.oneShot: if (frames > end) { keepGoing = false; - _spilledTime = (frames - end) / animation.fps; + _spilledTime = (frames - end) / fps; frames = end.toDouble(); - _time = frames / animation.fps; + _time = frames / fps; _didLoop = true; } break; case Loop.loop: if (frames >= end) { - _spilledTime = (frames - end) / animation.fps; - frames = _time * animation.fps; + _spilledTime = (frames - end) / fps; + frames = _time * fps; frames = start + (frames - start) % range; - _time = frames / animation.fps; + _time = frames / fps; _didLoop = true; } break; @@ -120,6 +126,7 @@ class LinearAnimationInstance { // advanced on regular intervals. break; } + _lastTime = _time; } break; } diff --git a/lib/src/rive_core/animation/nested_linear_animation.dart b/lib/src/rive_core/animation/nested_linear_animation.dart new file mode 100644 index 0000000..b5fdfe6 --- /dev/null +++ b/lib/src/rive_core/animation/nested_linear_animation.dart @@ -0,0 +1,51 @@ +import 'package:rive/src/generated/animation/nested_linear_animation_base.dart'; +import 'package:rive/src/rive_core/nested_artboard.dart'; + +export 'package:rive/src/generated/animation/nested_linear_animation_base.dart'; + +/// Need this abstraction to not depend on package:rive in rive_core. +// ignore: one_member_abstracts +abstract class NestedLinearAnimationInstance { + bool needsApply = true; + void goto(double value); + double get durationSeconds; + + double get speed; + set speed(double value); + + void advance(double elapsedSeconds); + void apply(covariant MountedArtboard artboard, double mix); +} + +abstract class NestedLinearAnimation extends NestedLinearAnimationBase { + NestedLinearAnimationInstance? _linearAnimationInstance; + NestedLinearAnimationInstance? get linearAnimationInstance => + _linearAnimationInstance; + set linearAnimationInstance(NestedLinearAnimationInstance? value) { + if (_linearAnimationInstance == value) { + return; + } + var from = _linearAnimationInstance; + _linearAnimationInstance = value; + linearAnimationInstanceChanged(from, value); + } + + void linearAnimationInstanceChanged( + NestedLinearAnimationInstance? from, NestedLinearAnimationInstance? to) {} + + @override + bool get isEnabled => true; + + @override + void mixChanged(double from, double to) { + linearAnimationInstance?.needsApply = true; + } + + @override + void advance(double elapsedSeconds, MountedArtboard mountedArtboard) { + if (linearAnimationInstance?.needsApply ?? false) { + linearAnimationInstance!.apply(mountedArtboard, mix); + linearAnimationInstance!.needsApply = false; + } + } +} diff --git a/lib/src/rive_core/animation/nested_remap_animation.dart b/lib/src/rive_core/animation/nested_remap_animation.dart new file mode 100644 index 0000000..c4e3e30 --- /dev/null +++ b/lib/src/rive_core/animation/nested_remap_animation.dart @@ -0,0 +1,24 @@ +import 'package:rive/src/generated/animation/nested_remap_animation_base.dart'; +import 'package:rive/src/rive_core/animation/nested_linear_animation.dart'; + +export 'package:rive/src/generated/animation/nested_remap_animation_base.dart'; + +class NestedRemapAnimation extends NestedRemapAnimationBase { + @override + void timeChanged(double from, double to) => syncTime(); + + void syncTime() { + if (linearAnimationInstance != null) { + linearAnimationInstance! + .goto(linearAnimationInstance!.durationSeconds * time); + } + } + + @override + void linearAnimationInstanceChanged(NestedLinearAnimationInstance? from, + NestedLinearAnimationInstance? to) => + syncTime(); + + @override + bool get isEnabled => true; +} diff --git a/lib/src/rive_core/animation/nested_simple_animation.dart b/lib/src/rive_core/animation/nested_simple_animation.dart new file mode 100644 index 0000000..b2f21d6 --- /dev/null +++ b/lib/src/rive_core/animation/nested_simple_animation.dart @@ -0,0 +1,32 @@ +import 'package:rive/src/generated/animation/nested_simple_animation_base.dart'; +import 'package:rive/src/rive_core/animation/nested_linear_animation.dart'; +import 'package:rive/src/rive_core/nested_artboard.dart'; + +export 'package:rive/src/generated/animation/nested_simple_animation_base.dart'; + +class NestedSimpleAnimation extends NestedSimpleAnimationBase { + @override + void isPlayingChanged(bool from, bool to) {} + + @override + void speedChanged(double from, double to) { + linearAnimationInstance?.speed = to; + } + + @override + void linearAnimationInstanceChanged( + NestedLinearAnimationInstance? from, NestedLinearAnimationInstance? to) { + to?.speed = speed; + } + + @override + bool get isEnabled => true; + + @override + void advance(double elapsedSeconds, MountedArtboard mountedArtboard) { + if (isPlaying) { + linearAnimationInstance?.advance(elapsedSeconds); + } + super.advance(elapsedSeconds, mountedArtboard); + } +} diff --git a/lib/src/rive_core/animation/nested_state_machine.dart b/lib/src/rive_core/animation/nested_state_machine.dart new file mode 100644 index 0000000..3bd6e19 --- /dev/null +++ b/lib/src/rive_core/animation/nested_state_machine.dart @@ -0,0 +1,14 @@ +import 'package:rive/src/generated/animation/nested_state_machine_base.dart'; +import 'package:rive/src/rive_core/nested_artboard.dart'; + +export 'package:rive/src/generated/animation/nested_state_machine_base.dart'; + +class NestedStateMachine extends NestedStateMachineBase { + @override + void advance(double elapsedSeconds, MountedArtboard mountedArtboard) { + // TODO: implement advance + } + + @override + bool get isEnabled => false; +} diff --git a/lib/src/rive_core/animation/state_machine.dart b/lib/src/rive_core/animation/state_machine.dart index 9fa71e4..208050b 100644 --- a/lib/src/rive_core/animation/state_machine.dart +++ b/lib/src/rive_core/animation/state_machine.dart @@ -1,8 +1,9 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/state_machine_base.dart'; import 'package:rive/src/rive_core/animation/state_machine_input.dart'; import 'package:rive/src/rive_core/animation/state_machine_layer.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/state_machine_base.dart'; + export 'package:rive/src/generated/animation/state_machine_base.dart'; class StateMachine extends StateMachineBase { diff --git a/lib/src/rive_core/animation/state_machine_component.dart b/lib/src/rive_core/animation/state_machine_component.dart index 7805db8..b8a909e 100644 --- a/lib/src/rive_core/animation/state_machine_component.dart +++ b/lib/src/rive_core/animation/state_machine_component.dart @@ -1,8 +1,8 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; -import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/generated/animation/state_machine_component_base.dart'; +import 'package:rive/src/rive_core/animation/state_machine.dart'; export 'package:rive/src/generated/animation/state_machine_component_base.dart'; diff --git a/lib/src/rive_core/animation/state_machine_input.dart b/lib/src/rive_core/animation/state_machine_input.dart index ef801d8..e25a051 100644 --- a/lib/src/rive_core/animation/state_machine_input.dart +++ b/lib/src/rive_core/animation/state_machine_input.dart @@ -1,8 +1,9 @@ import 'dart:collection'; +import 'package:rive/src/generated/animation/state_machine_input_base.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_component.dart'; -import 'package:rive/src/generated/animation/state_machine_input_base.dart'; + export 'package:rive/src/generated/animation/state_machine_input_base.dart'; abstract class StateMachineInput extends StateMachineInputBase { diff --git a/lib/src/rive_core/animation/state_machine_layer.dart b/lib/src/rive_core/animation/state_machine_layer.dart index c9f93b5..a4e0548 100644 --- a/lib/src/rive_core/animation/state_machine_layer.dart +++ b/lib/src/rive_core/animation/state_machine_layer.dart @@ -1,13 +1,14 @@ import 'dart:collection'; +import 'package:rive/src/generated/animation/any_state_base.dart'; +import 'package:rive/src/generated/animation/state_machine_layer_base.dart'; import 'package:rive/src/rive_core/animation/any_state.dart'; import 'package:rive/src/rive_core/animation/entry_state.dart'; import 'package:rive/src/rive_core/animation/exit_state.dart'; import 'package:rive/src/rive_core/animation/layer_state.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_component.dart'; -import 'package:rive/src/generated/animation/any_state_base.dart'; -import 'package:rive/src/generated/animation/state_machine_layer_base.dart'; + export 'package:rive/src/generated/animation/state_machine_layer_base.dart'; class StateMachineLayer extends StateMachineLayerBase { diff --git a/lib/src/rive_core/animation/state_transition.dart b/lib/src/rive_core/animation/state_transition.dart index 84775a7..13bfdff 100644 --- a/lib/src/rive_core/animation/state_transition.dart +++ b/lib/src/rive_core/animation/state_transition.dart @@ -1,6 +1,7 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/state_transition_base.dart'; import 'package:rive/src/rive_core/animation/animation_state.dart'; import 'package:rive/src/rive_core/animation/animation_state_instance.dart'; import 'package:rive/src/rive_core/animation/layer_state.dart'; @@ -10,8 +11,8 @@ import 'package:rive/src/rive_core/animation/loop.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/rive_core/animation/transition_condition.dart'; import 'package:rive/src/rive_core/animation/transition_trigger_condition.dart'; -import 'package:rive/src/generated/animation/state_transition_base.dart'; import 'package:rive/src/rive_core/state_transition_flags.dart'; + export 'package:rive/src/generated/animation/state_transition_base.dart'; enum AllowTransition { no, waitingForExit, yes } diff --git a/lib/src/rive_core/animation/transition_bool_condition.dart b/lib/src/rive_core/animation/transition_bool_condition.dart index 5e58c47..eeef836 100644 --- a/lib/src/rive_core/animation/transition_bool_condition.dart +++ b/lib/src/rive_core/animation/transition_bool_condition.dart @@ -1,7 +1,9 @@ import 'dart:collection'; + +import 'package:rive/src/generated/animation/transition_bool_condition_base.dart'; import 'package:rive/src/rive_core/animation/state_machine_bool.dart'; import 'package:rive/src/rive_core/animation/transition_condition.dart'; -import 'package:rive/src/generated/animation/transition_bool_condition_base.dart'; + export 'package:rive/src/generated/animation/transition_bool_condition_base.dart'; class TransitionBoolCondition extends TransitionBoolConditionBase { diff --git a/lib/src/rive_core/animation/transition_condition.dart b/lib/src/rive_core/animation/transition_condition.dart index 99bb49b..4902a2a 100644 --- a/lib/src/rive_core/animation/transition_condition.dart +++ b/lib/src/rive_core/animation/transition_condition.dart @@ -1,9 +1,9 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/transition_condition_base.dart'; import 'package:rive/src/rive_core/animation/state_machine_input.dart'; import 'package:rive/src/rive_core/animation/state_transition.dart'; -import 'package:rive/src/generated/animation/transition_condition_base.dart'; export 'package:rive/src/generated/animation/transition_condition_base.dart'; diff --git a/lib/src/rive_core/animation/transition_number_condition.dart b/lib/src/rive_core/animation/transition_number_condition.dart index c4cfa57..49a0a1c 100644 --- a/lib/src/rive_core/animation/transition_number_condition.dart +++ b/lib/src/rive_core/animation/transition_number_condition.dart @@ -1,8 +1,8 @@ import 'dart:collection'; +import 'package:rive/src/generated/animation/transition_number_condition_base.dart'; import 'package:rive/src/rive_core/animation/state_machine_number.dart'; import 'package:rive/src/rive_core/animation/transition_condition.dart'; -import 'package:rive/src/generated/animation/transition_number_condition_base.dart'; export 'package:rive/src/generated/animation/transition_number_condition_base.dart'; diff --git a/lib/src/rive_core/animation/transition_trigger_condition.dart b/lib/src/rive_core/animation/transition_trigger_condition.dart index 124a2e2..2a96349 100644 --- a/lib/src/rive_core/animation/transition_trigger_condition.dart +++ b/lib/src/rive_core/animation/transition_trigger_condition.dart @@ -1,7 +1,8 @@ import 'dart:collection'; -import 'package:rive/src/rive_core/animation/state_machine_trigger.dart'; import 'package:rive/src/generated/animation/transition_trigger_condition_base.dart'; +import 'package:rive/src/rive_core/animation/state_machine_trigger.dart'; + export 'package:rive/src/generated/animation/transition_trigger_condition_base.dart'; class TransitionTriggerCondition extends TransitionTriggerConditionBase { diff --git a/lib/src/rive_core/animation/transition_value_condition.dart b/lib/src/rive_core/animation/transition_value_condition.dart index 2a68b87..62ef412 100644 --- a/lib/src/rive_core/animation/transition_value_condition.dart +++ b/lib/src/rive_core/animation/transition_value_condition.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/animation/transition_condition.dart'; import 'package:rive/src/generated/animation/transition_value_condition_base.dart'; +import 'package:rive/src/rive_core/animation/transition_condition.dart'; + export 'package:rive/src/generated/animation/transition_value_condition_base.dart'; abstract class TransitionValueCondition extends TransitionValueConditionBase { diff --git a/lib/src/rive_core/artboard.dart b/lib/src/rive_core/artboard.dart index eb1f1fb..440b8ce 100644 --- a/lib/src/rive_core/artboard.dart +++ b/lib/src/rive_core/artboard.dart @@ -1,6 +1,7 @@ import 'dart:ui'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/artboard_base.dart'; import 'package:rive/src/rive_core/animation/animation.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; @@ -11,10 +12,10 @@ import 'package:rive/src/rive_core/draw_rules.dart'; import 'package:rive/src/rive_core/draw_target.dart'; import 'package:rive/src/rive_core/drawable.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; +import 'package:rive/src/rive_core/nested_artboard.dart'; import 'package:rive/src/rive_core/rive_animation_controller.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/artboard_base.dart'; import 'package:rive/src/utilities/dependency_sorter.dart'; export 'package:rive/src/generated/artboard_base.dart'; @@ -120,8 +121,10 @@ class Artboard extends ArtboardBase with ShapePaintContainer { return didUpdate; } + final Set _activeNestedArtboards = {}; + /// Update any dirty components in this artboard. - bool advance(double elapsedSeconds) { + bool advance(double elapsedSeconds, {bool nested = false}) { bool didUpdate = false; for (final controller in _animationControllers) { if (controller.isActive) { @@ -129,6 +132,14 @@ class Artboard extends ArtboardBase with ShapePaintContainer { didUpdate = true; } } + + if (nested) { + var active = _activeNestedArtboards.toList(growable: false); + for (final activeNestedArtboard in active) { + activeNestedArtboard.advance(elapsedSeconds); + } + } + if (updateComponents() || didUpdate) { return true; } @@ -216,12 +227,18 @@ class Artboard extends ArtboardBase with ShapePaintContainer { if (!_components.add(component)) { return; } + if (component is NestedArtboard) { + _activeNestedArtboards.add(component); + } } /// Remove a component from the artboard and its various tracked lists of /// components. void removeComponent(Component component) { _components.remove(component); + if (component is NestedArtboard) { + _activeNestedArtboards.remove(component); + } } /// Let the artboard know that the drawables need to be resorted before diff --git a/lib/src/rive_core/bones/bone.dart b/lib/src/rive_core/bones/bone.dart index a82fdca..828ac6e 100644 --- a/lib/src/rive_core/bones/bone.dart +++ b/lib/src/rive_core/bones/bone.dart @@ -1,7 +1,8 @@ +import 'package:rive/src/generated/bones/bone_base.dart'; import 'package:rive/src/rive_core/constraints/constraint.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/bones/bone_base.dart'; + export 'package:rive/src/generated/bones/bone_base.dart'; typedef bool BoneCallback(Bone bone); diff --git a/lib/src/rive_core/bones/cubic_weight.dart b/lib/src/rive_core/bones/cubic_weight.dart index 45a0ee0..7cf795c 100644 --- a/lib/src/rive_core/bones/cubic_weight.dart +++ b/lib/src/rive_core/bones/cubic_weight.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/generated/bones/cubic_weight_base.dart'; +import 'package:rive/src/rive_core/math/vec2d.dart'; + export 'package:rive/src/generated/bones/cubic_weight_base.dart'; class CubicWeight extends CubicWeightBase { diff --git a/lib/src/rive_core/bones/skin.dart b/lib/src/rive_core/bones/skin.dart index 266cb88..7f13afe 100644 --- a/lib/src/rive_core/bones/skin.dart +++ b/lib/src/rive_core/bones/skin.dart @@ -1,12 +1,12 @@ import 'dart:typed_data'; +import 'package:rive/src/generated/bones/skin_base.dart'; import 'package:rive/src/rive_core/bones/bone.dart'; import 'package:rive/src/rive_core/bones/skinnable.dart'; import 'package:rive/src/rive_core/bones/tendon.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; -import 'package:rive/src/generated/bones/skin_base.dart'; export 'package:rive/src/generated/bones/skin_base.dart'; diff --git a/lib/src/rive_core/bones/tendon.dart b/lib/src/rive_core/bones/tendon.dart index 84a3d14..71cd818 100644 --- a/lib/src/rive_core/bones/tendon.dart +++ b/lib/src/rive_core/bones/tendon.dart @@ -1,6 +1,7 @@ +import 'package:rive/src/generated/bones/tendon_base.dart'; import 'package:rive/src/rive_core/bones/skeletal_component.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; -import 'package:rive/src/generated/bones/tendon_base.dart'; + export 'package:rive/src/generated/bones/tendon_base.dart'; class Tendon extends TendonBase { diff --git a/lib/src/rive_core/bones/weight.dart b/lib/src/rive_core/bones/weight.dart index af4cb82..8151184 100644 --- a/lib/src/rive_core/bones/weight.dart +++ b/lib/src/rive_core/bones/weight.dart @@ -1,8 +1,9 @@ import 'dart:typed_data'; +import 'package:rive/src/generated/bones/weight_base.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/bones/weight_base.dart'; + export 'package:rive/src/generated/bones/weight_base.dart'; class Weight extends WeightBase { diff --git a/lib/src/rive_core/component.dart b/lib/src/rive_core/component.dart index b5c388a..2c131af 100644 --- a/lib/src/rive_core/component.dart +++ b/lib/src/rive_core/component.dart @@ -1,11 +1,11 @@ -import 'package:rive/src/core/core.dart'; import 'package:flutter/foundation.dart'; +import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/component_base.dart'; import 'package:rive/src/rive_core/artboard.dart'; import 'package:rive/src/rive_core/container_component.dart'; - -import 'package:rive/src/generated/component_base.dart'; import 'package:rive/src/utilities/dependency_sorter.dart'; import 'package:rive/src/utilities/tops.dart'; + export 'package:rive/src/generated/component_base.dart'; abstract class Component extends ComponentBase diff --git a/lib/src/rive_core/constraints/constraint.dart b/lib/src/rive_core/constraints/constraint.dart index 3286ec2..91ec534 100644 --- a/lib/src/rive_core/constraints/constraint.dart +++ b/lib/src/rive_core/constraints/constraint.dart @@ -1,8 +1,9 @@ +import 'package:rive/src/generated/constraints/constraint_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; -import 'package:rive/src/generated/constraints/constraint_base.dart'; import 'package:rive/src/rive_core/transform_component.dart'; import 'package:rive/src/rive_core/world_transform_component.dart'; + export 'package:rive/src/generated/constraints/constraint_base.dart'; /// A specialized [Component] which can be parented to any [TransformComponent] diff --git a/lib/src/rive_core/constraints/distance_constraint.dart b/lib/src/rive_core/constraints/distance_constraint.dart index c7d8984..6b75a1a 100644 --- a/lib/src/rive_core/constraints/distance_constraint.dart +++ b/lib/src/rive_core/constraints/distance_constraint.dart @@ -1,6 +1,7 @@ -import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/generated/constraints/distance_constraint_base.dart'; +import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/transform_component.dart'; + export 'package:rive/src/generated/constraints/distance_constraint_base.dart'; /// [DistanceConstraint]'s logical distancing method. diff --git a/lib/src/rive_core/constraints/ik_constraint.dart b/lib/src/rive_core/constraints/ik_constraint.dart index b7538f1..25c54f7 100644 --- a/lib/src/rive_core/constraints/ik_constraint.dart +++ b/lib/src/rive_core/constraints/ik_constraint.dart @@ -1,11 +1,13 @@ import 'dart:math'; + +import 'package:rive/src/generated/constraints/ik_constraint_base.dart'; import 'package:rive/src/rive_core/bones/bone.dart'; import 'package:rive/src/rive_core/constraints/constraint.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/transform_components.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/constraints/ik_constraint_base.dart'; import 'package:rive/src/rive_core/transform_component.dart'; + export 'package:rive/src/generated/constraints/ik_constraint_base.dart'; /// A constraint which rotates its constrained bone and the parentBoneCount diff --git a/lib/src/rive_core/constraints/rotation_constraint.dart b/lib/src/rive_core/constraints/rotation_constraint.dart index 220fec8..0b2b0e4 100644 --- a/lib/src/rive_core/constraints/rotation_constraint.dart +++ b/lib/src/rive_core/constraints/rotation_constraint.dart @@ -1,11 +1,12 @@ import 'dart:math'; +import 'package:rive/src/generated/constraints/rotation_constraint_base.dart'; import 'package:rive/src/rive_core/constraints/constraint.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/transform_components.dart'; -import 'package:rive/src/generated/constraints/rotation_constraint_base.dart'; import 'package:rive/src/rive_core/transform_component.dart'; import 'package:rive/src/rive_core/transform_space.dart'; + export 'package:rive/src/generated/constraints/rotation_constraint_base.dart'; /// A constraint copies the rotation from the target component to the diff --git a/lib/src/rive_core/constraints/scale_constraint.dart b/lib/src/rive_core/constraints/scale_constraint.dart index 35802b2..4d4107a 100644 --- a/lib/src/rive_core/constraints/scale_constraint.dart +++ b/lib/src/rive_core/constraints/scale_constraint.dart @@ -1,9 +1,10 @@ +import 'package:rive/src/generated/constraints/scale_constraint_base.dart'; import 'package:rive/src/rive_core/constraints/constraint.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/transform_components.dart'; -import 'package:rive/src/generated/constraints/scale_constraint_base.dart'; import 'package:rive/src/rive_core/transform_component.dart'; import 'package:rive/src/rive_core/transform_space.dart'; + export 'package:rive/src/generated/constraints/scale_constraint_base.dart'; /// A constraint copies the scale from the target component to the diff --git a/lib/src/rive_core/constraints/transform_constraint.dart b/lib/src/rive_core/constraints/transform_constraint.dart index 6449812..676b4d7 100644 --- a/lib/src/rive_core/constraints/transform_constraint.dart +++ b/lib/src/rive_core/constraints/transform_constraint.dart @@ -1,10 +1,11 @@ import 'dart:math'; +import 'package:rive/src/generated/constraints/transform_constraint_base.dart'; import 'package:rive/src/rive_core/constraints/constraint.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; -import 'package:rive/src/generated/constraints/transform_constraint_base.dart'; import 'package:rive/src/rive_core/transform_component.dart'; import 'package:rive/src/rive_core/transform_space.dart'; + export 'package:rive/src/generated/constraints/transform_constraint_base.dart'; /// A constraint copies the transform from the target component to the diff --git a/lib/src/rive_core/constraints/transform_space_constraint.dart b/lib/src/rive_core/constraints/transform_space_constraint.dart index bc74a44..b60a9e9 100644 --- a/lib/src/rive_core/constraints/transform_space_constraint.dart +++ b/lib/src/rive_core/constraints/transform_space_constraint.dart @@ -1,6 +1,7 @@ -import 'package:rive/src/rive_core/math/transform_components.dart'; import 'package:rive/src/generated/constraints/transform_space_constraint_base.dart'; +import 'package:rive/src/rive_core/math/transform_components.dart'; import 'package:rive/src/rive_core/transform_space.dart'; + export 'package:rive/src/generated/constraints/transform_space_constraint_base.dart'; abstract class TransformSpaceConstraint extends TransformSpaceConstraintBase { diff --git a/lib/src/rive_core/constraints/translation_constraint.dart b/lib/src/rive_core/constraints/translation_constraint.dart index ffde868..7573370 100644 --- a/lib/src/rive_core/constraints/translation_constraint.dart +++ b/lib/src/rive_core/constraints/translation_constraint.dart @@ -1,9 +1,10 @@ +import 'package:rive/src/generated/constraints/translation_constraint_base.dart'; import 'package:rive/src/rive_core/constraints/constraint.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/constraints/translation_constraint_base.dart'; import 'package:rive/src/rive_core/transform_component.dart'; import 'package:rive/src/rive_core/transform_space.dart'; + export 'package:rive/src/generated/constraints/translation_constraint_base.dart'; /// A constraint copies the translation from the target component to the diff --git a/lib/src/rive_core/container_component.dart b/lib/src/rive_core/container_component.dart index 1892e76..c3d2250 100644 --- a/lib/src/rive_core/container_component.dart +++ b/lib/src/rive_core/container_component.dart @@ -1,9 +1,9 @@ -import 'package:rive/src/core/core.dart'; import 'package:flutter/material.dart'; +import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/container_component_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/draw_rules.dart'; import 'package:rive/src/rive_core/drawable.dart'; -import 'package:rive/src/generated/container_component_base.dart'; typedef bool DescentCallback(Component component); diff --git a/lib/src/rive_core/draw_rules.dart b/lib/src/rive_core/draw_rules.dart index 58ef46d..407262d 100644 --- a/lib/src/rive_core/draw_rules.dart +++ b/lib/src/rive_core/draw_rules.dart @@ -1,7 +1,8 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/draw_rules_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/draw_target.dart'; -import 'package:rive/src/generated/draw_rules_base.dart'; + export 'package:rive/src/generated/draw_rules_base.dart'; class DrawRules extends DrawRulesBase { diff --git a/lib/src/rive_core/draw_target.dart b/lib/src/rive_core/draw_target.dart index 5e20c1b..945e5df 100644 --- a/lib/src/rive_core/draw_target.dart +++ b/lib/src/rive_core/draw_target.dart @@ -1,6 +1,6 @@ import 'package:rive/src/core/core.dart'; -import 'package:rive/src/rive_core/drawable.dart'; import 'package:rive/src/generated/draw_target_base.dart'; +import 'package:rive/src/rive_core/drawable.dart'; export 'package:rive/src/generated/draw_target_base.dart'; diff --git a/lib/src/rive_core/drawable.dart b/lib/src/rive_core/drawable.dart index 2f15f9f..d28c050 100644 --- a/lib/src/rive_core/drawable.dart +++ b/lib/src/rive_core/drawable.dart @@ -1,12 +1,13 @@ import 'dart:ui'; +import 'package:rive/src/generated/drawable_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/component_flags.dart'; import 'package:rive/src/rive_core/container_component.dart'; import 'package:rive/src/rive_core/draw_rules.dart'; import 'package:rive/src/rive_core/shapes/clipping_shape.dart'; -import 'package:rive/src/generated/drawable_base.dart'; import 'package:rive/src/rive_core/transform_component.dart'; + export 'package:rive/src/generated/drawable_base.dart'; abstract class Drawable extends DrawableBase { diff --git a/lib/src/rive_core/nested_animation.dart b/lib/src/rive_core/nested_animation.dart new file mode 100644 index 0000000..cca682d --- /dev/null +++ b/lib/src/rive_core/nested_animation.dart @@ -0,0 +1,33 @@ +import 'package:rive/src/generated/nested_animation_base.dart'; +import 'package:rive/src/rive_core/animation/animation.dart'; +import 'package:rive/src/rive_core/nested_artboard.dart'; + +export 'package:rive/src/generated/nested_animation_base.dart'; + +abstract class NestedAnimation + extends NestedAnimationBase { + NestedArtboard? get nestedArtboard => + parent is NestedArtboard ? parent as NestedArtboard : null; + + @override + void animationIdChanged(int from, int to) {} + + + bool get isEnabled; + void advance(double elapsedSeconds, MountedArtboard mountedArtboard); + + // @override + // bool import(ImportStack stack) { + // var backboardImporter = + // stack.latest(BackboardBase.typeKey); + // if (backboardImporter == null) { + // return false; + // } + // backboardImporter.addNestedArtboard(this); + + // return super.import(stack); + // } + + @override + void update(int dirt) {} +} diff --git a/lib/src/rive_core/nested_artboard.dart b/lib/src/rive_core/nested_artboard.dart index 564edc3..3b2233b 100644 --- a/lib/src/rive_core/nested_artboard.dart +++ b/lib/src/rive_core/nested_artboard.dart @@ -1,9 +1,16 @@ import 'dart:ui'; + import 'package:rive/src/core/core.dart'; -import 'package:rive/src/rive_core/backboard.dart'; -import 'package:rive/src/rive_core/component_dirt.dart'; -import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/generated/nested_artboard_base.dart'; +import 'package:rive/src/rive_core/animation/nested_remap_animation.dart'; +import 'package:rive/src/rive_core/animation/nested_simple_animation.dart'; +import 'package:rive/src/rive_core/backboard.dart'; +import 'package:rive/src/rive_core/component.dart'; +import 'package:rive/src/rive_core/component_dirt.dart'; +import 'package:rive/src/rive_core/math/aabb.dart'; +import 'package:rive/src/rive_core/math/mat2d.dart'; +import 'package:rive/src/rive_core/nested_animation.dart'; + export 'package:rive/src/generated/nested_artboard_base.dart'; /// Represents the nested Artboard that'll actually be mounted and placed into @@ -12,9 +19,14 @@ abstract class MountedArtboard { void draw(Canvas canvas); Mat2D get worldTransform; set worldTransform(Mat2D value); + AABB get bounds; } class NestedArtboard extends NestedArtboardBase { + /// [NestedAnimation]s applied to this [NestedArtboard]. + final List _animations = []; + Iterable get animations => _animations; + MountedArtboard? _mountedArtboard; MountedArtboard? get mountedArtboard => _mountedArtboard; set mountedArtboard(MountedArtboard? value) { @@ -30,12 +42,46 @@ class NestedArtboard extends NestedArtboardBase { void artboardIdChanged(int from, int to) {} + @override + void childAdded(Component child) { + super.childAdded(child); + switch (child.coreType) { + case NestedRemapAnimationBase.typeKey: + case NestedSimpleAnimationBase.typeKey: + _animations.add(child as NestedAnimation); + break; + } + } + + @override + void childRemoved(Component child) { + super.childRemoved(child); + switch (child.coreType) { + case NestedRemapAnimationBase.typeKey: + case NestedSimpleAnimationBase.typeKey: + _animations.remove(child as NestedAnimation); + + break; + } + } + @override void updateWorldTransform() { super.updateWorldTransform(); _mountedArtboard?.worldTransform = worldTransform; } + void advance(double elapsedSeconds) { + if (mountedArtboard == null) { + return; + } + for (final animation in _animations) { + if (animation.isEnabled) { + animation.advance(elapsedSeconds, mountedArtboard!); + } + } + } + @override void draw(Canvas canvas) => mountedArtboard?.draw(canvas); diff --git a/lib/src/rive_core/node.dart b/lib/src/rive_core/node.dart index 222e777..e16f95b 100644 --- a/lib/src/rive_core/node.dart +++ b/lib/src/rive_core/node.dart @@ -1,6 +1,7 @@ +import 'package:rive/src/generated/node_base.dart'; import 'package:rive/src/rive_core/math/aabb.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/node_base.dart'; + export 'package:rive/src/generated/node_base.dart'; class _UnknownNode extends Node {} diff --git a/lib/src/rive_core/shapes/clipping_shape.dart b/lib/src/rive_core/shapes/clipping_shape.dart index ef0da44..1b24fb2 100644 --- a/lib/src/rive_core/shapes/clipping_shape.dart +++ b/lib/src/rive_core/shapes/clipping_shape.dart @@ -1,9 +1,10 @@ import 'dart:ui'; +import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/node.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; -import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; + export 'package:rive/src/generated/shapes/clipping_shape_base.dart'; class ClippingShape extends ClippingShapeBase { diff --git a/lib/src/rive_core/shapes/cubic_asymmetric_vertex.dart b/lib/src/rive_core/shapes/cubic_asymmetric_vertex.dart index d90304a..a20ecea 100644 --- a/lib/src/rive_core/shapes/cubic_asymmetric_vertex.dart +++ b/lib/src/rive_core/shapes/cubic_asymmetric_vertex.dart @@ -1,9 +1,10 @@ import 'dart:math'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/shapes/cubic_asymmetric_vertex_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/cubic_asymmetric_vertex_base.dart'; + export 'package:rive/src/generated/shapes/cubic_asymmetric_vertex_base.dart'; class CubicAsymmetricVertex extends CubicAsymmetricVertexBase { diff --git a/lib/src/rive_core/shapes/cubic_detached_vertex.dart b/lib/src/rive_core/shapes/cubic_detached_vertex.dart index 8e8d4c0..48394a1 100644 --- a/lib/src/rive_core/shapes/cubic_detached_vertex.dart +++ b/lib/src/rive_core/shapes/cubic_detached_vertex.dart @@ -1,9 +1,10 @@ import 'dart:math'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/shapes/cubic_detached_vertex_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/cubic_detached_vertex_base.dart'; + export 'package:rive/src/generated/shapes/cubic_detached_vertex_base.dart'; class CubicDetachedVertex extends CubicDetachedVertexBase { diff --git a/lib/src/rive_core/shapes/cubic_mirrored_vertex.dart b/lib/src/rive_core/shapes/cubic_mirrored_vertex.dart index 31f5514..fb964ce 100644 --- a/lib/src/rive_core/shapes/cubic_mirrored_vertex.dart +++ b/lib/src/rive_core/shapes/cubic_mirrored_vertex.dart @@ -1,9 +1,10 @@ import 'dart:math'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/shapes/cubic_mirrored_vertex_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/cubic_mirrored_vertex_base.dart'; + export 'package:rive/src/generated/shapes/cubic_mirrored_vertex_base.dart'; class CubicMirroredVertex extends CubicMirroredVertexBase { diff --git a/lib/src/rive_core/shapes/cubic_vertex.dart b/lib/src/rive_core/shapes/cubic_vertex.dart index 25d1bb8..e00a74f 100644 --- a/lib/src/rive_core/shapes/cubic_vertex.dart +++ b/lib/src/rive_core/shapes/cubic_vertex.dart @@ -1,9 +1,10 @@ import 'dart:typed_data'; +import 'package:rive/src/generated/shapes/cubic_vertex_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/cubic_vertex_base.dart'; + export 'package:rive/src/generated/shapes/cubic_vertex_base.dart'; abstract class CubicVertex extends CubicVertexBase { diff --git a/lib/src/rive_core/shapes/ellipse.dart b/lib/src/rive_core/shapes/ellipse.dart index 3afdfc7..5febbb0 100644 --- a/lib/src/rive_core/shapes/ellipse.dart +++ b/lib/src/rive_core/shapes/ellipse.dart @@ -1,7 +1,7 @@ +import 'package:rive/src/generated/shapes/ellipse_base.dart'; import 'package:rive/src/rive_core/math/circle_constant.dart'; import 'package:rive/src/rive_core/shapes/cubic_detached_vertex.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; -import 'package:rive/src/generated/shapes/ellipse_base.dart'; export 'package:rive/src/generated/shapes/ellipse_base.dart'; diff --git a/lib/src/rive_core/shapes/paint/fill.dart b/lib/src/rive_core/shapes/paint/fill.dart index c65f581..00f3058 100644 --- a/lib/src/rive_core/shapes/paint/fill.dart +++ b/lib/src/rive_core/shapes/paint/fill.dart @@ -1,8 +1,9 @@ import 'dart:ui'; +import 'package:rive/src/generated/shapes/paint/fill_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/shapes/paint/fill_base.dart'; + export 'package:rive/src/generated/shapes/paint/fill_base.dart'; /// A fill Shape painter. diff --git a/lib/src/rive_core/shapes/paint/gradient_stop.dart b/lib/src/rive_core/shapes/paint/gradient_stop.dart index cec815c..1e6b1d5 100644 --- a/lib/src/rive_core/shapes/paint/gradient_stop.dart +++ b/lib/src/rive_core/shapes/paint/gradient_stop.dart @@ -1,8 +1,8 @@ import 'dart:ui' as ui; +import 'package:rive/src/generated/shapes/paint/gradient_stop_base.dart'; import 'package:rive/src/rive_core/container_component.dart'; import 'package:rive/src/rive_core/shapes/paint/linear_gradient.dart'; -import 'package:rive/src/generated/shapes/paint/gradient_stop_base.dart'; export 'package:rive/src/generated/shapes/paint/gradient_stop_base.dart'; diff --git a/lib/src/rive_core/shapes/paint/linear_gradient.dart b/lib/src/rive_core/shapes/paint/linear_gradient.dart index 6dea1f0..488409d 100644 --- a/lib/src/rive_core/shapes/paint/linear_gradient.dart +++ b/lib/src/rive_core/shapes/paint/linear_gradient.dart @@ -1,13 +1,14 @@ import 'dart:ui' as ui; import 'package:meta/meta.dart'; +import 'package:rive/src/generated/shapes/paint/linear_gradient_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/shapes/paint/gradient_stop.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; -import 'package:rive/src/generated/shapes/paint/linear_gradient_base.dart'; + export 'package:rive/src/generated/shapes/paint/linear_gradient_base.dart'; /// A core linear gradient. Can be added as a child to a [Shape]'s [Fill] or diff --git a/lib/src/rive_core/shapes/paint/shape_paint.dart b/lib/src/rive_core/shapes/paint/shape_paint.dart index 4c89b7a..b97a0b9 100644 --- a/lib/src/rive_core/shapes/paint/shape_paint.dart +++ b/lib/src/rive_core/shapes/paint/shape_paint.dart @@ -1,13 +1,14 @@ import 'dart:ui'; import 'package:meta/meta.dart'; +import 'package:rive/src/generated/shapes/paint/shape_paint_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/container_component.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/shapes/paint/shape_paint_base.dart'; + export 'package:rive/src/generated/shapes/paint/shape_paint_base.dart'; /// Generic ShapePaint that abstracts Stroke and Fill. Automatically hooks up diff --git a/lib/src/rive_core/shapes/paint/solid_color.dart b/lib/src/rive_core/shapes/paint/solid_color.dart index eb33afa..0bcd170 100644 --- a/lib/src/rive_core/shapes/paint/solid_color.dart +++ b/lib/src/rive_core/shapes/paint/solid_color.dart @@ -1,9 +1,10 @@ import 'dart:ui'; +import 'package:rive/src/generated/shapes/paint/solid_color_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; -import 'package:rive/src/generated/shapes/paint/solid_color_base.dart'; + export 'package:rive/src/generated/shapes/paint/solid_color_base.dart'; /// A solid color painter for a shape. Works for both Fill and Stroke. diff --git a/lib/src/rive_core/shapes/paint/stroke.dart b/lib/src/rive_core/shapes/paint/stroke.dart index 01b11a8..7e75869 100644 --- a/lib/src/rive_core/shapes/paint/stroke.dart +++ b/lib/src/rive_core/shapes/paint/stroke.dart @@ -1,9 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:rive/src/generated/shapes/paint/stroke_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/paint/stroke_effect.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/shapes/paint/stroke_base.dart'; + export 'package:rive/src/generated/shapes/paint/stroke_base.dart'; /// A stroke Shape painter. diff --git a/lib/src/rive_core/shapes/paint/trim_path.dart b/lib/src/rive_core/shapes/paint/trim_path.dart index a97115e..6a032ec 100644 --- a/lib/src/rive_core/shapes/paint/trim_path.dart +++ b/lib/src/rive_core/shapes/paint/trim_path.dart @@ -1,11 +1,11 @@ import 'dart:ui'; +import 'package:rive/src/generated/shapes/paint/trim_path_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/paint/stroke.dart'; import 'package:rive/src/rive_core/shapes/paint/stroke_effect.dart'; import 'package:rive/src/rive_core/shapes/paint/trim_path_drawing.dart'; -import 'package:rive/src/generated/shapes/paint/trim_path_base.dart'; export 'package:rive/src/generated/shapes/paint/trim_path_base.dart'; enum TrimPathMode { diff --git a/lib/src/rive_core/shapes/parametric_path.dart b/lib/src/rive_core/shapes/parametric_path.dart index 266e548..4cb0243 100644 --- a/lib/src/rive_core/shapes/parametric_path.dart +++ b/lib/src/rive_core/shapes/parametric_path.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/generated/shapes/parametric_path_base.dart'; +import 'package:rive/src/rive_core/math/mat2d.dart'; + export 'package:rive/src/generated/shapes/parametric_path_base.dart'; abstract class ParametricPath extends ParametricPathBase { diff --git a/lib/src/rive_core/shapes/path.dart b/lib/src/rive_core/shapes/path.dart index 26bfe2f..92e3f03 100644 --- a/lib/src/rive_core/shapes/path.dart +++ b/lib/src/rive_core/shapes/path.dart @@ -1,6 +1,7 @@ import 'dart:math'; import 'dart:ui' as ui; +import 'package:rive/src/generated/shapes/path_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/component_flags.dart'; @@ -11,7 +12,7 @@ import 'package:rive/src/rive_core/shapes/cubic_vertex.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/path_base.dart'; + export 'package:rive/src/generated/shapes/path_base.dart'; /// An abstract low level path that gets implemented by parametric and point diff --git a/lib/src/rive_core/shapes/path_vertex.dart b/lib/src/rive_core/shapes/path_vertex.dart index d2e9508..02de297 100644 --- a/lib/src/rive_core/shapes/path_vertex.dart +++ b/lib/src/rive_core/shapes/path_vertex.dart @@ -1,11 +1,12 @@ import 'dart:typed_data'; +import 'package:rive/src/generated/shapes/path_vertex_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/shapes/path.dart'; -import 'package:rive/src/generated/shapes/path_vertex_base.dart'; + export 'package:rive/src/generated/shapes/path_vertex_base.dart'; abstract class PathVertex extends PathVertexBase { diff --git a/lib/src/rive_core/shapes/points_path.dart b/lib/src/rive_core/shapes/points_path.dart index be58fde..f8cf887 100644 --- a/lib/src/rive_core/shapes/points_path.dart +++ b/lib/src/rive_core/shapes/points_path.dart @@ -1,9 +1,9 @@ +import 'package:rive/src/generated/shapes/points_path_base.dart'; import 'package:rive/src/rive_core/bones/skinnable.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; -import 'package:rive/src/generated/shapes/points_path_base.dart'; export 'package:rive/src/generated/shapes/points_path_base.dart'; diff --git a/lib/src/rive_core/shapes/polygon.dart b/lib/src/rive_core/shapes/polygon.dart index de17e4f..9c44226 100644 --- a/lib/src/rive_core/shapes/polygon.dart +++ b/lib/src/rive_core/shapes/polygon.dart @@ -1,9 +1,9 @@ import 'dart:math'; +import 'package:rive/src/generated/shapes/polygon_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/polygon_base.dart'; export 'package:rive/src/generated/shapes/polygon_base.dart'; diff --git a/lib/src/rive_core/shapes/rectangle.dart b/lib/src/rive_core/shapes/rectangle.dart index b72149c..a827042 100644 --- a/lib/src/rive_core/shapes/rectangle.dart +++ b/lib/src/rive_core/shapes/rectangle.dart @@ -1,6 +1,7 @@ +import 'package:rive/src/generated/shapes/rectangle_base.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/rectangle_base.dart'; + export 'package:rive/src/generated/shapes/rectangle_base.dart'; class Rectangle extends RectangleBase { diff --git a/lib/src/rive_core/shapes/shape.dart b/lib/src/rive_core/shapes/shape.dart index ec3d9b0..8c4df11 100644 --- a/lib/src/rive_core/shapes/shape.dart +++ b/lib/src/rive_core/shapes/shape.dart @@ -1,6 +1,7 @@ import 'dart:ui' as ui; import 'package:collection/collection.dart'; +import 'package:rive/src/generated/shapes/shape_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/paint/linear_gradient.dart' as core; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; @@ -8,7 +9,6 @@ import 'package:rive/src/rive_core/shapes/paint/stroke.dart'; import 'package:rive/src/rive_core/shapes/path.dart'; import 'package:rive/src/rive_core/shapes/path_composer.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/shapes/shape_base.dart'; export 'package:rive/src/generated/shapes/shape_base.dart'; diff --git a/lib/src/rive_core/shapes/star.dart b/lib/src/rive_core/shapes/star.dart index 7c69c1d..accf691 100644 --- a/lib/src/rive_core/shapes/star.dart +++ b/lib/src/rive_core/shapes/star.dart @@ -1,9 +1,10 @@ import 'dart:math'; +import 'package:rive/src/generated/shapes/star_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/star_base.dart'; + export 'package:rive/src/generated/shapes/star_base.dart'; class Star extends StarBase { diff --git a/lib/src/rive_core/shapes/straight_vertex.dart b/lib/src/rive_core/shapes/straight_vertex.dart index 55a130f..c41d40e 100644 --- a/lib/src/rive_core/shapes/straight_vertex.dart +++ b/lib/src/rive_core/shapes/straight_vertex.dart @@ -1,8 +1,9 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/shapes/straight_vertex_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/straight_vertex_base.dart'; + export 'package:rive/src/generated/shapes/straight_vertex_base.dart'; class StraightVertex extends StraightVertexBase { diff --git a/lib/src/rive_core/shapes/triangle.dart b/lib/src/rive_core/shapes/triangle.dart index b218f63..7b21422 100644 --- a/lib/src/rive_core/shapes/triangle.dart +++ b/lib/src/rive_core/shapes/triangle.dart @@ -1,6 +1,6 @@ +import 'package:rive/src/generated/shapes/triangle_base.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/triangle_base.dart'; /// Export the Base class for external use (e.g. rive.dart) export 'package:rive/src/generated/shapes/triangle_base.dart'; diff --git a/lib/src/rive_core/state_machine_controller.dart b/lib/src/rive_core/state_machine_controller.dart index e5ed34a..2cd63b4 100644 --- a/lib/src/rive_core/state_machine_controller.dart +++ b/lib/src/rive_core/state_machine_controller.dart @@ -1,8 +1,8 @@ import 'dart:collection'; -import 'package:rive/src/core/core.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/scheduler.dart'; +import 'package:rive/src/core/core.dart'; import 'package:rive/src/rive_core/animation/animation_state.dart'; import 'package:rive/src/rive_core/animation/animation_state_instance.dart'; import 'package:rive/src/rive_core/animation/any_state.dart'; @@ -25,6 +25,7 @@ typedef OnLayerStateChange = void Function(LayerState); class LayerController { final StateMachineLayer layer; final StateInstance anyStateInstance; + final CoreContext core; StateInstance? _currentState; StateInstance? _stateFrom; @@ -37,8 +38,11 @@ class LayerController { /// Takes the state machine name and state name final OnLayerStateChange? onLayerStateChange; - LayerController(this.layer, {this.onLayerStateChange}) - : assert(layer.anyState != null), + LayerController( + this.layer, { + required this.core, + this.onLayerStateChange, + }) : assert(layer.anyState != null), anyStateInstance = layer.anyState!.makeInstance() { _changeState(layer.entryState); } @@ -237,6 +241,7 @@ class StateMachineController extends RiveAnimationController { for (final layer in stateMachine.layers) { layerControllers.add(LayerController( layer, + core: core, onLayerStateChange: _onStateChange, )); } diff --git a/lib/src/rive_core/transform_component.dart b/lib/src/rive_core/transform_component.dart index 31e1ee8..a9aa9b1 100644 --- a/lib/src/rive_core/transform_component.dart +++ b/lib/src/rive_core/transform_component.dart @@ -1,4 +1,6 @@ import 'package:flutter/foundation.dart'; +import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; +import 'package:rive/src/generated/transform_component_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/constraints/constraint.dart'; @@ -13,11 +15,10 @@ import 'package:rive/src/rive_core/drawable.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/shapes/clipping_shape.dart'; -import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; -import 'package:rive/src/generated/transform_component_base.dart'; import 'package:rive/src/rive_core/world_transform_component.dart'; import 'constraints/distance_constraint.dart'; + export 'package:rive/src/generated/transform_component_base.dart'; abstract class TransformComponent extends TransformComponentBase { diff --git a/lib/src/rive_core/world_transform_component.dart b/lib/src/rive_core/world_transform_component.dart index 5f862ee..3644d58 100644 --- a/lib/src/rive_core/world_transform_component.dart +++ b/lib/src/rive_core/world_transform_component.dart @@ -1,6 +1,7 @@ +import 'package:rive/src/generated/world_transform_component_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; -import 'package:rive/src/generated/world_transform_component_base.dart'; + export 'package:rive/src/generated/world_transform_component_base.dart'; /// A Component with world transform. diff --git a/lib/src/runtime_nested_artboard.dart b/lib/src/runtime_nested_artboard.dart index 81922c3..4202bc7 100644 --- a/lib/src/runtime_nested_artboard.dart +++ b/lib/src/runtime_nested_artboard.dart @@ -1,6 +1,9 @@ import 'package:flutter/rendering.dart'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/rive_core/animation/linear_animation_instance.dart'; +import 'package:rive/src/rive_core/animation/nested_linear_animation.dart'; import 'package:rive/src/rive_core/artboard.dart'; +import 'package:rive/src/rive_core/math/aabb.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/nested_artboard.dart'; @@ -12,16 +15,74 @@ class RuntimeNestedArtboard extends NestedArtboard { object.copy(this); if (sourceArtboard != null) { object.sourceArtboard = sourceArtboard; - object.mountedArtboard = - RuntimeMountedArtboard(sourceArtboard!.instance()); + var runtimeArtboardInstance = + sourceArtboard!.instance() as RuntimeArtboard; + object.mountedArtboard = RuntimeMountedArtboard(runtimeArtboardInstance); } return object as K; } + + @override + void onAdded() { + super.onAdded(); + if (mountedArtboard is! RuntimeMountedArtboard || + sourceArtboard == null || + animations.isEmpty) { + return; + } + var runtimeLinearAnimations = + sourceArtboard!.linearAnimations.toList(growable: false); + for (final animation in animations) { + if (animation is NestedLinearAnimation) { + var animationId = animation.animationId; + if (animationId >= 0 && animationId < runtimeLinearAnimations.length) { + animation.linearAnimationInstance = + RuntimeNestedLinearAnimationInstance(LinearAnimationInstance( + runtimeLinearAnimations[animationId])); + } + } + } + } +} + +class RuntimeNestedLinearAnimationInstance + extends NestedLinearAnimationInstance { + final LinearAnimationInstance linearAnimation; + + RuntimeNestedLinearAnimationInstance(this.linearAnimation); + + @override + void apply(RuntimeMountedArtboard artboard, double mix) { + linearAnimation.animation.apply(linearAnimation.time, + coreContext: artboard.artboardInstance, mix: mix); + } + + @override + void advance(double elapsedSeconds) { + needsApply = true; + linearAnimation.advance(elapsedSeconds * speed); + } + + @override + double speed = 1; + + @override + void goto(double value) { + var localTime = linearAnimation.animation.globalToLocalTime(value); + if (localTime == linearAnimation.time) { + return; + } + needsApply = true; + linearAnimation.time = localTime; + } + + @override + double get durationSeconds => linearAnimation.animation.durationSeconds; } class RuntimeMountedArtboard extends MountedArtboard { - final Artboard artboardInstance; + final RuntimeArtboard artboardInstance; RuntimeMountedArtboard(this.artboardInstance); @override @@ -37,4 +98,14 @@ class RuntimeMountedArtboard extends MountedArtboard { artboardInstance.draw(canvas); canvas.restore(); } + + @override + AABB get bounds { + var width = artboardInstance.width; + + var height = artboardInstance.height; + var x = -artboardInstance.originX * width; + var y = -artboardInstance.originY * height; + return AABB.fromValues(x, y, x + width, y + height); + } } diff --git a/test/linear_animation_instance_test.dart b/test/linear_animation_instance_test.dart index 228e099..d3dded8 100644 --- a/test/linear_animation_instance_test.dart +++ b/test/linear_animation_instance_test.dart @@ -33,8 +33,8 @@ void main() { LinearAnimationInstance instance = LinearAnimationInstance(artboard.animations.first as LinearAnimation); - final startTime = instance.startTime; - final endTime = instance.endTime; + final startTime = instance.animation.startTime; + final endTime = instance.animation.endTime; expect(startTime <= endTime, isTrue); expect(instance.direction, 1); // Advance the animation to the mid point @@ -54,15 +54,15 @@ void main() { LinearAnimationInstance(artboard.animations.first as LinearAnimation); // Check the starting position - expect(instance.startTime < instance.endTime, isTrue); - expect(instance.startTime, instance.time); + expect(instance.animation.startTime < instance.animation.endTime, isTrue); + expect(instance.animation.startTime, instance.time); // Advance - instance.advance(instance.endTime); - expect(instance.time, instance.endTime); + instance.advance(instance.animation.endTime); + expect(instance.time, instance.animation.endTime); // Reset instance.reset(); - expect(instance.time, instance.startTime); + expect(instance.time, instance.animation.startTime); }); }