Class: Plushie::Animation::Sequence

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/animation/sequence.rb

Overview

Renderer-side sequential animation chain.

Chains multiple transitions and springs that execute one after another on the same prop. Each step's +from:+ defaults to the previous step's final value if not specified.

Examples:

container("item",
  opacity: Sequence.build([
    Transition.build(200, to: 1.0, from: 0.0),
    Transition.loop(800, to: 0.7, from: 1.0, cycles: 3),
    Transition.build(300, to: 0.0)
  ]))

With completion event

container("item",
  opacity: Sequence.build([
    Transition.build(200, to: 1.0, from: 0.0),
    Transition.build(300, to: 0.0)
  ], on_complete: :fade_cycle_done))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps:, on_complete: nil) ⇒ Sequence

Returns a new instance of Sequence.

Parameters:

  • steps (Array<Transition, Spring>)

    animation steps

  • on_complete (Symbol, nil) (defaults to: nil)

    event tag fired on sequence completion



29
30
31
# File 'lib/plushie/animation/sequence.rb', line 29

def initialize(steps:, on_complete: nil)
  super
end

Instance Attribute Details

#on_completeObject (readonly)

Returns the value of attribute on_complete

Returns:

  • (Object)

    the current value of on_complete



26
27
28
# File 'lib/plushie/animation/sequence.rb', line 26

def on_complete
  @on_complete
end

#stepsObject (readonly)

Returns the value of attribute steps

Returns:

  • (Object)

    the current value of steps



26
27
28
# File 'lib/plushie/animation/sequence.rb', line 26

def steps
  @steps
end

Class Method Details

.build(steps, **opts) ⇒ Sequence

Create a sequence from a list of transition/spring steps.

Parameters:

  • steps (Array<Transition, Spring>)

    animation steps

  • opts (Hash)

    sequence options

Options Hash (**opts):

  • :on_complete (Symbol)

    event tag on completion

Returns:



49
50
51
52
53
54
55
# File 'lib/plushie/animation/sequence.rb', line 49

def self.build(steps, **opts)
  unless steps.is_a?(Array) && steps.all? { |s| s.respond_to?(:to_wire) }
    raise ArgumentError, "sequence steps must be an Array of Transition/Spring descriptors"
  end

  new(steps: steps, **opts)
end

Instance Method Details

#to_wireHash

Returns wire-ready descriptor map.

Returns:

  • (Hash)

    wire-ready descriptor map



34
35
36
37
38
39
40
41
# File 'lib/plushie/animation/sequence.rb', line 34

def to_wire
  h = {
    type: "sequence",
    steps: steps.map(&:to_wire)
  }
  h[:on_complete] = on_complete.to_s if on_complete
  h
end