import { ITimelineModel } from '../core/types' ; import { loopOff } from '../core/timeloop' ; import { S_PLAYING , _ } from '../utils/constants' ; import { inRange , minMax , flr } from '../utils/math' ; import { all } from '../utils/lists' ; import { setup } from './setup' ; import { UPDATE } from '../actions' ; import { IReducer , IReducerContext } from '../core/types' ; export const update = ( model , _data , ctx ) => { if ( model . players === _ ) { setup ( model ) ; } const isPlaying = model . state === S_PLAYING ; const time = model . time ; if ( ! isPlaying ) { loopOff ( model . id ) ; } all ( model . players , player => { const from = player . from ; const to = player . to ; const isActive = isPlaying && inRange ( flr ( time ) , from , to ) ; const offset = minMax ( ( time - from ) / ( to - from ) , 0 , 1 ) ; player . update ( offset , model . rate , isActive ) ; } ) ; ctx . trigger ( UPDATE ) ; } ;