import { GameState } from '../../../models/decktracker/game-state' ; import { GameEvent } from '../../../models/game-event' ; import { DeckHandlerService } from '../deck-handler.service' ; import { DeckstringOverrideEvent } from '../event/deckstring-override-event' ; import { DeckstringOverrideParser } from './deckstring-override-parser' ; import { EventParser } from './event-parser' ; export class ReconnectOverParser implements EventParser { constructor ( private readonly deckHandler ) { } applies ( gameEvent , state ) { return state && gameEvent . type === GameEvent . RECONNECT_OVER ; } async parse ( currentState , gameEvent ) { console . debug ( 'applying reconnect over event' , gameEvent , currentState ) ; const stateAfterPlayerDeckUpdate = await new DeckstringOverrideParser ( this . deckHandler ) . parse ( currentState , new DeckstringOverrideEvent ( currentState . playerDeck . name , currentState . playerDeck . deckstring ) , null , 'player' ) ; const stateAfterOpponentDeckUpdate = await new DeckstringOverrideParser ( this . deckHandler ) . parse ( stateAfterPlayerDeckUpdate , new DeckstringOverrideEvent ( stateAfterPlayerDeckUpdate . opponentDeck . name , stateAfterPlayerDeckUpdate . opponentDeck . deckstring ) , null , 'opponent' ) ; console . debug ( 'after applying reconnect over event' , stateAfterOpponentDeckUpdate , stateAfterPlayerDeckUpdate ) ; return stateAfterOpponentDeckUpdate . update ( { mulliganOver : true , } as GameState ) ; } event ( ) { return GameEvent . RECONNECT_OVER ; } }