1 | <?php |
||
9 | class Keyframe |
||
10 | { |
||
11 | use StringLength, ParserImporter, UtilImporter; |
||
12 | |||
13 | /** |
||
14 | * Get the enter keyframes for the desired direction |
||
15 | * |
||
16 | * @param array $lines |
||
17 | * @param string $direction |
||
18 | * |
||
19 | * @return array |
||
20 | */ |
||
21 | 40 | public function enterFrom($lines, $direction) |
|
25 | |||
26 | /** |
||
27 | * Get the exit keyframes for the desired direction |
||
28 | * |
||
29 | * @param array $lines |
||
30 | * @param string $direction |
||
31 | * |
||
32 | * @return array |
||
33 | */ |
||
34 | 56 | public function exitTo($lines, $direction) |
|
47 | |||
48 | /** |
||
49 | * Get scroll keyframes |
||
50 | * |
||
51 | * @param array $lines |
||
52 | * @param string $enter_from |
||
53 | * @param string $exit_to |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | 20 | public function scroll($lines, $enter_from, $exit_to) |
|
66 | |||
67 | /** |
||
68 | * Get the line parser for the direction |
||
69 | * |
||
70 | * @param string $direction |
||
71 | * @return string |
||
72 | */ |
||
73 | 56 | protected function getLineMethod($direction) |
|
77 | |||
78 | /** |
||
79 | * Adjust the array of lines if necessary |
||
80 | * |
||
81 | * @param array $lines |
||
82 | * @param string $direction |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | 56 | protected function adjustLines(array $lines, $direction) |
|
96 | |||
97 | /** |
||
98 | * Pad the array of lines for "right" animation |
||
99 | * |
||
100 | * @param array $lines |
||
101 | * @return array |
||
102 | */ |
||
103 | 20 | protected function adjustRightLines(array $lines) |
|
107 | |||
108 | /** |
||
109 | * Pad the array of lines for "left" animation |
||
110 | * |
||
111 | * @param array $lines |
||
112 | * @return array |
||
113 | */ |
||
114 | 20 | protected function adjustLeftLines(array $lines) |
|
118 | |||
119 | /** |
||
120 | * Get the keyframes appropriate for the animation direction |
||
121 | * |
||
122 | * @param string $direction |
||
123 | * @param array $lines |
||
124 | * @param string $line_method |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | 56 | protected function getDirectionFrames($direction, array $lines, $line_method) |
|
129 | { |
||
130 | $mapping = [ |
||
131 | 56 | 'exitHorizontalFrames' => ['left', 'right'], |
|
132 | 'exitVerticalFrames' => ['top', 'bottom'], |
||
133 | ]; |
||
134 | |||
135 | 56 | foreach ($mapping as $method => $directions) { |
|
136 | 56 | if (in_array($direction, $directions)) { |
|
137 | 56 | return $this->$method($lines, $line_method); |
|
138 | } |
||
139 | } |
||
140 | |||
141 | // Fail gracefully, simply return an array |
||
142 | return []; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Create horizontal exit animation keyframes for the art |
||
147 | * |
||
148 | * @param array $lines |
||
149 | * @param string $line_method |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | 28 | protected function exitHorizontalFrames(array $lines, $line_method) |
|
154 | { |
||
155 | 28 | $keyframes = []; |
|
156 | 28 | $length = mb_strlen($lines[0]); |
|
157 | |||
158 | 28 | for ($i = $length; $i > 0; $i--) { |
|
159 | 28 | $keyframes[] = $this->getHorizontalKeyframe($lines, $i, $line_method, $length); |
|
160 | } |
||
161 | |||
162 | 28 | return $keyframes; |
|
163 | } |
||
164 | |||
165 | /** |
||
166 | * Get the keyframe for a horizontal animation |
||
167 | * |
||
168 | * @param array $lines |
||
169 | * @param int $frame_number |
||
170 | * @param string $line_method |
||
171 | * @param int $length |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | 28 | protected function getHorizontalKeyframe(array $lines, $frame_number, $line_method, $length) |
|
176 | { |
||
177 | 28 | $keyframe = []; |
|
178 | |||
179 | 28 | foreach ($lines as $line) { |
|
180 | 28 | $keyframe[] = $this->$line_method($line, $frame_number, $length); |
|
181 | } |
||
182 | |||
183 | 28 | return $keyframe; |
|
184 | } |
||
185 | |||
186 | /** |
||
187 | * Create vertical exit animation keyframes for the art |
||
188 | * |
||
189 | * @param array $lines |
||
190 | * @param string $line_method |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | 28 | protected function exitVerticalFrames(array $lines, $line_method) |
|
195 | { |
||
196 | 28 | $keyframes = []; |
|
197 | 28 | $line_count = count($lines); |
|
198 | |||
199 | 28 | for ($i = $line_count - 1; $i >= 0; $i--) { |
|
200 | 28 | $keyframes[] = $this->$line_method($lines, $line_count, $i); |
|
201 | } |
||
202 | |||
203 | 28 | return $keyframes; |
|
204 | } |
||
205 | |||
206 | /** |
||
207 | * Get the current line as it is exiting left |
||
208 | * |
||
209 | * @param string $line |
||
210 | * @param int $frame_number |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | 20 | protected function currentLeftLine($line, $frame_number) |
|
218 | |||
219 | |||
220 | /** |
||
221 | * Get the current line as it is exiting right |
||
222 | * |
||
223 | * @param string $line |
||
224 | * @param int $frame_number |
||
225 | * @param int $length |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | 20 | protected function currentRightLine($line, $frame_number, $length) |
|
233 | |||
234 | /** |
||
235 | * Slice off X number of lines from the bottom and fill the rest with empty strings |
||
236 | * |
||
237 | * @param array $lines |
||
238 | * @param integer $total_lines |
||
239 | * @param integer $current |
||
240 | * |
||
241 | * @return array |
||
242 | */ |
||
243 | 16 | protected function currentTopLine($lines, $total_lines, $current) |
|
249 | |||
250 | /** |
||
251 | * Slice off X number of lines from the top and fill the rest with empty strings |
||
252 | * |
||
253 | * @param array $lines |
||
254 | * @param integer $total_lines |
||
255 | * @param integer $current |
||
256 | * |
||
257 | * @return array |
||
258 | */ |
||
259 | 20 | protected function currentBottomLine($lines, $total_lines, $current) |
|
265 | } |
||
266 |