import { Injectable } from '@angular/core' ; import { CardMetaInfo } from '../../models/decktracker/card-meta-info' ; import { DeckCard } from '../../models/decktracker/deck-card' ; import { DeckState } from '../../models/decktracker/deck-state' ; @ Injectable ( ) export class GameStateMetaInfoService { public updateDeck ( deckState , currentTurn ) { return Object . assign ( new DeckState ( ) , deckState , { board : this . cleanZone ( deckState . board ) , deck : this . cleanZone ( deckState . deck ) , hand : this . updateZone ( deckState . hand , currentTurn ) , otherZone : this . cleanZone ( deckState . otherZone ) , } as DeckState ) ; } private cleanZone ( zone ) { return zone . map ( ( card ) => card . metaInfo . turnAtWhichCardEnteredCurrentZone === undefined ? card : this . cleanCard ( card ) ) ; } private cleanCard ( card ) { const newMeta = Object . assign ( new CardMetaInfo ( ) , card . metaInfo , { turnAtWhichCardEnteredCurrentZone : undefined , } as CardMetaInfo ) ; return card . update ( { metaInfo : newMeta , } as DeckCard ) ; } private updateZone ( zone , currentTurn ) { return zone . map ( ( card ) => card . metaInfo . turnAtWhichCardEnteredCurrentZone === undefined ? this . updateCard ( card , currentTurn ) : card ) ; } private updateCard ( card , currentTurn ) { const newMeta = Object . assign ( new CardMetaInfo ( ) , card . metaInfo , { turnAtWhichCardEnteredCurrentZone : currentTurn , } as CardMetaInfo ) ; return card . update ( { metaInfo : newMeta , } as DeckCard ) ; } }