import { GameState } from '../../../models/decktracker/game-state' ; import { GameEvent } from '../../../models/game-event' ; import { DeckHandlerService } from '../deck-handler.service' ; import { DeckParserService } from '../deck-parser.service' ; import { DeckstringOverrideEvent } from '../event/deckstring-override-event' ; import { DeckstringOverrideParser } from './deckstring-override-parser' ; import { EventParser } from './event-parser' ; export class WhizbangDeckParser implements EventParser { constructor ( private readonly deckParser , private readonly deckHandler ) { } applies ( gameEvent , state ) { return state && gameEvent . type === GameEvent . WHIZBANG_DECK_ID ; } async parse ( currentState , gameEvent ) { const deckId = gameEvent . additionalData . deckId ; console . log ( 'parsing whizbang deck' , deckId ) ; const deck = await this . deckParser . getWhizbangDeck ( deckId , currentState . metadata ?. scenarioId , currentState . metadata ?. gameType ) ; console . log ( 'got whizbang deck' , deck ) ; if ( ! deck ) { return currentState ; } const stateAfterPlayerDeckUpdate = await new DeckstringOverrideParser ( this . deckHandler ) . parse ( currentState , new DeckstringOverrideEvent ( deck . name , deck . deckstring ) , null , 'player' ) ; return stateAfterPlayerDeckUpdate ; } event ( ) { return GameEvent . WHIZBANG_DECK_ID ; } }