import { Movie } from '../movie' ; import { Base } from './base' ; import { Visual } from '../layer' ; export interface StackOptions { effects : Base [ ] ; } /**
 * A sequence of effects to apply, treated as one effect. This can be useful
 * for defining reused effect sequences as one effect.
 */ export class Stack extends Base { readonly effects : Base [ ] ; private _effectsBack : Base [ ] ; constructor ( options ) { super ( ) ; this . _effectsBack = [ ] ; this . effects = new Proxy ( this . _effectsBack , { deleteProperty : function ( target , property ) : boolean { const value = target [ property ] ; value . detach ( ) ; delete target [ property ] ; return true ; } , set : function ( target , property , value ) : boolean { if ( ! isNaN ( Number ( property ) ) ) { if ( target [ property ] ) target [ property ] . detach ( ) ; value . attach ( this . _target ) ; } target [ property ] = value ; return true ; } } ) ; options . effects . forEach ( effect => this . effects . push ( effect ) ) ; } attach ( movie ) { super . attach ( movie ) ; this . effects . filter ( effect => ! ! effect ) . forEach ( effect => { effect . detach ( ) ; effect . attach ( movie ) ; } ) ; } detach ( ) { super . detach ( ) ; this . effects . filter ( effect => ! ! effect ) . forEach ( effect => { effect . detach ( ) ; } ) ; } apply ( target , reltime ) { for ( let i = 0 ; i < this . effects . length ; i ++ ) { const effect = this . effects [ i ] ; if ( ! effect ) continue ; effect . apply ( target , reltime ) ; } } param effect addEffect ( effect ) { this . effects . push ( effect ) ; return this ; } }