Skip to content

Commit

Permalink
Merge pull request #102 from 2d-inc/master
Browse files Browse the repository at this point in the history
Updating dev branch.
  • Loading branch information
luigi-rosso committed Jun 13, 2019
2 parents 6606b73 + 865e090 commit 8f04aa6
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 234 deletions.
197 changes: 20 additions & 177 deletions flare_dart/lib/animation/actor_animation.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import "../stream_reader.dart";
import "../actor_artboard.dart";
import "../actor_component.dart";
import "../actor_event.dart";
import "../actor_artboard.dart";
import "property_types.dart";
import "../stream_reader.dart";
import "keyframe.dart";
import "property_types.dart";


typedef KeyFrame KeyFrameReader(StreamReader reader, ActorComponent component);

Expand All @@ -26,13 +27,6 @@ class PropertyAnimation {
}
PropertyAnimation propertyAnimation = PropertyAnimation();
int type = propertyBlock.blockType;
// Wish there were a way do to this in Dart without having to create my own hash set.
// if(!Enum.IsDefined(typeof(PropertyTypes), type))
// {
// return null;
// }
// else
// {
propertyAnimation._type = type;

KeyFrameReader keyFrameReader;
Expand Down Expand Up @@ -167,7 +161,7 @@ class PropertyAnimation {
}

void apply(double time, ActorComponent component, double mix) {
if (_keyFrames.length == 0) {
if (_keyFrames.isEmpty) {
return;
}

Expand All @@ -180,7 +174,7 @@ class PropertyAnimation {
int end = _keyFrames.length - 1;

while (start <= end) {
mid = ((start + end) >> 1);
mid = (start + end) >> 1;
element = _keyFrames[mid].time;
if (element < time) {
start = mid + 1;
Expand Down Expand Up @@ -243,7 +237,7 @@ class ComponentAnimation {
}

void apply(double time, List<ActorComponent> components, double mix) {
for (PropertyAnimation propertyAnimation in _properties) {
for (final PropertyAnimation propertyAnimation in _properties) {
if (propertyAnimation != null) {
propertyAnimation.apply(time, components[_componentIndex], mix);
}
Expand Down Expand Up @@ -296,34 +290,21 @@ class ActorAnimation {
List<ComponentAnimation> _components;
List<ComponentAnimation> _triggerComponents;

String get name {
return _name;
}
String get name => _name;

bool get isLooping {
return _isLooping;
}
int get fps => _fps;

double get duration {
return _duration;
}
bool get isLooping => _isLooping;

List<ComponentAnimation> get animatedComponents {
return _components;
}
double get duration => _duration;

List<ComponentAnimation> get animatedComponents => _components;

//Animation.prototype.triggerEvents = function(actorComponents, fromTime, toTime, triggered)
/*
name:component._Name,
component:component,
propertyType:property._Type,
keyFrameTime:toTime,
elapsed:0*/
void triggerEvents(List<ActorComponent> components, double fromTime,
double toTime, List<AnimationEventArgs> triggerEvents) {
for (int i = 0; i < _triggerComponents.length; i++) {
ComponentAnimation keyedComponent = _triggerComponents[i];
for (PropertyAnimation property in keyedComponent.properties) {
for (final PropertyAnimation property in keyedComponent.properties) {
switch (property.propertyType) {
case PropertyTypes.Trigger:
List<KeyFrame> keyFrames = property.keyFrames;
Expand All @@ -342,7 +323,7 @@ class ActorAnimation {
int end = kfl - 1;

while (start <= end) {
mid = ((start + end) >> 1);
mid = (start + end) >> 1;
element = keyFrames[mid].time;
if (element < toTime) {
start = mid + 1;
Expand All @@ -357,7 +338,6 @@ class ActorAnimation {
idx = start;
}

//int idx = keyFrameLocation(toTime, keyFrames, 0, keyFrames.length-1);
if (idx == 0) {
if (kfl > 0 && keyFrames[0].time == toTime) {
ActorComponent component =
Expand Down Expand Up @@ -408,16 +388,18 @@ class ActorAnimation {
StreamReader reader, List<ActorComponent> components) {
ActorAnimation animation = ActorAnimation();
animation._name = reader.readString("name");
print("NAME ${animation._name}");
animation._fps = reader.readUint8("fps");
animation._duration = reader.readFloat32("duration");
animation._isLooping = reader.readBool("isLooping");

reader.openArray("keyed");
int numKeyedComponents = reader.readUint16Length();

// We distinguish between animated and triggered components as ActorEvents
// are currently only used to trigger events and don't need the full animation
// cycle. This lets them optimize them out of the regular animation cycle.
// We distinguish between animated and triggered components as ActorEvents
// are currently only used to trigger events and don't need the full
// animation cycle. This lets them optimize them out of the regular animation
// cycle.
int animatedComponentCount = 0;
int triggerComponentCount = 0;

Expand Down Expand Up @@ -468,142 +450,3 @@ class ActorAnimation {
return animation;
}
}

// class ActorAnimationInstance
// {
// Actor _actor;
// ActorAnimation _animation;
// double _time;
// double _min;
// double _max;
// double _range;
// bool loop;

// event EventHandler<AnimationEventArgs> AnimationEvent;

// ActorAnimationInstance(Actor actor, ActorAnimation animation)
// {
// _actor = actor;
// _animation = animation;
// _time = 0.0;
// _min = 0.0;
// _max = animation.Duration;
// _range = _max - _min;
// loop = animation.IsLooping;
// }

// double get minTime
// {
// return _min;
// }

// double get maxTime
// {
// return _max;
// }

// double get time
// {
// return _time;
// }

// set time(double value)
// {
// double delta = value - _time;
// double time = _time + (delta % _range);

// if(time < _min)
// {
// if(loop)
// {
// time = _max - (_min - time);
// }
// else
// {
// time = _min;
// }
// }
// else if(time > _max)
// {
// if(loop)
// {
// time = _min + (time - _max);
// }
// else
// {
// time = _max;
// }
// }
// _time = time;
// }

// void advance(float seconds)
// {
// List<AnimationEventArgs> triggeredEvents = new List<AnimationEventArgs>();
// float time = _time;
// time += seconds % _range;
// if(time < _min)
// {
// if(loop)
// {
// _animation.TriggerEvents(_actor.components, time, _time, triggeredEvents);
// time = _max - (_min - time);
// _animation.TriggerEvents(_actor.components, time, _max, triggeredEvents);
// }
// else
// {
// time = _min;
// if(_time != time)
// {
// _animation.TriggerEvents(_actor.components, _min, _time, triggeredEvents);
// }
// }
// }
// else if(time > _max)
// {
// if(loop)
// {
// _animation.TriggerEvents(_actor.components, time, _time, triggeredEvents);
// time = _min + (time - _max);
// _animation.TriggerEvents(_actor.components, _min-0.001f, time, triggeredEvents);
// }
// else
// {
// time = _max;
// if(_time != time)
// {
// _animation.TriggerEvents(_actor.components, _time, _max, triggeredEvents);
// }
// }
// }
// else if(time > _time)
// {
// _animation.TriggerEvents(_actor.components, _time, time, triggeredEvents);
// }
// else
// {
// _animation.TriggerEvents(_actor.components, time, _time, triggeredEvents);
// }

// for(AnimationEventArgs ev in triggeredEvents)
// {
// if (AnimationEvent != null)
// {
// AnimationEvent(this, ev);
// }
// _actor.OnAnimationEvent(ev);
// }
// /*for(var i = 0; i < triggeredEvents.length; i++)
// {
// var event = triggeredEvents[i];
// this.dispatch("animationEvent", event);
// _actor.dispatch("animationEvent", event);
// }*/
// _time = time;
// }

// void Apply(float mix)
// {
// _animation.apply(_time, _actor, mix);
// }
// }
3 changes: 2 additions & 1 deletion flare_dart/lib/animation/interpolation/cubic_ease.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ double getSlope(double aT, double aA1, double aA2) {
(3.0 * aA1);
}

double newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
double newtonRaphsonIterate(double aX, double aGuessT, double mX1, double mX2) {
for (int i = 0; i < NewtonIterations; ++i) {
double currentSlope = getSlope(aGuessT, mX1, mX2);
if (currentSlope == 0.0) {
Expand Down Expand Up @@ -113,6 +113,7 @@ class Cubic extends CubicEase {
}
}

@override
double ease(double mix) {
return calcBezier(getT(mix), y1, y2);
}
Expand Down
3 changes: 2 additions & 1 deletion flare_dart/lib/animation/interpolation/hold.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import "./interpolator.dart";

class HoldInterpolator extends Interpolator {
static get instance {
static Interpolator get instance {
return _instance;
}

@override
double getEasedMix(double mix) {
return 0.0;
}
Expand Down
3 changes: 2 additions & 1 deletion flare_dart/lib/animation/interpolation/linear.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import "./interpolator.dart";

class LinearInterpolator extends Interpolator {
static get instance {
static Interpolator get instance {
return _instance;
}

@override
double getEasedMix(double mix) {
return mix;
}
Expand Down
Loading

0 comments on commit 8f04aa6

Please sign in to comment.