// import {EventEmitter, Injectable, OnInit} from '@angular/core'; // import {PreloaderOxService, ScreenTypeOx} from 'ox-core'; // import {GameActionsService} from './game-actions.service'; // import {VideoService} from './video.service'; // export type ScreenOxTags = 'video-ox' | // @Injectable({ // providedIn: 'root' // }) // export class ScreenOxService implements OnInit { // public screensReady: Map; // public parentScreen: HTMLElement; // // private mainScreen: { element: HTMLElement, type: ScreenTypeOx }; // private popUpScreen: { element: HTMLElement, type: ScreenTypeOx }; // // public screenChanges: EventEmitter = new EventEmitter(); // // constructor(protected preloader: PreloaderOxService, private gameActions: GameActionsService, // private videoService: VideoService) { // this.gameActions.startGame.subscribe(e => { // this.showGame(); // }); // this.gameActions.resumeGame.subscribe(e => { // this.resumeGame(); // }); // this.gameActions.restartGame.subscribe(e => { // this.showGame(); // }); // this.gameActions.goToLevelMenu.subscribe(() => { // this.showLevelMenu(); // }); // this.gameActions.goToGamePreview.subscribe(() => { // this.showGamePreview(); // }); // this.gameActions.goToResults.subscribe(() => { // this.showGameComplete(); // }); // this.gameActions.goToInGameMenu.subscribe(() => { // this.showInGameMenu(); // }); // this.gameActions.showInstructive.subscribe(() => { // this.showInstructive(); // }); // // this.videoService.playVideo.subscribe((asPopUp: boolean) => { // this.showVideo(asPopUp); // }); // // this.screensReady = new Map(); // [ScreenTypeOx.Loading, ScreenTypeOx.GamePreview, ScreenTypeOx.Game, ScreenTypeOx.InGameMenu, ScreenTypeOx.GameComplete, // ScreenTypeOx.Video, ScreenTypeOx.ToBeContinue].forEach(aScreen => this.screensReady.set(aScreen, false)); // this.setScreenReadySubscription(); // } // // public ngOnInit(): void { // if (!this.parentScreen) { // throw new Error('Screen Service needs a parent screen to be set'); // } // } // // public isShowingScreen(type: ScreenTypeOx): boolean { // if (this.popUpScreen) { // return this.popUpScreen.type === type; // } else { // return this.mainScreen.type === type; // } // } // // public isShowingMainScreen(type: ScreenTypeOx): boolean { // return this.mainScreen.type === type; // } // // protected setScreenReadySubscription() { // // todo ver cuando hacer unsubscribe // this.preloader.screenReady.subscribe(screen => { // this.screensReady.set(screen, true); // }); // } // // public showLoading() { // this.changeMainScreen('loading-assets', ScreenTypeOx.Loading); // } // // public showNotInWumboxScreen() { // this.changeMainScreen('not-in-wumbox', ScreenTypeOx.NotInWumbox); // } // // public showInitialScreen() { // if (this.isDefined('game-preview')) { // this.showGamePreview(); // } else if (this.isDefined('level-menu')) { // this.showLevelMenu(); // } else { // this.showGame(); // } // } // // private changeMainScreen(tag: string, type: ScreenTypeOx) { // const element = document.createElement(tag); // if (this.mainScreen) { // this.parentScreen.removeChild(this.mainScreen.element); // } else { // this.mainScreen = {element: undefined, type: undefined}; // } // this.mainScreen.element = element; // this.mainScreen.type = type; // this.parentScreen.appendChild(this.mainScreen.element); // if (this.popUpScreen) { // this.removePopUp(this.popUpScreen.element, false); // // this.mainScreen.element.style.display = 'none'; // } // this.screenChanges.emit(); // } // // // private addPopUp(tag: string, screenType: ScreenTypeOx) { // const htmlElement = document.createElement(tag); // htmlElement.addEventListener('closed', () => { // this.removePopUp(htmlElement, false); // }); // if (this.popUpScreen) { // this.parentScreen.removeChild(this.popUpScreen.element); // } else { // this.popUpScreen = {element: undefined, type: undefined}; // } // this.popUpScreen.element = htmlElement; // this.popUpScreen.type = screenType; // this.parentScreen.prepend(this.popUpScreen.element); // if (this.mainScreen) { // this.mainScreen.element.style.display = 'none'; // } // this.screenChanges.emit(); // } // // private removePopUp(htmlElement: HTMLElement, sendEvent: boolean) { // this.parentScreen.removeChild(htmlElement); // this.popUpScreen = undefined; // if (this.mainScreen) { // this.mainScreen.element.style.display = ''; // } // if (sendEvent) { // this.screenChanges.emit(); // } // } // // private showInGameMenu() { // this.addPopUp('in-game-menu', ScreenTypeOx.InGameMenu); // } // // private showGamePreview() { // this.addPopUp('game-preview', ScreenTypeOx.GamePreview); // } // // private showLevelMenu() { // this.changeMainScreen('level-menu', ScreenTypeOx.LevelMenu); // } // // private showGame() { // this.changeMainScreen('micro-lesson', ScreenTypeOx.Game); // } // // private showGameComplete() { // this.changeMainScreen('game-complete', ScreenTypeOx.GameComplete); // } // // // TODO find way to correctly test gis method. // private isDefined(tagName: string) { // return document.createElement(tagName).constructor !== HTMLElement; // } // // public hasInstructive() { // return this.isDefined('micro-lesson-instructive'); // } // // private showInstructive() { // this.changeMainScreen('micro-lesson-instructive', ScreenTypeOx.Game); // } // // private showVideo(asPopUp: boolean) { // if (asPopUp) { // this.addPopUp('video-ox', ScreenTypeOx.Video); // } else { // this.changeMainScreen('video-ox', ScreenTypeOx.Video); // } // } // // private resumeGame() { // if (this.popUpScreen) { // this.removePopUp(this.popUpScreen.element, true); // } // } // }