import { GameState } from '../../../models/decktracker/game-state' ; import { GameEvent } from '../../../models/game-event' ; import { Preferences } from '../../../models/preferences' ; import { PreferencesService } from '../../preferences.service' ; import { DeckParserService } from '../deck-parser.service' ; import { EventParser } from './event-parser' ; export class GameEndParser implements EventParser { constructor ( private readonly prefs , private readonly deckParser ) { } applies ( gameEvent , state , prefs ? ) { return ( state && ( gameEvent . type === GameEvent . GAME_END || ( gameEvent . type === GameEvent . SPECTATING && ! gameEvent . additionalData . spectating ) ) ) ; } async parse ( currentState ) { const prefs = await this . prefs . getPreferences ( ) ; if ( prefs && prefs . decktrackerCloseOnGameEnd ) { return new GameState ( ) ; } return currentState . update ( { gameEnded : true , } as GameState ) ; } event ( ) { return GameEvent . GAME_END ; } }