@@ -249,17 +249,59 @@ class Editor extends Component {
249
249
return 2.0 ;
250
250
}
251
251
252
+ animationType ( ) {
253
+ const type = this . phraseBook [ '%preamble' ] . animationType ;
254
+ if ( type !== undefined ) return type ;
255
+ else return "bounce" ;
256
+ }
257
+
252
258
onDoFrame ( ) {
253
259
if ( this . state . playing ) {
254
- try {
255
- const elapsedSeconds = ( Date . now ( ) - this . startTime ) / 1000.0 ;
256
- const durationSeconds = this . durationSeconds ( ) ;
257
- const t = ( elapsedSeconds / durationSeconds ) % 1.0 ;
258
- const result = generateString ( this . phraseBook , 'root' , { } , this . state . seed , t ) ;
259
- this . setState ( { frame : this . state . frame + 1 , result : result , debugOutput : '' } ) ;
260
- window . requestAnimationFrame ( this . onDoFrame . bind ( this ) ) ;
261
- } catch ( e ) {
262
- this . setState ( { frame : 0 , playing : false , debugOutput : e . message } ) ;
260
+ const animationType = this . animationType ( ) ;
261
+
262
+ switch ( animationType ) {
263
+ case "once" :
264
+ try {
265
+ const elapsedSeconds = ( Date . now ( ) - this . startTime ) / 1000.0 ;
266
+ const durationSeconds = this . durationSeconds ( ) ;
267
+ const t = ( elapsedSeconds / durationSeconds ) % 1.0 ;
268
+
269
+ if ( durationSeconds <= elapsedSeconds ) return false ;
270
+ else {
271
+ const result = generateString ( this . phraseBook , 'root' , { } , this . state . seed , t ) ;
272
+ this . setState ( { frame : this . state . frame + 1 , result : result , debugOutput : '' } ) ;
273
+ window . requestAnimationFrame ( this . onDoFrame . bind ( this ) ) ;
274
+ }
275
+ } catch ( e ) {
276
+ this . setState ( { frame : 0 , playing : false , debugOutput : e . message } ) ;
277
+ }
278
+ break ;
279
+
280
+ case "linear" :
281
+ try {
282
+ const elapsedSeconds = ( Date . now ( ) - this . startTime ) / 1000.0 ;
283
+ const durationSeconds = this . durationSeconds ( ) ;
284
+ const t = ( elapsedSeconds / durationSeconds ) % 1.0 ;
285
+ const result = generateString ( this . phraseBook , 'root' , { } , this . state . seed , t ) ;
286
+ this . setState ( { frame : this . state . frame + 1 , result : result , debugOutput : '' } ) ;
287
+ window . requestAnimationFrame ( this . onDoFrame . bind ( this ) ) ;
288
+ } catch ( e ) {
289
+ this . setState ( { frame : 0 , playing : false , debugOutput : e . message } ) ;
290
+ }
291
+ break ;
292
+
293
+ case "bounce" :
294
+ try {
295
+ const elapsedSeconds = ( Date . now ( ) - this . startTime ) / 1000.0 ;
296
+ const durationSeconds = this . durationSeconds ( ) ;
297
+ const t = ( elapsedSeconds / durationSeconds ) % 1.0 ;
298
+ const result = generateString ( this . phraseBook , 'root' , { } , this . state . seed , t ) ;
299
+ this . setState ( { frame : this . state . frame + 1 , result : result , debugOutput : '' } ) ;
300
+ window . requestAnimationFrame ( this . onDoFrame . bind ( this ) ) ;
301
+ } catch ( e ) {
302
+ this . setState ( { frame : 0 , playing : false , debugOutput : e . message } ) ;
303
+ }
304
+ break ;
263
305
}
264
306
}
265
307
}
0 commit comments