1 | <?php |
||
9 | class Animation extends DynamicTerminalObject |
||
10 | { |
||
11 | use Art; |
||
12 | |||
13 | /** |
||
14 | * @var \League\CLImate\TerminalObject\Helper\Sleeper $sleeper |
||
15 | */ |
||
16 | protected $sleeper; |
||
17 | |||
18 | /** |
||
19 | * @var \League\CLImate\TerminalObject\Dynamic\Animation\Keyframe $keyframes |
||
20 | */ |
||
21 | protected $keyframes; |
||
22 | |||
23 | 60 | public function __construct($art, Sleeper $sleeper = null, Keyframe $keyframes = null) |
|
33 | |||
34 | /** |
||
35 | * Run a basic animation |
||
36 | */ |
||
37 | 4 | public function run() |
|
38 | { |
||
39 | 4 | $files = $this->artDir($this->art); |
|
40 | 4 | $animation = []; |
|
41 | |||
42 | 4 | foreach ($files as $file) { |
|
43 | 4 | $animation[] = $this->parse($file); |
|
44 | } |
||
45 | |||
46 | 4 | $this->animate($animation); |
|
47 | 4 | } |
|
48 | |||
49 | /** |
||
50 | * Set the speed of the animation based on a percentage |
||
51 | * (50% slower, 200% faster, etc) |
||
52 | * |
||
53 | * @param int|float $percentage |
||
54 | * |
||
55 | * @return \League\CLImate\TerminalObject\Dynamic\Animation |
||
56 | */ |
||
57 | public function speed($percentage) |
||
63 | |||
64 | /** |
||
65 | * Scroll the art |
||
66 | * |
||
67 | * @param string $direction |
||
68 | * @return bool |
||
69 | */ |
||
70 | 20 | public function scroll($direction = 'right') |
|
86 | |||
87 | /** |
||
88 | * Animate the art exiting the screen |
||
89 | * |
||
90 | * @param string $direction top|bottom|right|left |
||
91 | */ |
||
92 | 16 | public function exitTo($direction) |
|
98 | |||
99 | /** |
||
100 | * Animate the art entering the screen |
||
101 | * |
||
102 | * @param string $direction top|bottom|right|left |
||
103 | */ |
||
104 | 20 | public function enterFrom($direction) |
|
110 | |||
111 | 20 | protected function getScrollDirectionMapping() |
|
112 | { |
||
113 | return [ |
||
114 | 20 | 'left' => 'right', |
|
115 | 'right' => 'left', |
||
116 | 'top' => 'bottom', |
||
117 | 'bottom' => 'top', |
||
118 | 'up' => 'bottom', |
||
119 | 'down' => 'top', |
||
120 | ]; |
||
121 | } |
||
122 | |||
123 | 56 | protected function getLines() |
|
127 | |||
128 | /** |
||
129 | * @param \League\CLImate\TerminalObject\Helper\Sleeper $sleeper |
||
130 | */ |
||
131 | 60 | protected function setSleeper($sleeper = null) |
|
135 | |||
136 | /** |
||
137 | * @param League\CLImate\TerminalObject\Dynamic\Animation\Keyframe $keyframes |
||
138 | */ |
||
139 | 60 | protected function setKeyFrames($keyframes) |
|
143 | |||
144 | /** |
||
145 | * Set up the necessary properties on the Keyframe class |
||
146 | */ |
||
147 | 56 | protected function setupKeyframes() |
|
152 | |||
153 | /** |
||
154 | * Animate the given keyframes |
||
155 | * |
||
156 | * @param array $keyframes Array of arrays |
||
157 | */ |
||
158 | 60 | protected function animate(array $keyframes) |
|
168 | |||
169 | /** |
||
170 | * Write the current keyframe to the terminal, line by line |
||
171 | * |
||
172 | * @param array $lines |
||
173 | * @param integer $count |
||
174 | */ |
||
175 | 60 | protected function writeKeyFrame(array $lines, $count) |
|
182 | |||
183 | /** |
||
184 | * Format the line to re-write previous lines, if necessary |
||
185 | * |
||
186 | * @param string $line |
||
187 | * @param integer $key |
||
188 | * @param integer $last_frame_count |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | 60 | protected function getLineFormatted($line, $key, $last_frame_count) |
|
213 | } |
||
214 |