Permalink
Browse files

Don't animate properties that are equal

  • Loading branch information...
koenbok committed May 15, 2014
1 parent 216a271 commit e86abfa3d8071493cd85f42b97c8d95b2323d751
Showing with 25 additions and 8 deletions.
  1. +10 −3 extras/CactusFramer/static/app.coffee
  2. +14 −4 framer/Animation.coffee
  3. +1 −1 framer/Layer.coffee
@@ -4,7 +4,14 @@ layerA = new Layer
midX: 200
clip: true
Utils.labelLayer layerA, "Hello"
layerA.states.add "hello", {x:500}
layerA.draggable.enabled = true
layerA.draggable.speedY = 0.1
layerA.y = 300
layerA.states.add "other", layerA.properties
layerA.states.switchInstant "hello"
layerA.states.switch "other"
# console.log typeof layerA.properties.visible
@@ -63,8 +63,14 @@ class exports.Animation extends EventEmitter
@_repeatCounter = @options.repeat
_filterAnimatableProperties: (properties) ->
delete properties.image
properties
animatableProperties = {}
# Only animate numeric properties for now
for k, v of properties
animatableProperties[k] = v if _.isNumber v
animatableProperties
_currentState: ->
_.pick @options.layer, _.keys(@options.properties)
@@ -124,13 +130,17 @@ class exports.Animation extends EventEmitter
target = @options.layer
stateA = @_currentState()
stateB = @options.properties
stateB = {}
# Filter out the properties that are equal
for k, v of @options.properties
stateB[k] = v if stateA[k] != v
if _.isEqual stateA, stateB
console.warn "Nothing to animate"
console.debug "Animation.start"
console.debug "\t#{k}: #{stateA[k]} -> #{stateB[k]}" for k, v of stateB
console.debug "\t#{k}: #{stateA[k]} -> #{stateB[k]}" for k, v of stateB
@_animator.on "start", => @emit "start"
@_animator.on "stop", => @emit "stop"
@@ -26,7 +26,7 @@ layerProperty = (name, cssProperty, fallback, validator, set) ->
# console.log "Missing validator for Layer.#{name}", validator
if validator(value) is false
throw Error "type #{typeof value} is not valid for a Layer.#{name} property"
throw Error "value '#{value}' of type #{typeof value} is not valid for a Layer.#{name} property"
@_setPropertyValue name, value
@style[cssProperty] = LayerStyle[cssProperty](@)

1 comment on commit e86abfa

@koenbok

This comment has been minimized.

Owner

koenbok commented on e86abfa May 15, 2014

Also, don't animate non-numeric properties.

Please sign in to comment.