import { ArgEvent } from './Events' ; import { ProgressStatus , LoadingProgressCallback , } from '@casual-simulation/causal-trees' ; import { lerp } from './utils' ; export class LoadingProgress implements ProgressStatus { /**
     * This event is fired any time a value in this loading progress object changes.
     */ public onChanged : ArgEvent < LoadingProgress > = new ArgEvent < LoadingProgress > ( ) ; private _show : boolean = true ; private _progress : number = 0 ; private _status : string = '' ; private _error : string = '' ; constructor ( ) { } /**
     * Should a loading progress screen be shown?
     */ get show ( ) : boolean { return this . _show ; } set show ( val ) { this . _show = val ; this . _emitChanged ( ) ; } /**
     * Current progress of the load (0-100).
     */ get progress ( ) : number { return this . _progress ; } set progress ( val ) { this . _progress = val ; this . _emitChanged ( ) ; } /**
     * Current status message of the load.
     */ get status ( ) : string { return this . _status ; } set status ( val ) { this . _status = val ; this . _emitChanged ( ) ; } /**
     * Messsage to show when something bad occurs while loading (null for no error).
     */ get error ( ) : string { return this . _error ; } set error ( val ) { this . _error = val ; this . _emitChanged ( ) ; } get progressPercent ( ) { return this . progress / 100 ; } get message ( ) { return this . status ; } param progress param status param error set ( progress , status , error ) { this . _progress = getOptionalValue ( progress , 0 ) ; this . _status = getOptionalValue ( status , '' ) ; this . _error = getOptionalValue ( error , '' ) ; this . _emitChanged ( ) ; } param start param end createNestedCallback ( start , end ) { return ( status ) => { let percent = status . progressPercent ? lerp ( start , end , status . progressPercent ) : this . progress ; let message = status . message ? status . message : this . status ; let error = status . error ? status . error : this . error ; this . set ( percent , message , error ) ; } ; } /**
     * Clone this object and all its current data.
     */ clone ( ) { let clone = new LoadingProgress ( ) ; clone . _show = this . _show ; clone . _progress = this . _progress ; clone . _status = this . _status ; clone . _error = this . _error ; return clone ; } private _emitChanged ( ) { this . onChanged . invoke ( this ) ; } } function getOptionalValue ( obj , defaultValue ) { return obj !== undefined && obj !== null ? obj : defaultValue ; }