mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-08-06 08:29:35 +08:00
update flutter runtime
updated the flutter runtime @alxgibsn @philter This update included some changes from other branches. Can you verify that all looks good? Diffs= cd9520371 update flutter runtime (#7141) 2b2e92ca7 Fix audio instances (#7113) Co-authored-by: hernan <hernan@rive.app>
This commit is contained in:
@ -1 +1 @@
|
|||||||
fdd52090da92bc230f9bf6d4707a77b1e80e62d2
|
cd9520371615e6eb1fcc5f4ba9b5c3d58b3f29ea
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// lib/src/generated/animation/layer_state_base.dart.
|
// lib/src/generated/animation/layer_state_base.dart.
|
||||||
// Do not modify manually.
|
// Do not modify manually.
|
||||||
|
|
||||||
|
import 'package:rive/src/core/core.dart';
|
||||||
import 'package:rive/src/rive_core/animation/state_machine_layer_component.dart';
|
import 'package:rive/src/rive_core/animation/state_machine_layer_component.dart';
|
||||||
|
|
||||||
abstract class LayerStateBase extends StateMachineLayerComponent {
|
abstract class LayerStateBase extends StateMachineLayerComponent {
|
||||||
@ -11,4 +12,34 @@ abstract class LayerStateBase extends StateMachineLayerComponent {
|
|||||||
@override
|
@override
|
||||||
Set<int> get coreTypes =>
|
Set<int> get coreTypes =>
|
||||||
{LayerStateBase.typeKey, StateMachineLayerComponentBase.typeKey};
|
{LayerStateBase.typeKey, StateMachineLayerComponentBase.typeKey};
|
||||||
|
|
||||||
|
/// --------------------------------------------------------------------------
|
||||||
|
/// Flags field with key 536.
|
||||||
|
static const int flagsPropertyKey = 536;
|
||||||
|
static const int flagsInitialValue = 0;
|
||||||
|
int _flags = flagsInitialValue;
|
||||||
|
int get flags => _flags;
|
||||||
|
|
||||||
|
/// Change the [_flags] field value.
|
||||||
|
/// [flagsChanged] will be invoked only if the field's value has changed.
|
||||||
|
set flags(int value) {
|
||||||
|
if (_flags == value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int from = _flags;
|
||||||
|
_flags = value;
|
||||||
|
if (hasValidated) {
|
||||||
|
flagsChanged(from, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void flagsChanged(int from, int to);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void copy(Core source) {
|
||||||
|
super.copy(source);
|
||||||
|
if (source is LayerStateBase) {
|
||||||
|
_flags = source._flags;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,6 +161,31 @@ abstract class StateTransitionBase extends StateMachineLayerComponent {
|
|||||||
|
|
||||||
void interpolatorIdChanged(int from, int to);
|
void interpolatorIdChanged(int from, int to);
|
||||||
|
|
||||||
|
/// --------------------------------------------------------------------------
|
||||||
|
/// RandomWeight field with key 537.
|
||||||
|
static const int randomWeightPropertyKey = 537;
|
||||||
|
static const int randomWeightInitialValue = 1;
|
||||||
|
int _randomWeight = randomWeightInitialValue;
|
||||||
|
|
||||||
|
/// Weight of the transition in the overall random options
|
||||||
|
int get randomWeight => _randomWeight;
|
||||||
|
|
||||||
|
/// Change the [_randomWeight] field value.
|
||||||
|
/// [randomWeightChanged] will be invoked only if the field's value has
|
||||||
|
/// changed.
|
||||||
|
set randomWeight(int value) {
|
||||||
|
if (_randomWeight == value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int from = _randomWeight;
|
||||||
|
_randomWeight = value;
|
||||||
|
if (hasValidated) {
|
||||||
|
randomWeightChanged(from, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void randomWeightChanged(int from, int to);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void copy(Core source) {
|
void copy(Core source) {
|
||||||
super.copy(source);
|
super.copy(source);
|
||||||
@ -171,6 +196,7 @@ abstract class StateTransitionBase extends StateMachineLayerComponent {
|
|||||||
_exitTime = source._exitTime;
|
_exitTime = source._exitTime;
|
||||||
_interpolationType = source._interpolationType;
|
_interpolationType = source._interpolationType;
|
||||||
_interpolatorId = source._interpolatorId;
|
_interpolatorId = source._interpolatorId;
|
||||||
|
_randomWeight = source._randomWeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
lib/src/generated/layout_component_absolute_base.dart
Normal file
22
lib/src/generated/layout_component_absolute_base.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Core automatically generated
|
||||||
|
// lib/src/generated/layout_component_absolute_base.dart.
|
||||||
|
// 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/world_transform_component_base.dart';
|
||||||
|
import 'package:rive/src/rive_core/layout_component.dart';
|
||||||
|
|
||||||
|
abstract class AbsoluteLayoutComponentBase extends LayoutComponent {
|
||||||
|
static const int typeKey = 423;
|
||||||
|
@override
|
||||||
|
int get coreType => AbsoluteLayoutComponentBase.typeKey;
|
||||||
|
@override
|
||||||
|
Set<int> get coreTypes => {
|
||||||
|
AbsoluteLayoutComponentBase.typeKey,
|
||||||
|
LayoutComponentBase.typeKey,
|
||||||
|
WorldTransformComponentBase.typeKey,
|
||||||
|
ContainerComponentBase.typeKey,
|
||||||
|
ComponentBase.typeKey
|
||||||
|
};
|
||||||
|
}
|
@ -13,6 +13,7 @@ import 'package:rive/src/generated/animation/cubic_interpolator_base.dart';
|
|||||||
import 'package:rive/src/generated/animation/interpolating_keyframe_base.dart';
|
import 'package:rive/src/generated/animation/interpolating_keyframe_base.dart';
|
||||||
import 'package:rive/src/generated/animation/keyframe_base.dart';
|
import 'package:rive/src/generated/animation/keyframe_base.dart';
|
||||||
import 'package:rive/src/generated/animation/keyframe_string_base.dart';
|
import 'package:rive/src/generated/animation/keyframe_string_base.dart';
|
||||||
|
import 'package:rive/src/generated/animation/layer_state_base.dart';
|
||||||
import 'package:rive/src/generated/animation/listener_input_change_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_input_base.dart';
|
||||||
import 'package:rive/src/generated/animation/nested_linear_animation_base.dart';
|
import 'package:rive/src/generated/animation/nested_linear_animation_base.dart';
|
||||||
@ -30,6 +31,7 @@ import 'package:rive/src/generated/constraints/transform_component_constraint_ba
|
|||||||
import 'package:rive/src/generated/constraints/transform_component_constraint_y_base.dart';
|
import 'package:rive/src/generated/constraints/transform_component_constraint_y_base.dart';
|
||||||
import 'package:rive/src/generated/constraints/transform_space_constraint_base.dart';
|
import 'package:rive/src/generated/constraints/transform_space_constraint_base.dart';
|
||||||
import 'package:rive/src/generated/drawable_base.dart';
|
import 'package:rive/src/generated/drawable_base.dart';
|
||||||
|
import 'package:rive/src/generated/layout_component_absolute_base.dart';
|
||||||
import 'package:rive/src/generated/nested_animation_base.dart';
|
import 'package:rive/src/generated/nested_animation_base.dart';
|
||||||
import 'package:rive/src/generated/shapes/paint/shape_paint_base.dart';
|
import 'package:rive/src/generated/shapes/paint/shape_paint_base.dart';
|
||||||
import 'package:rive/src/generated/shapes/parametric_path_base.dart';
|
import 'package:rive/src/generated/shapes/parametric_path_base.dart';
|
||||||
@ -112,6 +114,7 @@ import 'package:rive/src/rive_core/event.dart';
|
|||||||
import 'package:rive/src/rive_core/joystick.dart';
|
import 'package:rive/src/rive_core/joystick.dart';
|
||||||
import 'package:rive/src/rive_core/layout/layout_component_style.dart';
|
import 'package:rive/src/rive_core/layout/layout_component_style.dart';
|
||||||
import 'package:rive/src/rive_core/layout_component.dart';
|
import 'package:rive/src/rive_core/layout_component.dart';
|
||||||
|
import 'package:rive/src/rive_core/layout_component_absolute.dart';
|
||||||
import 'package:rive/src/rive_core/nested_artboard.dart';
|
import 'package:rive/src/rive_core/nested_artboard.dart';
|
||||||
import 'package:rive/src/rive_core/node.dart';
|
import 'package:rive/src/rive_core/node.dart';
|
||||||
import 'package:rive/src/rive_core/open_url_event.dart';
|
import 'package:rive/src/rive_core/open_url_event.dart';
|
||||||
@ -332,6 +335,8 @@ class RiveCoreContext {
|
|||||||
return Joystick();
|
return Joystick();
|
||||||
case BackboardBase.typeKey:
|
case BackboardBase.typeKey:
|
||||||
return Backboard();
|
return Backboard();
|
||||||
|
case AbsoluteLayoutComponentBase.typeKey:
|
||||||
|
return AbsoluteLayoutComponent();
|
||||||
case OpenUrlEventBase.typeKey:
|
case OpenUrlEventBase.typeKey:
|
||||||
return OpenUrlEvent();
|
return OpenUrlEvent();
|
||||||
case BoneBase.typeKey:
|
case BoneBase.typeKey:
|
||||||
@ -749,6 +754,11 @@ class RiveCoreContext {
|
|||||||
object.eventId = value;
|
object.eventId = value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case LayerStateBase.flagsPropertyKey:
|
||||||
|
if (object is LayerStateBase && value is int) {
|
||||||
|
object.flags = value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case AnimationBase.namePropertyKey:
|
case AnimationBase.namePropertyKey:
|
||||||
if (object is AnimationBase && value is String) {
|
if (object is AnimationBase && value is String) {
|
||||||
object.name = value;
|
object.name = value;
|
||||||
@ -1019,6 +1029,11 @@ class RiveCoreContext {
|
|||||||
object.interpolatorId = value;
|
object.interpolatorId = value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case StateTransitionBase.randomWeightPropertyKey:
|
||||||
|
if (object is StateTransitionBase && value is int) {
|
||||||
|
object.randomWeight = value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case NestedBoolBase.nestedValuePropertyKey:
|
case NestedBoolBase.nestedValuePropertyKey:
|
||||||
if (object is NestedBoolBase && value is bool) {
|
if (object is NestedBoolBase && value is bool) {
|
||||||
object.nestedValue = value;
|
object.nestedValue = value;
|
||||||
@ -1884,6 +1899,7 @@ class RiveCoreContext {
|
|||||||
case LayoutComponentStyleBase.layoutFlags1PropertyKey:
|
case LayoutComponentStyleBase.layoutFlags1PropertyKey:
|
||||||
case LayoutComponentStyleBase.layoutFlags2PropertyKey:
|
case LayoutComponentStyleBase.layoutFlags2PropertyKey:
|
||||||
case ListenerFireEventBase.eventIdPropertyKey:
|
case ListenerFireEventBase.eventIdPropertyKey:
|
||||||
|
case LayerStateBase.flagsPropertyKey:
|
||||||
case LinearAnimationBase.fpsPropertyKey:
|
case LinearAnimationBase.fpsPropertyKey:
|
||||||
case LinearAnimationBase.durationPropertyKey:
|
case LinearAnimationBase.durationPropertyKey:
|
||||||
case LinearAnimationBase.loopValuePropertyKey:
|
case LinearAnimationBase.loopValuePropertyKey:
|
||||||
@ -1915,6 +1931,7 @@ class RiveCoreContext {
|
|||||||
case StateTransitionBase.exitTimePropertyKey:
|
case StateTransitionBase.exitTimePropertyKey:
|
||||||
case StateTransitionBase.interpolationTypePropertyKey:
|
case StateTransitionBase.interpolationTypePropertyKey:
|
||||||
case StateTransitionBase.interpolatorIdPropertyKey:
|
case StateTransitionBase.interpolatorIdPropertyKey:
|
||||||
|
case StateTransitionBase.randomWeightPropertyKey:
|
||||||
case StateMachineFireEventBase.eventIdPropertyKey:
|
case StateMachineFireEventBase.eventIdPropertyKey:
|
||||||
case StateMachineFireEventBase.occursValuePropertyKey:
|
case StateMachineFireEventBase.occursValuePropertyKey:
|
||||||
case ElasticInterpolatorBase.easingValuePropertyKey:
|
case ElasticInterpolatorBase.easingValuePropertyKey:
|
||||||
@ -2235,6 +2252,8 @@ class RiveCoreContext {
|
|||||||
return (object as LayoutComponentStyleBase).layoutFlags2;
|
return (object as LayoutComponentStyleBase).layoutFlags2;
|
||||||
case ListenerFireEventBase.eventIdPropertyKey:
|
case ListenerFireEventBase.eventIdPropertyKey:
|
||||||
return (object as ListenerFireEventBase).eventId;
|
return (object as ListenerFireEventBase).eventId;
|
||||||
|
case LayerStateBase.flagsPropertyKey:
|
||||||
|
return (object as LayerStateBase).flags;
|
||||||
case LinearAnimationBase.fpsPropertyKey:
|
case LinearAnimationBase.fpsPropertyKey:
|
||||||
return (object as LinearAnimationBase).fps;
|
return (object as LinearAnimationBase).fps;
|
||||||
case LinearAnimationBase.durationPropertyKey:
|
case LinearAnimationBase.durationPropertyKey:
|
||||||
@ -2297,6 +2316,8 @@ class RiveCoreContext {
|
|||||||
return (object as StateTransitionBase).interpolationType;
|
return (object as StateTransitionBase).interpolationType;
|
||||||
case StateTransitionBase.interpolatorIdPropertyKey:
|
case StateTransitionBase.interpolatorIdPropertyKey:
|
||||||
return (object as StateTransitionBase).interpolatorId;
|
return (object as StateTransitionBase).interpolatorId;
|
||||||
|
case StateTransitionBase.randomWeightPropertyKey:
|
||||||
|
return (object as StateTransitionBase).randomWeight;
|
||||||
case StateMachineFireEventBase.eventIdPropertyKey:
|
case StateMachineFireEventBase.eventIdPropertyKey:
|
||||||
return (object as StateMachineFireEventBase).eventId;
|
return (object as StateMachineFireEventBase).eventId;
|
||||||
case StateMachineFireEventBase.occursValuePropertyKey:
|
case StateMachineFireEventBase.occursValuePropertyKey:
|
||||||
@ -2937,6 +2958,11 @@ class RiveCoreContext {
|
|||||||
object.eventId = value;
|
object.eventId = value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case LayerStateBase.flagsPropertyKey:
|
||||||
|
if (object is LayerStateBase) {
|
||||||
|
object.flags = value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case LinearAnimationBase.fpsPropertyKey:
|
case LinearAnimationBase.fpsPropertyKey:
|
||||||
if (object is LinearAnimationBase) {
|
if (object is LinearAnimationBase) {
|
||||||
object.fps = value;
|
object.fps = value;
|
||||||
@ -3092,6 +3118,11 @@ class RiveCoreContext {
|
|||||||
object.interpolatorId = value;
|
object.interpolatorId = value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case StateTransitionBase.randomWeightPropertyKey:
|
||||||
|
if (object is StateTransitionBase) {
|
||||||
|
object.randomWeight = value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case StateMachineFireEventBase.eventIdPropertyKey:
|
case StateMachineFireEventBase.eventIdPropertyKey:
|
||||||
if (object is StateMachineFireEventBase) {
|
if (object is StateMachineFireEventBase) {
|
||||||
object.eventId = value;
|
object.eventId = value;
|
||||||
|
@ -26,6 +26,9 @@ abstract class LayerState extends LayerStateBase {
|
|||||||
_transitions.remove(transition);
|
_transitions.remove(transition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void flagsChanged(int from, int to) {}
|
||||||
|
|
||||||
StateInstance makeInstance();
|
StateInstance makeInstance();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -28,6 +28,7 @@ class StateTransition extends StateTransitionBase {
|
|||||||
|
|
||||||
static final StateTransition unknown = StateTransition();
|
static final StateTransition unknown = StateTransition();
|
||||||
|
|
||||||
|
int evaluatedRandomWeight = 0;
|
||||||
Interpolator? _interpolator;
|
Interpolator? _interpolator;
|
||||||
Interpolator? get interpolator => _interpolator;
|
Interpolator? get interpolator => _interpolator;
|
||||||
set interpolator(Interpolator? value) {
|
set interpolator(Interpolator? value) {
|
||||||
@ -160,6 +161,9 @@ class StateTransition extends StateTransitionBase {
|
|||||||
@override
|
@override
|
||||||
void durationChanged(int from, int to) {}
|
void durationChanged(int from, int to) {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void randomWeightChanged(int from, int to) {}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void exitTimeChanged(int from, int to) {}
|
void exitTimeChanged(int from, int to) {}
|
||||||
|
|
||||||
|
@ -535,23 +535,12 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
|
|||||||
@override
|
@override
|
||||||
void onStrokesChanged() {}
|
void onStrokesChanged() {}
|
||||||
|
|
||||||
/// Sets `isPlaying` to true. Animations and state machines will play.
|
|
||||||
///
|
|
||||||
/// See [pause], to pause the artboard from advancing/drawing.
|
|
||||||
@mustBeOverridden
|
@mustBeOverridden
|
||||||
void play() {}
|
void play() {}
|
||||||
|
|
||||||
/// Sets `isPlaying` to false. Animations and state machines will not play.
|
|
||||||
/// This can be used to reduce resources when the animation is not visible
|
|
||||||
/// in the app.
|
|
||||||
///
|
|
||||||
/// See [play], to play the artboard and continue advancing/drawing.
|
|
||||||
@mustBeOverridden
|
@mustBeOverridden
|
||||||
void pause() {}
|
void pause() {}
|
||||||
|
|
||||||
/// Indicates if the runtime artboard is active/playing. When `false` no
|
|
||||||
/// artboard animation or state machine will advance. The underlying animation
|
|
||||||
/// ticker is paused.
|
|
||||||
@mustBeOverridden
|
@mustBeOverridden
|
||||||
bool get isPlaying => true;
|
bool get isPlaying => true;
|
||||||
|
|
||||||
|
@ -29,11 +29,6 @@ class AudioAsset extends AudioAssetBase {
|
|||||||
audioBytes = bytes;
|
audioBytes = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
String get fileExtension {
|
|
||||||
return 'wav';
|
|
||||||
}
|
|
||||||
|
|
||||||
static AudioContainerFormat containerFormatFromName(String name) {
|
static AudioContainerFormat containerFormatFromName(String name) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'flac':
|
case 'flac':
|
||||||
@ -45,4 +40,8 @@ class AudioAsset extends AudioAssetBase {
|
|||||||
}
|
}
|
||||||
return AudioContainerFormat.unknown;
|
return AudioContainerFormat.unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See comment in font_asset.dart
|
||||||
|
@override
|
||||||
|
String get fileExtension => 'wav';
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,6 @@ class AudioPlayer {
|
|||||||
_soundDuration = source.duration;
|
_soundDuration = source.duration;
|
||||||
_soundStartTime = engineTime -
|
_soundStartTime = engineTime -
|
||||||
(startTime.inMicroseconds * 1e-6 * engine.sampleRate).round();
|
(startTime.inMicroseconds * 1e-6 * engine.sampleRate).round();
|
||||||
|
|
||||||
_timer ??= Timer.periodic(const Duration(milliseconds: 0), _frameCallback);
|
_timer ??= Timer.periodic(const Duration(milliseconds: 0), _frameCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
lib/src/rive_core/layer_state_flags.dart
Normal file
4
lib/src/rive_core/layer_state_flags.dart
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class LayerStateFlags {
|
||||||
|
/// Whether the state can randomize on exit.
|
||||||
|
static const int random = 1 << 0;
|
||||||
|
}
|
@ -238,7 +238,9 @@ class LayoutComponentStyle extends LayoutComponentStyleBase {
|
|||||||
void layoutFlags0Changed(int from, int to) => markLayoutNodeDirty();
|
void layoutFlags0Changed(int from, int to) => markLayoutNodeDirty();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void layoutFlags1Changed(int from, int to) => markLayoutNodeDirty();
|
void layoutFlags1Changed(int from, int to) {
|
||||||
|
markLayoutNodeDirty();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void layoutFlags2Changed(int from, int to) => markLayoutNodeDirty();
|
void layoutFlags2Changed(int from, int to) => markLayoutNodeDirty();
|
||||||
|
@ -30,6 +30,17 @@ class LayoutComponent extends LayoutComponentBase {
|
|||||||
final LayoutNode _layoutNode = LayoutNode.make();
|
final LayoutNode _layoutNode = LayoutNode.make();
|
||||||
LayoutNode get layoutNode => _layoutNode;
|
LayoutNode get layoutNode => _layoutNode;
|
||||||
|
|
||||||
|
LayoutComponent? get layoutParent {
|
||||||
|
var p = parent;
|
||||||
|
while (p != null) {
|
||||||
|
if (p is LayoutComponent) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
p = p.parent;
|
||||||
|
}
|
||||||
|
return artboard;
|
||||||
|
}
|
||||||
|
|
||||||
void markLayoutNodeDirty() {
|
void markLayoutNodeDirty() {
|
||||||
_layoutNode.markDirty();
|
_layoutNode.markDirty();
|
||||||
artboard?.markLayoutDirty(this);
|
artboard?.markLayoutDirty(this);
|
||||||
@ -253,6 +264,24 @@ class LayoutComponent extends LayoutComponentBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AABB get layoutBounds {
|
||||||
|
return AABB.fromValues(
|
||||||
|
_layoutLocation.dx,
|
||||||
|
_layoutLocation.dy,
|
||||||
|
_layoutLocation.dx + _layoutSize.width,
|
||||||
|
_layoutLocation.dy + _layoutSize.height,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
AABB get worldBounds {
|
||||||
|
return AABB.fromValues(
|
||||||
|
worldTransform[4],
|
||||||
|
worldTransform[5],
|
||||||
|
worldTransform[4] + _layoutSize.width,
|
||||||
|
worldTransform[5] + _layoutSize.height,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
AABB get constraintBounds => localBounds;
|
AABB get constraintBounds => localBounds;
|
||||||
|
|
||||||
|
7
lib/src/rive_core/layout_component_absolute.dart
Normal file
7
lib/src/rive_core/layout_component_absolute.dart
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import 'package:rive/src/generated/layout_component_absolute_base.dart';
|
||||||
|
|
||||||
|
export 'package:rive/src/generated/layout_component_base.dart';
|
||||||
|
|
||||||
|
class AbsoluteLayoutComponent extends AbsoluteLayoutComponentBase {
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
library rive_core;
|
library rive_core;
|
||||||
|
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
@ -28,6 +29,7 @@ import 'package:rive/src/rive_core/audio_player.dart';
|
|||||||
import 'package:rive/src/rive_core/component.dart';
|
import 'package:rive/src/rive_core/component.dart';
|
||||||
import 'package:rive/src/rive_core/drawable.dart';
|
import 'package:rive/src/rive_core/drawable.dart';
|
||||||
import 'package:rive/src/rive_core/event.dart';
|
import 'package:rive/src/rive_core/event.dart';
|
||||||
|
import 'package:rive/src/rive_core/layer_state_flags.dart';
|
||||||
import 'package:rive/src/rive_core/nested_artboard.dart';
|
import 'package:rive/src/rive_core/nested_artboard.dart';
|
||||||
import 'package:rive/src/rive_core/node.dart';
|
import 'package:rive/src/rive_core/node.dart';
|
||||||
import 'package:rive/src/rive_core/rive_animation_controller.dart';
|
import 'package:rive/src/rive_core/rive_animation_controller.dart';
|
||||||
@ -86,12 +88,14 @@ class LayerController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _changeState(LayerState? state, {StateTransition? transition}) {
|
bool _canChangeState(LayerState? state) {
|
||||||
|
return state != _currentState?.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _changeState(LayerState? state, {StateTransition? transition}) {
|
||||||
assert(state is! AnyState,
|
assert(state is! AnyState,
|
||||||
'We don\'t allow making the AnyState an active state.');
|
'We don\'t allow making the AnyState an active state.');
|
||||||
if (state == _currentState?.state) {
|
assert(state != _currentState?.state, 'Cannot change to state to self.');
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var currentState = _currentState;
|
var currentState = _currentState;
|
||||||
if (currentState != null) {
|
if (currentState != null) {
|
||||||
_fireEvents(currentState.state.eventsAt(StateMachineFireOccurance.atEnd));
|
_fireEvents(currentState.state.eventsAt(StateMachineFireOccurance.atEnd));
|
||||||
@ -105,8 +109,6 @@ class LayerController {
|
|||||||
} else {
|
} else {
|
||||||
_currentState = null;
|
_currentState = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@ -208,64 +210,118 @@ class LayerController {
|
|||||||
return tryChangeState(_currentState, ignoreTriggers);
|
return tryChangeState(_currentState, ignoreTriggers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StateTransition? _findRandomTransition(
|
||||||
|
StateInstance stateFrom, bool ignoreTriggers) {
|
||||||
|
double totalWeight = 0;
|
||||||
|
final transitions = stateFrom.state.transitions;
|
||||||
|
for (final transition in transitions) {
|
||||||
|
var allowed = transition.allowed(
|
||||||
|
stateFrom, controller._inputValues, ignoreTriggers);
|
||||||
|
if (allowed == AllowTransition.yes &&
|
||||||
|
_canChangeState(transition.stateTo)) {
|
||||||
|
transition.evaluatedRandomWeight = transition.randomWeight;
|
||||||
|
totalWeight += transition.randomWeight;
|
||||||
|
// If random is not active we don't search for more candidates
|
||||||
|
} else {
|
||||||
|
transition.evaluatedRandomWeight = 0;
|
||||||
|
if (allowed == AllowTransition.waitingForExit) {
|
||||||
|
_waitingForExit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (totalWeight > 0) {
|
||||||
|
final random = Random().nextDouble() * totalWeight;
|
||||||
|
double currentWeight = 0;
|
||||||
|
int index = 0;
|
||||||
|
while (index < transitions.length) {
|
||||||
|
final transitionWeight =
|
||||||
|
transitions.elementAt(index).evaluatedRandomWeight;
|
||||||
|
if (currentWeight + transitionWeight > random) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
currentWeight += transitionWeight;
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
assert(index < transitions.length);
|
||||||
|
final transition = transitions.elementAt(index);
|
||||||
|
return transition;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
StateTransition? _findAllowedTransition(
|
||||||
|
StateInstance stateFrom, bool ignoreTriggers) {
|
||||||
|
if (stateFrom.state.flags & LayerStateFlags.random ==
|
||||||
|
LayerStateFlags.random) {
|
||||||
|
return _findRandomTransition(stateFrom, ignoreTriggers);
|
||||||
|
}
|
||||||
|
final transitions = stateFrom.state.transitions;
|
||||||
|
for (final transition in transitions) {
|
||||||
|
var allowed = transition.allowed(
|
||||||
|
stateFrom, controller._inputValues, ignoreTriggers);
|
||||||
|
if (allowed == AllowTransition.yes &&
|
||||||
|
_canChangeState(transition.stateTo)) {
|
||||||
|
return transition;
|
||||||
|
} else if (allowed == AllowTransition.waitingForExit) {
|
||||||
|
_waitingForExit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
bool tryChangeState(StateInstance? stateFrom, bool ignoreTriggers) {
|
bool tryChangeState(StateInstance? stateFrom, bool ignoreTriggers) {
|
||||||
if (stateFrom == null) {
|
if (stateFrom == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var outState = _currentState;
|
var outState = _currentState;
|
||||||
for (final transition in stateFrom.state.transitions) {
|
final transition = _findAllowedTransition(stateFrom, ignoreTriggers);
|
||||||
var allowed = transition.allowed(
|
if (transition != null) {
|
||||||
stateFrom, controller._inputValues, ignoreTriggers);
|
_changeState(transition.stateTo, transition: transition);
|
||||||
if (allowed == AllowTransition.yes &&
|
// Take transition
|
||||||
_changeState(transition.stateTo, transition: transition)) {
|
_transition = transition;
|
||||||
// Take transition
|
|
||||||
_transition = transition;
|
|
||||||
|
|
||||||
_fireEvents(transition.eventsAt(StateMachineFireOccurance.atStart));
|
_fireEvents(transition.eventsAt(StateMachineFireOccurance.atStart));
|
||||||
// Immediately fire end events if transition has no duration.
|
// Immediately fire end events if transition has no duration.
|
||||||
if (transition.duration == 0) {
|
if (transition.duration == 0) {
|
||||||
_transitionCompleted = true;
|
_transitionCompleted = true;
|
||||||
_fireEvents(transition.eventsAt(StateMachineFireOccurance.atEnd));
|
_fireEvents(transition.eventsAt(StateMachineFireOccurance.atEnd));
|
||||||
} else {
|
} else {
|
||||||
_transitionCompleted = false;
|
_transitionCompleted = false;
|
||||||
}
|
|
||||||
|
|
||||||
_stateFrom = outState;
|
|
||||||
|
|
||||||
// If we had an exit time and wanted to pause on exit, make sure to hold
|
|
||||||
// the exit time. Delegate this to the transition by telling it that it
|
|
||||||
// was completed.
|
|
||||||
if (outState != null && transition.applyExitCondition(outState)) {
|
|
||||||
// Make sure we apply this state.
|
|
||||||
var inst = (outState as AnimationStateInstance).animationInstance;
|
|
||||||
_holdAnimation = inst.animation;
|
|
||||||
_holdTime = inst.time;
|
|
||||||
}
|
|
||||||
_mixFrom = _mix;
|
|
||||||
|
|
||||||
// Keep mixing last animation that was mixed in.
|
|
||||||
if (_mix != 0) {
|
|
||||||
_holdAnimationFrom = transition.pauseOnExit;
|
|
||||||
}
|
|
||||||
if (outState is AnimationStateInstance) {
|
|
||||||
var spilledTime = outState.animationInstance.spilledTime;
|
|
||||||
_currentState?.advance(spilledTime, controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
_mix = 0;
|
|
||||||
_updateMix(0);
|
|
||||||
// Make sure to reset _waitingForExit to false if we succeed at taking a
|
|
||||||
// transition.
|
|
||||||
_waitingForExit = false;
|
|
||||||
// State has changed, fire the callback if there's one
|
|
||||||
if (_currentState != null) {
|
|
||||||
onLayerStateChange?.call(_currentState!.state);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (allowed == AllowTransition.waitingForExit) {
|
|
||||||
_waitingForExit = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_stateFrom = outState;
|
||||||
|
|
||||||
|
// If we had an exit time and wanted to pause on exit, make sure to hold
|
||||||
|
// the exit time. Delegate this to the transition by telling it that it
|
||||||
|
// was completed.
|
||||||
|
if (outState != null && transition.applyExitCondition(outState)) {
|
||||||
|
// Make sure we apply this state.
|
||||||
|
var inst = (outState as AnimationStateInstance).animationInstance;
|
||||||
|
_holdAnimation = inst.animation;
|
||||||
|
_holdTime = inst.time;
|
||||||
|
}
|
||||||
|
_mixFrom = _mix;
|
||||||
|
|
||||||
|
// Keep mixing last animation that was mixed in.
|
||||||
|
if (_mix != 0) {
|
||||||
|
_holdAnimationFrom = transition.pauseOnExit;
|
||||||
|
}
|
||||||
|
if (outState is AnimationStateInstance) {
|
||||||
|
var spilledTime = outState.animationInstance.spilledTime;
|
||||||
|
_currentState?.advance(spilledTime, controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
_mix = 0;
|
||||||
|
_updateMix(0);
|
||||||
|
// Make sure to reset _waitingForExit to false if we succeed at taking a
|
||||||
|
// transition.
|
||||||
|
_waitingForExit = false;
|
||||||
|
// State has changed, fire the callback if there's one
|
||||||
|
if (_currentState != null) {
|
||||||
|
onLayerStateChange?.call(_currentState!.state);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -289,7 +345,9 @@ class StateMachineController extends RiveAnimationController<CoreContext>
|
|||||||
|
|
||||||
final _eventListeners = <OnEvent>{};
|
final _eventListeners = <OnEvent>{};
|
||||||
AudioPlayer? _audioPlayer;
|
AudioPlayer? _audioPlayer;
|
||||||
|
|
||||||
AudioPlayer get audioPlayer => (_audioPlayer ??= AudioPlayer.make())!;
|
AudioPlayer get audioPlayer => (_audioPlayer ??= AudioPlayer.make())!;
|
||||||
|
|
||||||
AudioPlayer? get peekAudioPlayer => _audioPlayer;
|
AudioPlayer? get peekAudioPlayer => _audioPlayer;
|
||||||
|
|
||||||
List<Event> get reportedEvents => _reportedEvents;
|
List<Event> get reportedEvents => _reportedEvents;
|
||||||
|
Reference in New Issue
Block a user