Class: Yuki::Animation::TimedAnimation
- Defined in:
- scripts/01100 Yuki/00100 Animation/00100 Animation.rb
Overview
Class calculating time offset for animation.
This class also manage parallel & sub animation. Example :
(TimedAnimation.new(1) | TimedAnimation.new(2) > TimedAnimation.new(3)).root
# Is equivalent to
TimedAnimation.new(1).parallel_play(TimedAnimation.new(2)).play_before(TimedAnimation.new(3)).root
# Which is equivalent to : play 1 & 2 in parallel and then play 3
# Note that if 2 has sub animation, its sub animation has to finish in order to see animation 3
Direct Known Subclasses
Battle::Visual::FakeHPAnimation, Command, Dim2Animation, Dim2AnimationDiscreet, DiscreetAnimation, FullyResolvedAnimation, MessageLocked, ScalarAnimation, SpriteSheetAnimation, TimedLoopAnimation
Instance Attribute Summary collapse
-
#begin_time ⇒ Time?
readonly
Get the begin time of the animation (if started).
-
#end_time ⇒ Time?
readonly
Get the end time of the animation (if started).
-
#parallel_animations ⇒ Array<TimedAnimation>
readonly
Animation playing in parallel.
-
#root ⇒ TimedAnimation
The root animation (to retreive the right animation to play when building animation using operators).
-
#sub_animation ⇒ TimedAnimation?
readonly
Animation that plays after.
-
#time_source ⇒ #call?
readonly
Get the time source of the animation (if started).
Instance Method Summary collapse
-
#done? ⇒ Boolean
Indicate if the animation is done.
-
#in_parallel_of(other) ⇒ TimedAnimation
(also: #>>)
Add this animation in parallel of another animation.
-
#initialize(time_to_process, distortion = :UNICITY_DISTORTION, time_source = :GENERIC_TIME_SOURCE) ⇒ TimedAnimation
constructor
Create a new TimedAnimation.
-
#parallel_add(other) ⇒ self
(also: #<<, #|, #parallel_play)
Add a parallel animation.
-
#play_before(other) ⇒ TimedAnimation
(also: #>)
Add a sub animation.
-
#resolver=(resolver)
Define the resolver (and transmit it to all the childs / parallel).
-
#start(begin_offset = 0)
Start the animation (initialize it).
-
#update
Update the animation internal time and call update_internal with a parameter between 0 & 1 indicating the progression of the animation.
Constructor Details
#initialize(time_to_process, distortion = :UNICITY_DISTORTION, time_source = :GENERIC_TIME_SOURCE) ⇒ TimedAnimation
Create a new TimedAnimation
61 62 63 64 65 66 67 68 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 61 def initialize(time_to_process, distortion = :UNICITY_DISTORTION, time_source = :GENERIC_TIME_SOURCE) @time_to_process = time_to_process.to_f @distortion_param = distortion @time_source_param = time_source @sub_animation = nil @parallel_animations = [] @root = self # We make self as default root so the animations will always have a root end |
Instance Attribute Details
#begin_time ⇒ Time? (readonly)
Get the begin time of the animation (if started)
49 50 51 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 49 def begin_time @begin_time end |
#end_time ⇒ Time? (readonly)
Get the end time of the animation (if started)
52 53 54 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 52 def end_time @end_time end |
#parallel_animations ⇒ Array<TimedAnimation> (readonly)
Returns animation playing in parallel.
41 42 43 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 41 def parallel_animations @parallel_animations end |
#root ⇒ TimedAnimation
Returns the root animation (to retreive the right animation to play when building animation using operators).
46 47 48 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 46 def root @root end |
#sub_animation ⇒ TimedAnimation? (readonly)
Returns animation that plays after.
43 44 45 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 43 def sub_animation @sub_animation end |
#time_source ⇒ #call? (readonly)
Get the time source of the animation (if started)
55 56 57 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 55 def time_source @time_source end |
Instance Method Details
#done? ⇒ Boolean
should always be called after start
Indicate if the animation is done
91 92 93 94 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 91 def done? private_done? && @parallel_animations.all?(&:done?) && (@sub_animation ? @sub_animation.done? : true) && @played_until_end end |
#in_parallel_of(other) ⇒ TimedAnimation Also known as: >>
Add this animation in parallel of another animation
133 134 135 136 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 133 def in_parallel_of(other) other.parallel_add(self) return other end |
#parallel_add(other) ⇒ self Also known as: <<, |, parallel_play
Add a parallel animation
121 122 123 124 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 121 def parallel_add(other) @parallel_animations << other return self end |
#play_before(other) ⇒ TimedAnimation Also known as: >
Add a sub animation
143 144 145 146 147 148 149 150 151 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 143 def play_before(other) if @sub_animation @sub_animation.play_before(other) else @sub_animation = other end other.root = root return other end |
#resolver=(resolver)
Define the resolver (and transmit it to all the childs / parallel)
157 158 159 160 161 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 157 def resolver=(resolver) @resolver = resolver @sub_animation&.resolver = resolver @parallel_animations.each { |animation| animation.resolver = resolver } end |
#start(begin_offset = 0)
Start the animation (initialize it)
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 72 def start(begin_offset = 0) # Resolve the distortion & time source @distortion = DISTORTIONS[@distortion_param] || resolve(@distortion_param) @time_source = TIME_SOURCES[@time_source_param] || resolve(@time_source_param) # @type [Time] time when the animation started @begin_time = @time_source.call + begin_offset # @type [Time] time when the animation ends @end_time = @begin_time + @time_to_process # Start all the parallel animation @parallel_animations.each { |animation| animation.start(begin_offset) } # Start the sub animation @sub_animation&.start(begin_offset + @time_to_process) # Boolean telling if the animation has been processed until the end (to prevent some display error) @played_until_end = false end |
#update
should always be called after start
Update the animation internal time and call update_internal with a parameter between 0 & 1 indicating the progression of the animation
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'scripts/01100 Yuki/00100 Animation/00100 Animation.rb', line 99 def update return unless private_began? return if done? @parallel_animations.each(&:update) # Update the sub animation if the current animation is actually done if private_done? unless @played_until_end update_internal(@distortion.call(1)) @played_until_end = true end return unless @parallel_animations.all?(&:done?) return @sub_animation&.update end # Calculate the time progression value, apply it the distortion and send it to update_internal update_internal(@distortion.call((@time_source.call - @begin_time) / @time_to_process)) end |