import { Observer } from './' ; import { Delay , Task , TaskQueue } from '../helpers' ; export class Transition extends Observer { private _domElement : HTMLElement ; private _taskQueue : TaskQueue ; constructor ( taskQueue ) { super ( ) ; this . _acceptedTasks = new Set ( [ 'scene-transition-start' , 'scene-transition-end' , 'start-game' ] ) ; this . _domElement = document . getElementById ( 'transition' ) ; this . _taskQueue = taskQueue ; } handleUpdate ( { name } ) { switch ( name ) { case 'scene-transition-start' : this . handleSceneTransitionStart ( ) ; break ; case 'scene-transition-end' : this . handleSceneTransitionEnd ( ) ; break ; case 'start-game' : this . handleStartGame ( ) ; break ; } } handleStartGame ( ) { this . hide ( ) ; } async handleSceneTransitionStart ( ) { this . show ( ) ; await Delay . delay ( 1000 ) ; this . _taskQueue . addTask ( new Task ( 'scene-transition-end' , null ) ) ; } handleSceneTransitionEnd ( ) { this . hide ( ) ; } show ( ) { this . _domElement . style . opacity = '1' ; } hide ( ) { this . _domElement . style . opacity = '0' ; } }