UNPKG

micro-lesson-core

Version:

1,614 lines (1,595 loc) 101 kB
import { NgModule, Injectable, ɵɵdefineInjectable, EventEmitter, ɵɵinject, Directive, Input, Output } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; import { ScreenTypeOx, PreloaderOxService, Constants, SettingsService, CommunicationOxService, MicroLessonMetrics, TimerOxService, HintMetric, ExerciseMetric, AnswerMetric, GameCompleteOxBridge, SettingsInfoOxBridge, MetricsOxBridge, CollectiblesOxBridge } from 'ox-core'; import { BehaviorSubject, forkJoin, timer, Subscription } from 'rxjs'; import { first, takeUntil, tap } from 'rxjs/operators'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var GameModule = /** @class */ (function () { function GameModule() { } GameModule.decorators = [ { type: NgModule, args: [{ declarations: [], imports: [ CommonModule ] },] } ]; return GameModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @template Answer */ var GameActionsService = /** @class */ (function () { function GameActionsService() { this.showNextChallenge = new EventEmitter(); this.showFeedbackOfAnswer = new EventEmitter(); this.microLessonCompleted = new EventEmitter(); this.goToResults = new EventEmitter(); this.goToInGameMenu = new EventEmitter(); this.goToLevelMenu = new EventEmitter(); this.showHint = new EventEmitter(); this.surrender = new EventEmitter(); this.restartGame = new EventEmitter(); this.resumeGame = new EventEmitter(); this.goToGamePreview = new EventEmitter(); this.actionToAnswer = new EventEmitter(); this.actionNotToAnswer = new EventEmitter(); this.finishedTimeOfExercise = new EventEmitter(); this.exitFromGame = new EventEmitter(); } /** * @return {?} */ GameActionsService.prototype.onClickNextButton = /** * @return {?} */ function () { /* this.clickNext.next(); if (!this.composeService.haveToCompose()) { this.challengeReadyToChange.next(); } else { this.composeService.decompose(); } */ }; GameActionsService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ GameActionsService.ctorParameters = function () { return []; }; /** @nocollapse */ GameActionsService.ngInjectableDef = ɵɵdefineInjectable({ factory: function GameActionsService_Factory() { return new GameActionsService(); }, token: GameActionsService, providedIn: "root" }); return GameActionsService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var GamePreviewService = /** @class */ (function () { function GamePreviewService() { this.startGame = new EventEmitter(); this.selectLevel = new BehaviorSubject(-1); this.showInstructive = new EventEmitter(); } GamePreviewService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ GamePreviewService.ctorParameters = function () { return []; }; /** @nocollapse */ GamePreviewService.ngInjectableDef = ɵɵdefineInjectable({ factory: function GamePreviewService_Factory() { return new GamePreviewService(); }, token: GamePreviewService, providedIn: "root" }); return GamePreviewService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var VideoService = /** @class */ (function () { function VideoService() { // todo ver si estos dos son especificos de un juego o se pueden generalizar this.playVideo = new EventEmitter(); } /** * @param {?} data * @return {?} */ VideoService.prototype.onPlayVideo = /** * @param {?} data * @return {?} */ function (data) { this.currentVideoData = data; this.playVideo.emit(data); }; VideoService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ VideoService.ctorParameters = function () { return []; }; /** @nocollapse */ VideoService.ngInjectableDef = ɵɵdefineInjectable({ factory: function VideoService_Factory() { return new VideoService(); }, token: VideoService, providedIn: "root" }); return VideoService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // export type ScreenOxTags = 'video-ox' | var ScreenOxService = /** @class */ (function () { function ScreenOxService(preloader, gameActions, videoService, gamePreviewActions) { var _this = this; this.preloader = preloader; this.gameActions = gameActions; this.videoService = videoService; this.gamePreviewActions = gamePreviewActions; this.screenChanges = new EventEmitter(); this.gamePreviewActions.startGame.subscribe((/** * @param {?} e * @return {?} */ function (e) { _this.showGame(); })); this.gameActions.resumeGame.subscribe((/** * @param {?} e * @return {?} */ function (e) { _this.resumeGame(); })); this.gameActions.restartGame.subscribe((/** * @param {?} e * @return {?} */ function (e) { _this.showGame(); })); this.gameActions.goToLevelMenu.subscribe((/** * @return {?} */ function () { _this.showLevelMenu(); })); this.gameActions.goToGamePreview.subscribe((/** * @return {?} */ function () { _this.showGamePreview(); })); this.gameActions.goToResults.subscribe((/** * @return {?} */ function () { _this.showGameComplete(); })); this.gameActions.goToInGameMenu.subscribe((/** * @return {?} */ function () { _this.showInGameMenu(); })); this.gamePreviewActions.showInstructive.subscribe((/** * @return {?} */ function () { _this.showInstructive(); })); this.videoService.playVideo.subscribe((/** * @param {?} asPopUp * @return {?} */ function (asPopUp) { _this.showVideo(asPopUp); })); this.screensReady = new Map(); [ScreenTypeOx.Loading, ScreenTypeOx.GamePreview, ScreenTypeOx.Game, ScreenTypeOx.InGameMenu, ScreenTypeOx.GameComplete, ScreenTypeOx.Video, ScreenTypeOx.ToBeContinue].forEach((/** * @param {?} aScreen * @return {?} */ function (aScreen) { return _this.screensReady.set(aScreen, false); })); this.setScreenReadySubscription(); } /** * @return {?} */ ScreenOxService.prototype.ngOnInit = /** * @return {?} */ function () { if (!this.parentScreen) { throw new Error('Screen Service needs a parent screen to be set'); } }; /** * @param {?} type * @return {?} */ ScreenOxService.prototype.isShowingScreen = /** * @param {?} type * @return {?} */ function (type) { if (this.popUpScreen) { return this.popUpScreen.type === type; } else { return this.mainScreen.type === type; } }; /** * @param {?} type * @return {?} */ ScreenOxService.prototype.isShowingMainScreen = /** * @param {?} type * @return {?} */ function (type) { return this.mainScreen.type === type; }; /** * @protected * @return {?} */ ScreenOxService.prototype.setScreenReadySubscription = /** * @protected * @return {?} */ function () { var _this = this; // todo ver cuando hacer unsubscribe this.preloader.screenReady.subscribe((/** * @param {?} screen * @return {?} */ function (screen) { _this.screensReady.set(screen, true); })); }; /** * @return {?} */ ScreenOxService.prototype.showLoading = /** * @return {?} */ function () { this.changeMainScreen(document.createElement('loading-assets'), ScreenTypeOx.Loading); }; /** * @return {?} */ ScreenOxService.prototype.showNotInWumboxScreen = /** * @return {?} */ function () { this.changeMainScreen(document.createElement('not-in-wumbox'), ScreenTypeOx.NotInWumbox); }; /** * @return {?} */ ScreenOxService.prototype.showInitialScreen = /** * @return {?} */ function () { if (this.isDefined('game-preview')) { this.showGamePreview(); } else if (this.isDefined('level-menu')) { this.showLevelMenu(); } else { this.showGame(); } }; /** * @private * @param {?} element * @param {?} type * @return {?} */ ScreenOxService.prototype.changeMainScreen = /** * @private * @param {?} element * @param {?} type * @return {?} */ function (element, type) { 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); // this.mainScreen.element.style.display = 'none'; } this.screenChanges.emit(); }; /** * @private * @param {?} htmlElement * @param {?} screenType * @return {?} */ ScreenOxService.prototype.addPopUp = /** * @private * @param {?} htmlElement * @param {?} screenType * @return {?} */ function (htmlElement, screenType) { var _this = this; htmlElement.addEventListener('closed', (/** * @return {?} */ function () { _this.removePopUp(htmlElement); })); 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 * @param {?} htmlElement * @return {?} */ ScreenOxService.prototype.removePopUp = /** * @private * @param {?} htmlElement * @return {?} */ function (htmlElement) { this.parentScreen.removeChild(htmlElement); this.popUpScreen = undefined; if (this.mainScreen) { this.mainScreen.element.style.display = ''; } }; /** * @private * @return {?} */ ScreenOxService.prototype.showInGameMenu = /** * @private * @return {?} */ function () { this.addPopUp(document.createElement('in-game-menu'), ScreenTypeOx.InGameMenu); }; /** * @private * @return {?} */ ScreenOxService.prototype.showGamePreview = /** * @private * @return {?} */ function () { this.addPopUp(document.createElement('game-preview'), ScreenTypeOx.GamePreview); }; /** * @private * @return {?} */ ScreenOxService.prototype.showLevelMenu = /** * @private * @return {?} */ function () { this.changeMainScreen(document.createElement('level-menu'), ScreenTypeOx.LevelMenu); }; /** * @private * @return {?} */ ScreenOxService.prototype.showGame = /** * @private * @return {?} */ function () { this.changeMainScreen(document.createElement('micro-lesson'), ScreenTypeOx.Game); }; /** * @private * @return {?} */ ScreenOxService.prototype.showGameComplete = /** * @private * @return {?} */ function () { this.changeMainScreen(document.createElement('game-complete'), ScreenTypeOx.GameComplete); }; /** * @private * @param {?} tagName * @return {?} */ ScreenOxService.prototype.isDefined = /** * @private * @param {?} tagName * @return {?} */ function (tagName) { return document.createElement(tagName).constructor !== HTMLElement; }; /** * @return {?} */ ScreenOxService.prototype.hasInstructive = /** * @return {?} */ function () { return this.isDefined('micro-lesson-instructive'); }; /** * @private * @return {?} */ ScreenOxService.prototype.showInstructive = /** * @private * @return {?} */ function () { this.changeMainScreen(document.createElement('micro-lesson-instructive'), ScreenTypeOx.Game); }; /** * @private * @param {?} asPopUp * @return {?} */ ScreenOxService.prototype.showVideo = /** * @private * @param {?} asPopUp * @return {?} */ function (asPopUp) { if (asPopUp) { this.addPopUp(document.createElement('video-ox'), ScreenTypeOx.Video); } else { this.changeMainScreen(document.createElement('video-ox'), ScreenTypeOx.Video); } }; /** * @private * @return {?} */ ScreenOxService.prototype.resumeGame = /** * @private * @return {?} */ function () { if (this.popUpScreen) { this.removePopUp(this.popUpScreen.element); } }; ScreenOxService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ ScreenOxService.ctorParameters = function () { return [ { type: PreloaderOxService }, { type: GameActionsService }, { type: VideoService }, { type: GamePreviewService } ]; }; /** @nocollapse */ ScreenOxService.ngInjectableDef = ɵɵdefineInjectable({ factory: function ScreenOxService_Factory() { return new ScreenOxService(ɵɵinject(PreloaderOxService), ɵɵinject(GameActionsService), ɵɵinject(VideoService), ɵɵinject(GamePreviewService)); }, token: ScreenOxService, providedIn: "root" }); return ScreenOxService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var AudiOX = /** @class */ (function () { function AudiOX(audioHowl, askingScreen) { this.audio = audioHowl; this.askedFor = askingScreen; } return AudiOX; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var SoundOxService = /** @class */ (function () { function SoundOxService(preloader, settingsService, screenOx) { var _this = this; this.preloader = preloader; this.settingsService = settingsService; this.screenOx = screenOx; this.audios = []; this.musics = []; this.screenOx.screenChanges.subscribe((/** * @return {?} */ function () { _this.checkAudiosByScreen(); _this.checkMusicByScreen(); })); } /** * @param {?} on * @return {?} */ SoundOxService.prototype.setSoundOn = /** * @param {?} on * @return {?} */ function (on) { this.settingsService.setSound(on); this.checkAudiosByScreen(); }; /** * @return {?} */ SoundOxService.prototype.soundOn = /** * @return {?} */ function () { return this.settingsService.getSound(); }; /** * @return {?} */ SoundOxService.prototype.musicOn = /** * @return {?} */ function () { return this.settingsService.getMusic(); }; /** * @param {?} on * @return {?} */ SoundOxService.prototype.setMusicOn = /** * @param {?} on * @return {?} */ function (on) { this.settingsService.setMusic(on); this.checkMusicByScreen(); }; /** * @param {?} url * @param {?} askingScreen * @return {?} */ SoundOxService.prototype.playMusic = /** * @param {?} url * @param {?} askingScreen * @return {?} */ function (url, askingScreen) { if (!this.preloader.resources.has(url)) { return; } /** @type {?} */ var musicOx = new AudiOX(this.preloader.resources.get(url).data, askingScreen); this.addAsLastScreenMusic(musicOx); musicOx.audio.loop(true); if (askingScreen === askingScreen && this.musicOn()) { this.playHowl(musicOx); } }; /** * @param {?} askingScreen * @return {?} */ SoundOxService.prototype.pauseMusic = /** * @param {?} askingScreen * @return {?} */ function (askingScreen) { /** @type {?} */ var music = this.musics.find((/** * @param {?} x * @return {?} */ function (x) { return x.askedFor === askingScreen; })); if (music) { music.audio.pause(); } }; /** * @param {?} url * @param {?} askingScreen * @param {?=} duplicateIfIsTheSame * @param {?=} playAnyWay * @param {?=} callBack * @return {?} */ SoundOxService.prototype.playSoundEffect = /** * @param {?} url * @param {?} askingScreen * @param {?=} duplicateIfIsTheSame * @param {?=} playAnyWay * @param {?=} callBack * @return {?} */ function (url, askingScreen, duplicateIfIsTheSame, playAnyWay, callBack) { var _this = this; if (duplicateIfIsTheSame === void 0) { duplicateIfIsTheSame = false; } if (playAnyWay === void 0) { playAnyWay = false; } /** @type {?} */ var aux = this.preloader.resources.get(url); if (!aux || aux.error) { console.log('The audio ' + url + ' can not be played, ', aux ? 'error: ' + aux.error : 'the resource is not loaded.'); return; } /** @type {?} */ var howlerData = aux.data; if (!duplicateIfIsTheSame && howlerData.playing) { howlerData.stop(); } /** @type {?} */ var audiOX = new AudiOX(howlerData, askingScreen); this.addAsLastScreenAudio(audiOX); audiOX.audio.mute(!this.screenOx.isShowingScreen(askingScreen) || (!this.soundOn() && !playAnyWay)); audiOX.audio.once('end', (/** * @return {?} */ function () { _this.audios = _this.audios.filter((/** * @param {?} x * @return {?} */ function (x) { return x.audio !== audiOX.audio; })); if (callBack) { callBack(); } })); this.playHowl(audiOX); }; /** * @private * @param {?} sound * @return {?} */ SoundOxService.prototype.addAsLastScreenAudio = /** * @private * @param {?} sound * @return {?} */ function (sound) { this.audios.filter((/** * @param {?} x * @return {?} */ function (x) { return x.askedFor === sound.askedFor; })).forEach((/** * @param {?} x * @return {?} */ function (x) { return x.audio.mute(true); })); this.audios = this.audios.filter((/** * @param {?} x * @return {?} */ function (x) { return x.askedFor !== sound.askedFor; })); this.audios.push(sound); }; /** * @private * @param {?} musicOx * @return {?} */ SoundOxService.prototype.addAsLastScreenMusic = /** * @private * @param {?} musicOx * @return {?} */ function (musicOx) { this.musics.filter((/** * @param {?} x * @return {?} */ function (x) { return x.askedFor === musicOx.askedFor; })).forEach((/** * @param {?} x * @return {?} */ function (x) { return x.audio.stop(); })); this.musics = this.musics.filter((/** * @param {?} x * @return {?} */ function (x) { return x.askedFor !== musicOx.askedFor; })); this.musics.push(musicOx); }; /** * @private * @return {?} */ SoundOxService.prototype.checkMusicByScreen = /** * @private * @return {?} */ function () { var _this = this; this.musics.forEach((/** * @param {?} x * @return {?} */ function (x) { if (_this.screenOx.isShowingScreen(x.askedFor) && _this.musicOn()) { _this.playHowl(x); } else { x.audio.pause(); } })); }; /** * @private * @return {?} */ SoundOxService.prototype.checkAudiosByScreen = /** * @private * @return {?} */ function () { var _this = this; this.audios.forEach((/** * @param {?} x * @return {?} */ function (x) { x.audio.mute(!_this.screenOx.isShowingScreen(x.askedFor) || !_this.soundOn()); })); }; /** * @private * @param {?} audiOX * @return {?} */ SoundOxService.prototype.playHowl = /** * @private * @param {?} audiOX * @return {?} */ function (audiOX) { /*const id = audiOX.audio._sounds && audiOX.audio._sounds[0] ? audiOX.audio._sounds[0]._id : undefined; if (id) { audiOX.audio.play(id); } else { audiOX.audio.play(); }*/ audiOX.audio.play(); }; /** * @param {?} fromScreen * @return {?} */ SoundOxService.prototype.playClick = /** * @param {?} fromScreen * @return {?} */ function (fromScreen) { this.playSoundEffect(Constants.clickSoundPath, fromScreen); }; /** * @param {?} fromScreen * @return {?} */ SoundOxService.prototype.playBubble = /** * @param {?} fromScreen * @return {?} */ function (fromScreen) { this.playSoundEffect(Constants.bubble, fromScreen); }; /** * @param {?} fromScreen * @return {?} */ SoundOxService.prototype.playWoosh = /** * @param {?} fromScreen * @return {?} */ function (fromScreen) { this.playSoundEffect(Constants.woosh, fromScreen); }; /** * @param {?} fromScreen * @return {?} */ SoundOxService.prototype.playRightSound = /** * @param {?} fromScreen * @return {?} */ function (fromScreen) { this.playSoundEffect(Constants.correctAnswerSoundPath, fromScreen); }; /** * @param {?} fromScreen * @return {?} */ SoundOxService.prototype.playWrongSound = /** * @param {?} fromScreen * @return {?} */ function (fromScreen) { this.playSoundEffect(Constants.wrongAnswerSoundPath, fromScreen); }; /** * @param {?} fromScreen * @return {?} */ SoundOxService.prototype.playGameCompleteSound = /** * @param {?} fromScreen * @return {?} */ function (fromScreen) { this.playSoundEffect(Constants.gameCompleteAnswerSoundPath, fromScreen); }; /** * @param {?} fromScreen * @return {?} */ SoundOxService.prototype.playCantClickSound = /** * @param {?} fromScreen * @return {?} */ function (fromScreen) { this.playSoundEffect(Constants.cantClickSoundPath, fromScreen); }; SoundOxService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ SoundOxService.ctorParameters = function () { return [ { type: PreloaderOxService }, { type: SettingsService }, { type: ScreenOxService } ]; }; /** @nocollapse */ SoundOxService.ngInjectableDef = ɵɵdefineInjectable({ factory: function SoundOxService_Factory() { return new SoundOxService(ɵɵinject(PreloaderOxService), ɵɵinject(SettingsService), ɵɵinject(ScreenOxService)); }, token: SoundOxService, providedIn: "root" }); return SoundOxService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var GameCompleteDirective = /** @class */ (function () { function GameCompleteDirective(activatedRoute, router, sound) { this.activatedRoute = activatedRoute; this.router = router; this.sound = sound; } /** * @return {?} */ GameCompleteDirective.prototype.onShowGameComplete = /** * @return {?} */ function () { this.sound.playSoundEffect('sounds/levelCompleted.mp3', ScreenTypeOx.GameComplete, true, true); }; /** * @return {?} */ GameCompleteDirective.prototype.onClickNext = /** * @return {?} */ function () { /* if (this.currentLvl < 6) { this.sound.playSoundEffect('sounds/click.mp3', ScreenTypeOx.GameComplete, true, true, event => { this.router.navigate(['game'], {queryParams: {level: this.currentLvl + 1}}); }); } else { this.sound.playSoundEffect('sounds/cantClick.mp3', ScreenTypeOx.GameComplete); } */ }; /** * @return {?} */ GameCompleteDirective.prototype.onClickRestart = /** * @return {?} */ function () { var _this = this; this.sound.playSoundEffect('sounds/click.mp3', ScreenTypeOx.GameComplete, true, true, (/** * @param {?} event * @return {?} */ function (event) { _this.router.navigate(['game'], { preserveQueryParams: true }); })); }; /** * @return {?} */ GameCompleteDirective.prototype.onClickMenu = /** * @return {?} */ function () { var _this = this; this.sound.playSoundEffect('sounds/click.mp3', ScreenTypeOx.GameComplete, true, true, (/** * @param {?} event * @return {?} */ function (event) { _this.router.navigate(['menu']); })); }; GameCompleteDirective.decorators = [ { type: Directive, args: [{ selector: '[mlGameComplete]' },] } ]; /** @nocollapse */ GameCompleteDirective.ctorParameters = function () { return [ { type: ActivatedRoute }, { type: Router }, { type: SoundOxService } ]; }; return GameCompleteDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var GameCompleteHeaderDirective = /** @class */ (function () { function GameCompleteHeaderDirective() { } GameCompleteHeaderDirective.decorators = [ { type: Directive, args: [{ selector: '[mlGameCompleteHeader]' },] } ]; /** @nocollapse */ GameCompleteHeaderDirective.ctorParameters = function () { return []; }; GameCompleteHeaderDirective.propDecorators = { title: [{ type: Input }], subtitle: [{ type: Input }], logo: [{ type: Input }], medal: [{ type: Input }] }; return GameCompleteHeaderDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NumericResultsDirective = /** @class */ (function () { function NumericResultsDirective() { } NumericResultsDirective.decorators = [ { type: Directive, args: [{ selector: '[mlNumericResults]' },] } ]; /** @nocollapse */ NumericResultsDirective.ctorParameters = function () { return []; }; NumericResultsDirective.propDecorators = { rightAnswers: [{ type: Input }], wrongAnswers: [{ type: Input }], hints: [{ type: Input }], lapsedSeconds: [{ type: Input }] }; return NumericResultsDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var GameCompleteModule = /** @class */ (function () { function GameCompleteModule() { } GameCompleteModule.decorators = [ { type: NgModule, args: [{ declarations: [GameCompleteDirective, GameCompleteHeaderDirective, NumericResultsDirective], imports: [ CommonModule, ], exports: [ GameCompleteDirective, GameCompleteHeaderDirective, NumericResultsDirective ] },] } ]; return GameCompleteModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var InGameMenuDirective = /** @class */ (function () { function InGameMenuDirective(gameActions, sound) { this.gameActions = gameActions; this.sound = sound; this.closed = new EventEmitter(); } /** * @return {?} */ InGameMenuDirective.prototype.onClickResumeGame = /** * @return {?} */ function () { this.sound.playClick(ScreenTypeOx.InGameMenu); this.closed.next(); this.gameActions.resumeGame.emit(); }; /** * @return {?} */ InGameMenuDirective.prototype.onClickRestartGame = /** * @return {?} */ function () { this.sound.playClick(ScreenTypeOx.InGameMenu); // todo pop up de ¡vas a perder el avance! this.gameActions.exitFromGame.emit(); this.closed.next(); this.gameActions.restartGame.emit(); }; /** * @return {?} */ InGameMenuDirective.prototype.onClickInformation = /** * @return {?} */ function () { this.sound.playClick(ScreenTypeOx.InGameMenu); // todo VER esto es porque ya no se puede volver al juego desde aca en las pantallas que tnego // analizar this.gameActions.exitFromGame.emit(); this.closed.next(); this.gameActions.goToGamePreview.emit(); }; /** * @return {?} */ InGameMenuDirective.prototype.onClickLevelMenu = /** * @return {?} */ function () { this.sound.playClick(ScreenTypeOx.InGameMenu); // todo pop up de ¡vas a perder el avance! this.gameActions.exitFromGame.emit(); this.gameActions.goToLevelMenu.emit(); this.closed.next(); }; InGameMenuDirective.decorators = [ { type: Directive, args: [{ selector: '[mlInGameMenu]' },] } ]; /** @nocollapse */ InGameMenuDirective.ctorParameters = function () { return [ { type: GameActionsService }, { type: SoundOxService } ]; }; InGameMenuDirective.propDecorators = { closed: [{ type: Output }] }; return InGameMenuDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var InGameMenuModule = /** @class */ (function () { function InGameMenuModule() { } InGameMenuModule.decorators = [ { type: NgModule, args: [{ declarations: [InGameMenuDirective], imports: [ CommonModule, RouterModule ], },] } ]; return InGameMenuModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var AppInfoOxService = /** @class */ (function () { function AppInfoOxService(communicationService) { var _this = this; this.communicationService = communicationService; this.communicationService.receiveUserInfo.pipe(first()).subscribe((/** * @param {?} userInfo * @return {?} */ function (userInfo) { _this.userInfo = userInfo; })); this.communicationService.receiveMicroLessonInfo.pipe(first()).subscribe((/** * @param {?} microLessonInfo * @return {?} */ function (microLessonInfo) { _this.microLessonInfo = microLessonInfo; })); } /** * @return {?} */ AppInfoOxService.prototype.getInitialLevel = /** * @return {?} */ function () { return this.getFirstMicroLessonInfo().initialLevel; }; /** * @return {?} */ AppInfoOxService.prototype.getFirstMicroLessonInfo = /** * @return {?} */ function () { return this.microLessonInfo[0] ? ((/** @type {?} */ (this.microLessonInfo)))[0] : ((/** @type {?} */ (this.microLessonInfo))); }; /** * @param {?} microLessonId * @return {?} */ AppInfoOxService.prototype.getMicroLessonInfoById = /** * @param {?} microLessonId * @return {?} */ function (microLessonId) { /** @type {?} */ var aux = this.microLessonInfo[0] ? (/** @type {?} */ (this.microLessonInfo)) : [(/** @type {?} */ (this.microLessonInfo))]; return aux.find((/** * @param {?} x * @return {?} */ function (x) { return x.microLessonId === microLessonId; })); }; /** * @param {?} microLessonId * @param {?=} level * @return {?} */ AppInfoOxService.prototype.getMetricsTable = /** * @param {?} microLessonId * @param {?=} level * @return {?} */ function (microLessonId, level) { if (level === void 0) { level = 0; } /** @type {?} */ var aux = this.getMicroLessonInfoById(microLessonId); return aux.metricTables.length > 1 ? aux.metricTables[level] : aux.metricTables[0]; }; AppInfoOxService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ AppInfoOxService.ctorParameters = function () { return [ { type: CommunicationOxService } ]; }; /** @nocollapse */ AppInfoOxService.ngInjectableDef = ɵɵdefineInjectable({ factory: function AppInfoOxService_Factory() { return new AppInfoOxService(ɵɵinject(CommunicationOxService)); }, token: AppInfoOxService, providedIn: "root" }); return AppInfoOxService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @abstract * @template Exercise */ var ScoreStarsService = /** @class */ (function () { function ScoreStarsService() { } /** * @param {?} metrics * @return {?} */ ScoreStarsService.prototype.calculateStars = /** * @param {?} metrics * @return {?} */ function (metrics) { if (!metrics.score) { throw new Error('You can\' t set the star count if you haven\'t set the score!'); } metrics.stars = this.defaultStarCalculator(metrics.score); }; /** * @private * @param {?} score * @return {?} */ ScoreStarsService.prototype.defaultStarCalculator = /** * @private * @param {?} score * @return {?} */ function (score) { if (score > 9000) { return 5; } if (score >= 7500) { return 4; } if (score >= 6000) { return 3; } if (score >= 3000) { return 2; } return 1; }; ScoreStarsService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ ScoreStarsService.ngInjectableDef = ɵɵdefineInjectable({ factory: function ScoreStarsService_Factory() { return new ScoreStarsService(); }, token: ScoreStarsService, providedIn: "root" }); return ScoreStarsService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @abstract * @template Answer */ var AnswerService = /** @class */ (function () { function AnswerService() { this.checkedAnswer = new EventEmitter(); this.tryAnswer = new EventEmitter(); this.validAnswer = new EventEmitter(); } Object.defineProperty(AnswerService.prototype, "currentAnswer", { get: /** * @return {?} */ function () { return this._currentAnswer; }, set: /** * @param {?} value * @return {?} */ function (value) { this._currentAnswer = value; this.validAnswer.emit(this.isValidAnswer(this.currentAnswer)); }, enumerable: true, configurable: true }); /** * @return {?} */ AnswerService.prototype.onTryAnswer = /** * @return {?} */ function () { var _this = this; this.tryAnswer.emit(this.currentAnswer); this.checkAnswer(this.currentAnswer).subscribe((/** * @param {?} value * @return {?} */ function (value) { _this.checkedAnswer.emit(value); })); }; AnswerService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ AnswerService.ctorParameters = function () { return []; }; /** @nocollapse */ AnswerService.ngInjectableDef = ɵɵdefineInjectable({ factory: function AnswerService_Factory() { return new AnswerService(); }, token: AnswerService, providedIn: "root" }); return AnswerService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var SubLevelService = /** @class */ (function () { function SubLevelService(answerService, gameActions, gamePreviewService, appInfoOxService) { var _this = this; this.answerService = answerService; this.gameActions = gameActions; this.gamePreviewService = gamePreviewService; this.appInfoOxService = appInfoOxService; this.currentSublevel = new BehaviorSubject(1); this.gamePreviewService.selectLevel.subscribe((/** * @param {?} newLevel * @return {?} */ function (newLevel) { if (newLevel >= 0) { _this.setValuesByLevel(newLevel); } })); this.gameActions.showNextChallenge.subscribe((/** * @param {?} _ * @return {?} */ function (_) { _this.progressAddedInThisChallenge = false; })); this.gamePreviewService.startGame.subscribe((/** * @param {?} _ * @return {?} */ function (_) { _this.asStart(); })); // TODO correct circular dependency here this.answerService.checkedAnswer.subscribe((/** * @param {?} correct * @return {?} */ function (correct) { _this.updateCurrentSubLevel(correct); })); this.gameActions.restartGame.subscribe((/** * @param {?} _ * @return {?} */ function (_) { _this.asStart(); })); } /** * @private * @param {?} newLevel * @return {?} */ SubLevelService.prototype.setValuesByLevel = /** * @private * @param {?} newLevel * @return {?} */ function (newLevel) { this.maxSubLevel = this.appInfoOxService.getFirstMicroLessonInfo() .microLessonConfiguration[newLevel - 1].exercisesToUpSubLevel.length; /** @type {?} */ var carry = 0; this.currentExercisesToReach = this.appInfoOxService.getFirstMicroLessonInfo() .microLessonConfiguration[newLevel - 1].exercisesToUpSubLevel.map((/** * @param {?} value * @param {?} index * @return {?} */ function (value, index) { carry += value; return carry; })); }; /** * @private * @return {?} */ SubLevelService.prototype.asStart = /** * @private * @return {?} */ function () { this.progressAddedInThisChallenge = false; this.subLevelProgress = 0; this.currentSublevel.next(1); }; /** * @private * @param {?} correct * @return {?} */ SubLevelService.prototype.updateCurrentSubLevel = /** * @private * @param {?} correct * @return {?} */ function (correct) { var _this = this; if (!this.progressAddedInThisChallenge) { /** @type {?} */ var diff = correct ? 1 : -1; this.subLevelProgress = Math.max(0, this.subLevelProgress + diff); this.progressAddedInThisChallenge = true; /** @type {?} */ var newSubLevel = this.currentExercisesToReach.findIndex((/** * @param {?} toReach * @return {?} */ function (toReach) { return _this.subLevelProgress < toReach; })) + 1; if (this.currentSublevel.value !== newSubLevel) { this.currentSublevel.next(newSubLevel); } } }; /** * @return {?} */ SubLevelService.prototype.getMaxSubLevel = /** * @return {?} */ function () { return this.maxSubLevel; }; SubLevelService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ SubLevelService.ctorParameters = function () { return [ { type: AnswerService }, { type: GameActionsService }, { type: GamePreviewService }, { type: AppInfoOxService } ]; }; /** @nocollapse */ SubLevelService.ngInjectableDef = ɵɵdefineInjectable({ factory: function SubLevelService_Factory() { return new SubLevelService(ɵɵinject(AnswerService), ɵɵinject(GameActionsService), ɵɵinject(GamePreviewService), ɵɵinject(AppInfoOxService)); }, token: SubLevelService, providedIn: "root" }); return SubLevelService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @abstract * @template Exercise, Answer */ var ChallengeService = /** @class */ (function () { function ChallengeService(gameActions, gamePreview, subLevelService) { var _this = this; this.gameActions = gameActions; this.gamePreview = gamePreview; this.subLevelService = subLevelService; this.currentExercise = new BehaviorSubject(undefined); this.currentSubLevelPregeneratedExercisesNeeded = 2; this.cachedExercises = []; this.usedDataExercises = []; this.gameActions.showNextChallenge.subscribe((/** * @param {?} _ * @return {?} */ function (_) { _this.nextChallenge(); _this.assignCurrentExerciseFromCache(); })); this.gameActions.restartGame.subscribe((/** * @param {?} answer * @return {?} */ function (answer) { _this.cachedExercises = []; _this.currentExercise.next(undefined); })); this.gameActions.microLessonCompleted.subscribe((/** * @param {?} e * @return {?} */ function (e) { _this.cachedExercises = []; _this.currentExercise.next(undefined); })); this.gameActions.exitFromGame.subscribe((/** * @param {?} e * @return {?} */ function (e) { _this.cachedExercises = []; _this.currentExercise.next(undefined); })); } /** * @return {?} */ ChallengeService.prototype.nextChallenge = /** * @return {?} */ function () { /** @type {?} */ var checkingRepeatedCount = 0; /** @type {?} */ var possibleChallenge; // the goal is to have pre cached possible exercises for every possible sub level /** @type {?} */ var toAddSubLevels = this.getPossibleNextSubLevels(); var _loop_1 = function (i) { if (this_1.cachedExercises.filter((/** * @param {?} x * @return {?} */ function (x) { return x.subLevel === toAddSubLevels[i]; })).length > 3) { return "continue"; } do { possibleChallenge = this_1.generateNextChallenge(toAddSubLevels[i]); checkingRepeatedCount++; if (checkingRepeatedCount >= 50) { this_1.removeHalfRepeatedExercises(); } if (checkingRepeatedCount >= 2000) { console.log('loop in generate next challenge', this_1.usedDataExercises); throw new Error('Loop in generate next challenge'); } } while (this_1.isRepeatedExercise(possibleChallenge.exerciseData)); this_1.cachedExercises.push(possibleChallenge); }; var this_1 = this; for (var i = 0; i < toAddSubLevels.length; i++) { _loop_1(i); } /* this.exercisesReadyToUse.next(this.cachedExercises.splice(0, 1)[0]); */ }; /** * @protected * @return {?} */ ChallengeService.prototype.removeHalfRepeatedExercises = /** * @protected * @return {?} */ function () { /** @type {?} */ var countToRemove = this.usedDataExercises.length / 2; this.usedDataExercises = this.usedDataExercises.length > 1 ? this.usedDataExercises.slice(countToRemove) : []; }; /** * @protected * @param {?} exerciseData * @return {?} */ ChallengeService.prototype.isRepeatedExercise = /** * @protected * @param {?} exerciseData * @return {?} */ function (exerciseData) { var _this = this; return this.usedDataExercises.some((/** * @param {?} x * @return {?} */ function (x) { return _this.equalsExerciseData(exerciseData, x); })); }; /** * @return {?} */ ChallengeService.prototype.assignCurrentExerciseFromCache = /** * @return {?} */