import { Injectable } from '@angular/core' ; import { AllCardsService , Locale } from '@firestone-hs/reference-data' ; import { CARDS_VERSION } from './hs-utils' ; import { PreferencesService } from './preferences.service' ; @ Injectable ( ) export class CardsInitService { private inInit = false ; constructor ( private readonly cards , private readonly prefs ) { } public async init ( ) { console . debug ( 'starting init' ) ; if ( this . inInit ) { console . warn ( 'already in init' ) ; return ; } this . inInit = true ; const prefs = await this . prefs . getPreferences ( ) ; const fileName = this . getFileName ( prefs . locale ) ; console . log ( 'initializing cards db with' , fileName ) ; await this . cards . initializeCardsDb ( CARDS_VERSION , fileName ) ; window [ 'cards' ] = this . cards ; } private getFileName ( locale ) { switch ( locale ) { case Locale [ Locale . enUS ] : case Locale [ Locale . frFR ] : return `cards_${ locale }.json` ; default : return `cards_${ Locale [ Locale . enUS ] }.json` ; } } }