From 6e97a2c076d43384121ac254321e5247514a6eee Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Thu, 16 Jun 2022 15:46:46 -0700 Subject: [PATCH] Support for nested inputs. --- lib/src/core/core.dart | 1 + .../nested_state_machine_importer.dart | 21 ++++++++ .../generated/animation/nested_bool_base.dart | 44 +++++++++++++++++ .../animation/nested_input_base.dart | 43 ++++++++++++++++ .../nested_linear_animation_base.dart | 2 + .../animation/nested_number_base.dart | 47 ++++++++++++++++++ .../nested_remap_animation_base.dart | 2 + .../nested_simple_animation_base.dart | 2 + .../animation/nested_state_machine_base.dart | 2 + .../animation/nested_trigger_base.dart | 18 +++++++ lib/src/generated/nested_animation_base.dart | 13 +++-- lib/src/generated/rive_core_context.dart | 49 +++++++++++++++++++ lib/src/rive_core/animation/nested_bool.dart | 10 ++++ lib/src/rive_core/animation/nested_input.dart | 32 ++++++++++++ .../rive_core/animation/nested_number.dart | 10 ++++ .../animation/nested_state_machine.dart | 9 ++++ .../rive_core/animation/nested_trigger.dart | 7 +++ lib/src/rive_core/assets/asset.dart | 4 +- lib/src/rive_core/assets/drawable_asset.dart | 4 +- lib/src/rive_core/assets/image_asset.dart | 3 +- lib/src/rive_core/transform_component.dart | 11 +++++ lib/src/rive_file.dart | 5 ++ lib/src/runtime_nested_artboard.dart | 8 +++ 23 files changed, 337 insertions(+), 10 deletions(-) create mode 100644 lib/src/core/importers/nested_state_machine_importer.dart create mode 100644 lib/src/generated/animation/nested_bool_base.dart create mode 100644 lib/src/generated/animation/nested_input_base.dart create mode 100644 lib/src/generated/animation/nested_number_base.dart create mode 100644 lib/src/generated/animation/nested_trigger_base.dart create mode 100644 lib/src/rive_core/animation/nested_bool.dart create mode 100644 lib/src/rive_core/animation/nested_input.dart create mode 100644 lib/src/rive_core/animation/nested_number.dart create mode 100644 lib/src/rive_core/animation/nested_trigger.dart diff --git a/lib/src/core/core.dart b/lib/src/core/core.dart index 6fa2bd7..b10505c 100644 --- a/lib/src/core/core.dart +++ b/lib/src/core/core.dart @@ -17,6 +17,7 @@ export 'package:rive/src/core/importers/keyed_object_importer.dart'; export 'package:rive/src/core/importers/keyed_property_importer.dart'; export 'package:rive/src/core/importers/layer_state_importer.dart'; export 'package:rive/src/core/importers/linear_animation_importer.dart'; +export 'package:rive/src/core/importers/nested_state_machine_importer.dart'; export 'package:rive/src/core/importers/state_machine_importer.dart'; export 'package:rive/src/core/importers/state_machine_layer_importer.dart'; export 'package:rive/src/core/importers/state_machine_listener_importer.dart'; diff --git a/lib/src/core/importers/nested_state_machine_importer.dart b/lib/src/core/importers/nested_state_machine_importer.dart new file mode 100644 index 0000000..01fcd44 --- /dev/null +++ b/lib/src/core/importers/nested_state_machine_importer.dart @@ -0,0 +1,21 @@ +import 'package:rive/src/core/importers/artboard_import_stack_object.dart'; +import 'package:rive/src/rive_core/animation/nested_input.dart'; +import 'package:rive/src/rive_core/animation/nested_state_machine.dart'; + +class NestedStateMachineImporter extends ArtboardImportStackObject { + final NestedStateMachine stateMachine; + NestedStateMachineImporter(this.stateMachine); + + final List _inputs = []; + void addNestedInput(NestedInput nestedInput) { + _inputs.add(nestedInput); + } + + @override + bool resolve() { + for (final input in _inputs) { + input.parent = stateMachine; + } + return super.resolve(); + } +} diff --git a/lib/src/generated/animation/nested_bool_base.dart b/lib/src/generated/animation/nested_bool_base.dart new file mode 100644 index 0000000..2ba132d --- /dev/null +++ b/lib/src/generated/animation/nested_bool_base.dart @@ -0,0 +1,44 @@ +/// Core automatically generated +/// lib/src/generated/animation/nested_bool_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/rive_core/animation/nested_input.dart'; + +abstract class NestedBoolBase extends NestedInput { + static const int typeKey = 123; + @override + int get coreType => NestedBoolBase.typeKey; + @override + Set get coreTypes => + {NestedBoolBase.typeKey, NestedInputBase.typeKey, ComponentBase.typeKey}; + + /// -------------------------------------------------------------------------- + /// NestedValue field with key 238. + static const bool nestedValueInitialValue = false; + bool _nestedValue = nestedValueInitialValue; + static const int nestedValuePropertyKey = 238; + bool get nestedValue => _nestedValue; + + /// Change the [_nestedValue] field value. + /// [nestedValueChanged] will be invoked only if the field's value has + /// changed. + set nestedValue(bool value) { + if (_nestedValue == value) { + return; + } + bool from = _nestedValue; + _nestedValue = value; + if (hasValidated) { + nestedValueChanged(from, value); + } + } + + void nestedValueChanged(bool from, bool to); + + @override + void copy(covariant NestedBoolBase source) { + super.copy(source); + _nestedValue = source._nestedValue; + } +} diff --git a/lib/src/generated/animation/nested_input_base.dart b/lib/src/generated/animation/nested_input_base.dart new file mode 100644 index 0000000..3b594c5 --- /dev/null +++ b/lib/src/generated/animation/nested_input_base.dart @@ -0,0 +1,43 @@ +/// Core automatically generated +/// lib/src/generated/animation/nested_input_base.dart. +/// Do not modify manually. + +import 'package:rive/src/rive_core/component.dart'; + +abstract class NestedInputBase extends Component { + static const int typeKey = 121; + @override + int get coreType => NestedInputBase.typeKey; + @override + Set get coreTypes => {NestedInputBase.typeKey, ComponentBase.typeKey}; + + /// -------------------------------------------------------------------------- + /// InputId field with key 237. + static const int inputIdInitialValue = -1; + int _inputId = inputIdInitialValue; + static const int inputIdPropertyKey = 237; + + /// Identifier used to track the actual backing state machine input. + int get inputId => _inputId; + + /// Change the [_inputId] field value. + /// [inputIdChanged] will be invoked only if the field's value has changed. + set inputId(int value) { + if (_inputId == value) { + return; + } + int from = _inputId; + _inputId = value; + if (hasValidated) { + inputIdChanged(from, value); + } + } + + void inputIdChanged(int from, int to); + + @override + void copy(covariant NestedInputBase source) { + super.copy(source); + _inputId = source._inputId; + } +} diff --git a/lib/src/generated/animation/nested_linear_animation_base.dart b/lib/src/generated/animation/nested_linear_animation_base.dart index 3bf7247..9831021 100644 --- a/lib/src/generated/animation/nested_linear_animation_base.dart +++ b/lib/src/generated/animation/nested_linear_animation_base.dart @@ -3,6 +3,7 @@ /// Do not modify manually. import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/container_component_base.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/nested_animation.dart'; @@ -15,6 +16,7 @@ abstract class NestedLinearAnimationBase Set get coreTypes => { NestedLinearAnimationBase.typeKey, NestedAnimationBase.typeKey, + ContainerComponentBase.typeKey, ComponentBase.typeKey }; diff --git a/lib/src/generated/animation/nested_number_base.dart b/lib/src/generated/animation/nested_number_base.dart new file mode 100644 index 0000000..72d77bd --- /dev/null +++ b/lib/src/generated/animation/nested_number_base.dart @@ -0,0 +1,47 @@ +/// Core automatically generated +/// lib/src/generated/animation/nested_number_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/rive_core/animation/nested_input.dart'; + +abstract class NestedNumberBase extends NestedInput { + static const int typeKey = 124; + @override + int get coreType => NestedNumberBase.typeKey; + @override + Set get coreTypes => { + NestedNumberBase.typeKey, + NestedInputBase.typeKey, + ComponentBase.typeKey + }; + + /// -------------------------------------------------------------------------- + /// NestedValue field with key 239. + static const double nestedValueInitialValue = 0; + double _nestedValue = nestedValueInitialValue; + static const int nestedValuePropertyKey = 239; + double get nestedValue => _nestedValue; + + /// Change the [_nestedValue] field value. + /// [nestedValueChanged] will be invoked only if the field's value has + /// changed. + set nestedValue(double value) { + if (_nestedValue == value) { + return; + } + double from = _nestedValue; + _nestedValue = value; + if (hasValidated) { + nestedValueChanged(from, value); + } + } + + void nestedValueChanged(double from, double to); + + @override + void copy(covariant NestedNumberBase source) { + super.copy(source); + _nestedValue = source._nestedValue; + } +} diff --git a/lib/src/generated/animation/nested_remap_animation_base.dart b/lib/src/generated/animation/nested_remap_animation_base.dart index 841a0b7..bde3809 100644 --- a/lib/src/generated/animation/nested_remap_animation_base.dart +++ b/lib/src/generated/animation/nested_remap_animation_base.dart @@ -3,6 +3,7 @@ /// Do not modify manually. import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/container_component_base.dart'; import 'package:rive/src/generated/nested_animation_base.dart'; import 'package:rive/src/rive_core/animation/nested_linear_animation.dart'; @@ -15,6 +16,7 @@ abstract class NestedRemapAnimationBase extends NestedLinearAnimation { NestedRemapAnimationBase.typeKey, NestedLinearAnimationBase.typeKey, NestedAnimationBase.typeKey, + ContainerComponentBase.typeKey, ComponentBase.typeKey }; diff --git a/lib/src/generated/animation/nested_simple_animation_base.dart b/lib/src/generated/animation/nested_simple_animation_base.dart index 8788067..9a187d8 100644 --- a/lib/src/generated/animation/nested_simple_animation_base.dart +++ b/lib/src/generated/animation/nested_simple_animation_base.dart @@ -3,6 +3,7 @@ /// Do not modify manually. import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/container_component_base.dart'; import 'package:rive/src/generated/nested_animation_base.dart'; import 'package:rive/src/rive_core/animation/nested_linear_animation.dart'; @@ -15,6 +16,7 @@ abstract class NestedSimpleAnimationBase extends NestedLinearAnimation { NestedSimpleAnimationBase.typeKey, NestedLinearAnimationBase.typeKey, NestedAnimationBase.typeKey, + ContainerComponentBase.typeKey, ComponentBase.typeKey }; diff --git a/lib/src/generated/animation/nested_state_machine_base.dart b/lib/src/generated/animation/nested_state_machine_base.dart index a9da9ee..4ae9fa1 100644 --- a/lib/src/generated/animation/nested_state_machine_base.dart +++ b/lib/src/generated/animation/nested_state_machine_base.dart @@ -3,6 +3,7 @@ /// Do not modify manually. import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/container_component_base.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/nested_animation.dart'; @@ -14,6 +15,7 @@ abstract class NestedStateMachineBase extends NestedAnimation { Set get coreTypes => { NestedStateMachineBase.typeKey, NestedAnimationBase.typeKey, + ContainerComponentBase.typeKey, ComponentBase.typeKey }; } diff --git a/lib/src/generated/animation/nested_trigger_base.dart b/lib/src/generated/animation/nested_trigger_base.dart new file mode 100644 index 0000000..c869389 --- /dev/null +++ b/lib/src/generated/animation/nested_trigger_base.dart @@ -0,0 +1,18 @@ +/// Core automatically generated +/// lib/src/generated/animation/nested_trigger_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/rive_core/animation/nested_input.dart'; + +abstract class NestedTriggerBase extends NestedInput { + static const int typeKey = 122; + @override + int get coreType => NestedTriggerBase.typeKey; + @override + Set get coreTypes => { + NestedTriggerBase.typeKey, + NestedInputBase.typeKey, + ComponentBase.typeKey + }; +} diff --git a/lib/src/generated/nested_animation_base.dart b/lib/src/generated/nested_animation_base.dart index 63bcb4e..6900655 100644 --- a/lib/src/generated/nested_animation_base.dart +++ b/lib/src/generated/nested_animation_base.dart @@ -1,15 +1,20 @@ /// Core automatically generated lib/src/generated/nested_animation_base.dart. /// Do not modify manually. -import 'package:rive/src/rive_core/component.dart'; +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/container_component_base.dart'; +import 'package:rive/src/rive_core/container_component.dart'; -abstract class NestedAnimationBase extends Component { +abstract class NestedAnimationBase extends ContainerComponent { static const int typeKey = 93; @override int get coreType => NestedAnimationBase.typeKey; @override - Set get coreTypes => - {NestedAnimationBase.typeKey, ComponentBase.typeKey}; + Set get coreTypes => { + NestedAnimationBase.typeKey, + ContainerComponentBase.typeKey, + ComponentBase.typeKey + }; /// -------------------------------------------------------------------------- /// AnimationId field with key 198. diff --git a/lib/src/generated/rive_core_context.dart b/lib/src/generated/rive_core_context.dart index d886d59..9d2eb18 100644 --- a/lib/src/generated/rive_core_context.dart +++ b/lib/src/generated/rive_core_context.dart @@ -10,6 +10,7 @@ import 'package:rive/src/generated/animation/blend_animation_base.dart'; import 'package:rive/src/generated/animation/cubic_interpolator_base.dart'; import 'package:rive/src/generated/animation/keyframe_base.dart'; import 'package:rive/src/generated/animation/listener_input_change_base.dart'; +import 'package:rive/src/generated/animation/nested_input_base.dart'; import 'package:rive/src/generated/animation/nested_linear_animation_base.dart'; import 'package:rive/src/generated/animation/state_machine_component_base.dart'; import 'package:rive/src/generated/animation/transition_condition_base.dart'; @@ -52,9 +53,12 @@ import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/animation/listener_bool_change.dart'; import 'package:rive/src/rive_core/animation/listener_number_change.dart'; import 'package:rive/src/rive_core/animation/listener_trigger_change.dart'; +import 'package:rive/src/rive_core/animation/nested_bool.dart'; +import 'package:rive/src/rive_core/animation/nested_number.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/nested_trigger.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'; @@ -140,6 +144,8 @@ class RiveCoreContext { return NestedSimpleAnimation(); case AnimationStateBase.typeKey: return AnimationState(); + case NestedTriggerBase.typeKey: + return NestedTrigger(); case KeyedObjectBase.typeKey: return KeyedObject(); case BlendAnimationDirectBase.typeKey: @@ -170,6 +176,8 @@ class RiveCoreContext { return CubicInterpolator(); case StateTransitionBase.typeKey: return StateTransition(); + case NestedBoolBase.typeKey: + return NestedBool(); case KeyFrameDoubleBase.typeKey: return KeyFrameDouble(); case KeyFrameColorBase.typeKey: @@ -188,6 +196,8 @@ class RiveCoreContext { return NestedStateMachine(); case ExitStateBase.typeKey: return ExitState(); + case NestedNumberBase.typeKey: + return NestedNumber(); case BlendAnimation1DBase.typeKey: return BlendAnimation1D(); case BlendState1DBase.typeKey: @@ -522,6 +532,11 @@ class RiveCoreContext { object.animationId = value; } break; + case NestedInputBase.inputIdPropertyKey: + if (object is NestedInputBase && value is int) { + object.inputId = value; + } + break; case KeyedObjectBase.objectIdPropertyKey: if (object is KeyedObjectBase && value is int) { object.objectId = value; @@ -652,6 +667,11 @@ class RiveCoreContext { object.exitTime = value; } break; + case NestedBoolBase.nestedValuePropertyKey: + if (object is NestedBoolBase && value is bool) { + object.nestedValue = value; + } + break; case KeyFrameDoubleBase.valuePropertyKey: if (object is KeyFrameDoubleBase && value is double) { object.value = value; @@ -662,6 +682,11 @@ class RiveCoreContext { object.value = value; } break; + case NestedNumberBase.nestedValuePropertyKey: + if (object is NestedNumberBase && value is double) { + object.nestedValue = value; + } + break; case BlendAnimation1DBase.valuePropertyKey: if (object is BlendAnimation1DBase && value is double) { object.value = value; @@ -1158,6 +1183,7 @@ class RiveCoreContext { case LinearAnimationBase.workEndPropertyKey: case ListenerInputChangeBase.inputIdPropertyKey: case AnimationStateBase.animationIdPropertyKey: + case NestedInputBase.inputIdPropertyKey: case KeyedObjectBase.objectIdPropertyKey: case BlendAnimationBase.animationIdPropertyKey: case BlendAnimationDirectBase.inputIdPropertyKey: @@ -1222,6 +1248,7 @@ class RiveCoreContext { case CubicInterpolatorBase.x2PropertyKey: case CubicInterpolatorBase.y2PropertyKey: case KeyFrameDoubleBase.valuePropertyKey: + case NestedNumberBase.nestedValuePropertyKey: case BlendAnimation1DBase.valuePropertyKey: case NestedRemapAnimationBase.timePropertyKey: case LinearGradientBase.startXPropertyKey: @@ -1293,6 +1320,7 @@ class RiveCoreContext { case LinearAnimationBase.enableWorkAreaPropertyKey: case NestedSimpleAnimationBase.isPlayingPropertyKey: case KeyFrameBoolBase.valuePropertyKey: + case NestedBoolBase.nestedValuePropertyKey: case StateMachineBoolBase.valuePropertyKey: case ShapePaintBase.isVisiblePropertyKey: case StrokeBase.transformAffectsStrokePropertyKey: @@ -1369,6 +1397,8 @@ class RiveCoreContext { return (object as ListenerInputChangeBase).inputId; case AnimationStateBase.animationIdPropertyKey: return (object as AnimationStateBase).animationId; + case NestedInputBase.inputIdPropertyKey: + return (object as NestedInputBase).inputId; case KeyedObjectBase.objectIdPropertyKey: return (object as KeyedObjectBase).objectId; case BlendAnimationBase.animationIdPropertyKey: @@ -1501,6 +1531,8 @@ class RiveCoreContext { return (object as CubicInterpolatorBase).y2; case KeyFrameDoubleBase.valuePropertyKey: return (object as KeyFrameDoubleBase).value; + case NestedNumberBase.nestedValuePropertyKey: + return (object as NestedNumberBase).nestedValue; case BlendAnimation1DBase.valuePropertyKey: return (object as BlendAnimation1DBase).value; case NestedRemapAnimationBase.timePropertyKey: @@ -1647,6 +1679,8 @@ class RiveCoreContext { return (object as NestedSimpleAnimationBase).isPlaying; case KeyFrameBoolBase.valuePropertyKey: return (object as KeyFrameBoolBase).value; + case NestedBoolBase.nestedValuePropertyKey: + return (object as NestedBoolBase).nestedValue; case StateMachineBoolBase.valuePropertyKey: return (object as StateMachineBoolBase).value; case ShapePaintBase.isVisiblePropertyKey: @@ -1814,6 +1848,11 @@ class RiveCoreContext { object.animationId = value; } break; + case NestedInputBase.inputIdPropertyKey: + if (object is NestedInputBase) { + object.inputId = value; + } + break; case KeyedObjectBase.objectIdPropertyKey: if (object is KeyedObjectBase) { object.objectId = value; @@ -2134,6 +2173,11 @@ class RiveCoreContext { object.value = value; } break; + case NestedNumberBase.nestedValuePropertyKey: + if (object is NestedNumberBase) { + object.nestedValue = value; + } + break; case BlendAnimation1DBase.valuePropertyKey: if (object is BlendAnimation1DBase) { object.value = value; @@ -2489,6 +2533,11 @@ class RiveCoreContext { object.value = value; } break; + case NestedBoolBase.nestedValuePropertyKey: + if (object is NestedBoolBase) { + object.nestedValue = value; + } + break; case StateMachineBoolBase.valuePropertyKey: if (object is StateMachineBoolBase) { object.value = value; diff --git a/lib/src/rive_core/animation/nested_bool.dart b/lib/src/rive_core/animation/nested_bool.dart new file mode 100644 index 0000000..da6a079 --- /dev/null +++ b/lib/src/rive_core/animation/nested_bool.dart @@ -0,0 +1,10 @@ +import 'package:rive/src/generated/animation/nested_bool_base.dart'; +export 'package:rive/src/generated/animation/nested_bool_base.dart'; + +class NestedBool extends NestedBoolBase { + @override + void nestedValueChanged(bool from, bool to) => updateValue(); + + @override + void updateValue() => nestedStateMachine?.setInputValue(inputId, nestedValue); +} diff --git a/lib/src/rive_core/animation/nested_input.dart b/lib/src/rive_core/animation/nested_input.dart new file mode 100644 index 0000000..b3462d6 --- /dev/null +++ b/lib/src/rive_core/animation/nested_input.dart @@ -0,0 +1,32 @@ +import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/nested_input_base.dart'; +import 'package:rive/src/rive_core/animation/nested_state_machine.dart'; + +export 'package:rive/src/generated/animation/nested_input_base.dart'; + +abstract class NestedInput extends NestedInputBase { + @override + void inputIdChanged(int from, int to) {} + + NestedStateMachine? get nestedStateMachine => parent as NestedStateMachine?; + + @override + bool validate() => super.validate() && nestedStateMachine != null; + + void updateValue(); + + @override + void update(int dirt) {} + + @override + bool import(ImportStack importStack) { + var importer = importStack + .latest(NestedStateMachineBase.typeKey); + if (importer == null) { + return false; + } + importer.addNestedInput(this); + + return super.import(importStack); + } +} diff --git a/lib/src/rive_core/animation/nested_number.dart b/lib/src/rive_core/animation/nested_number.dart new file mode 100644 index 0000000..dddd3c7 --- /dev/null +++ b/lib/src/rive_core/animation/nested_number.dart @@ -0,0 +1,10 @@ +import 'package:rive/src/generated/animation/nested_number_base.dart'; +export 'package:rive/src/generated/animation/nested_number_base.dart'; + +class NestedNumber extends NestedNumberBase { + @override + void nestedValueChanged(double from, double to) => updateValue(); + + @override + void updateValue() => nestedStateMachine?.setInputValue(inputId, nestedValue); +} diff --git a/lib/src/rive_core/animation/nested_state_machine.dart b/lib/src/rive_core/animation/nested_state_machine.dart index f5629c0..6663cdc 100644 --- a/lib/src/rive_core/animation/nested_state_machine.dart +++ b/lib/src/rive_core/animation/nested_state_machine.dart @@ -1,4 +1,5 @@ import 'package:flutter/foundation.dart'; +import 'package:rive/src/core/core.dart'; import 'package:rive/src/generated/animation/nested_state_machine_base.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/nested_artboard.dart'; @@ -16,6 +17,8 @@ abstract class NestedStateMachineInstance { void pointerDown(Vec2D position); void pointerUp(Vec2D position); + + void setInputValue(int id, dynamic value); } class NestedStateMachine extends NestedStateMachineBase { @@ -45,6 +48,12 @@ class NestedStateMachine extends NestedStateMachineBase { to?.isActiveChanged.addListener(_isActiveChanged); } + void setInputValue(int id, dynamic value) { + int inputId = id; + + _stateMachineInstance?.setInputValue(inputId, value); + } + void pointerMove(Vec2D position) => _stateMachineInstance?.pointerMove(position); diff --git a/lib/src/rive_core/animation/nested_trigger.dart b/lib/src/rive_core/animation/nested_trigger.dart new file mode 100644 index 0000000..b40bbac --- /dev/null +++ b/lib/src/rive_core/animation/nested_trigger.dart @@ -0,0 +1,7 @@ +import 'package:rive/src/generated/animation/nested_trigger_base.dart'; +export 'package:rive/src/generated/animation/nested_trigger_base.dart'; + +class NestedTrigger extends NestedTriggerBase { + @override + void updateValue() {} +} diff --git a/lib/src/rive_core/assets/asset.dart b/lib/src/rive_core/assets/asset.dart index c92dc5f..1fc54d4 100644 --- a/lib/src/rive_core/assets/asset.dart +++ b/lib/src/rive_core/assets/asset.dart @@ -2,7 +2,7 @@ import 'package:rive/src/generated/assets/asset_base.dart'; export 'package:rive/src/generated/assets/asset_base.dart'; -class Asset extends AssetBase { +abstract class Asset extends AssetBase { @override void nameChanged(String from, String to) {} @@ -11,6 +11,4 @@ class Asset extends AssetBase { @override void onAddedDirty() {} - - bool get isUsable => false; } diff --git a/lib/src/rive_core/assets/drawable_asset.dart b/lib/src/rive_core/assets/drawable_asset.dart index 7e1cf9c..4911066 100644 --- a/lib/src/rive_core/assets/drawable_asset.dart +++ b/lib/src/rive_core/assets/drawable_asset.dart @@ -1,9 +1,9 @@ import 'package:rive/src/generated/assets/drawable_asset_base.dart'; + export 'package:rive/src/generated/assets/drawable_asset_base.dart'; abstract class DrawableAsset extends DrawableAssetBase { - @override - bool get isUsable => width != 0 && height != 0; + DrawableAsset(); @override void heightChanged(double from, double to) {} diff --git a/lib/src/rive_core/assets/image_asset.dart b/lib/src/rive_core/assets/image_asset.dart index 56bf6c4..f934030 100644 --- a/lib/src/rive_core/assets/image_asset.dart +++ b/lib/src/rive_core/assets/image_asset.dart @@ -21,6 +21,7 @@ class ImageAsset extends ImageAssetBase { if (_image == image) { return; } + _image = image; } @@ -28,7 +29,7 @@ class ImageAsset extends ImageAssetBase { Future decode(Uint8List bytes) { final completer = Completer(); ui.decodeImageFromList(bytes, (value) { - _image = value; + image = value; completer.complete(); }); return completer.future; diff --git a/lib/src/rive_core/transform_component.dart b/lib/src/rive_core/transform_component.dart index 88cd230..0c132bf 100644 --- a/lib/src/rive_core/transform_component.dart +++ b/lib/src/rive_core/transform_component.dart @@ -33,6 +33,17 @@ abstract class TransformComponent extends TransformComponentBase { final List _constraints = []; Iterable get constraints => _constraints; + bool get isConstrained { + Component? component = this; + while (component != null) { + if (component is TransformComponent && component.constraints.isNotEmpty) { + return true; + } + component = component.parent; + } + return false; + } + double _renderOpacity = 1; double get renderOpacity => _renderOpacity; diff --git a/lib/src/rive_file.dart b/lib/src/rive_file.dart index 83789ed..3fe010d 100644 --- a/lib/src/rive_file.dart +++ b/lib/src/rive_file.dart @@ -19,6 +19,7 @@ import 'package:rive/src/rive_core/animation/keyed_object.dart'; import 'package:rive/src/rive_core/animation/keyed_property.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/nested_state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_layer.dart'; import 'package:rive/src/rive_core/animation/state_machine_listener.dart'; @@ -163,6 +164,10 @@ class RiveFile { stackObject = StateMachineListenerImporter(object as StateMachineListener); break; + case NestedStateMachineBase.typeKey: + stackObject = + NestedStateMachineImporter(object as NestedStateMachine); + break; case EntryStateBase.typeKey: case AnyStateBase.typeKey: case ExitStateBase.typeKey: diff --git a/lib/src/runtime_nested_artboard.dart b/lib/src/runtime_nested_artboard.dart index b69d77e..f276c04 100644 --- a/lib/src/runtime_nested_artboard.dart +++ b/lib/src/runtime_nested_artboard.dart @@ -124,6 +124,14 @@ class RuntimeNestedStateMachineInstance extends NestedStateMachineInstance { @override void pointerUp(Vec2D position) => stateMachineController.pointerUp(position); + + @override + void setInputValue(int id, dynamic value) { + var inputs = stateMachineController.stateMachine.inputs; + if (id < inputs.length && id >= 0) { + stateMachineController.setInputValue(inputs[id].id, value); + } + } } class RuntimeMountedArtboard extends MountedArtboard {