import { Injectable } from '@angular/core' ; import { TranslateService } from '@ngx-translate/core' ; import { map } from 'rxjs/operators' ; import { CardsFacadeService } from './cards-facade.service' ; import { formatClass } from './hs-utils' ; import { LocalizationFacadeService } from './localization-facade.service' ; import { OverwolfService } from './overwolf.service' ; import { AppUiStoreFacadeService } from './ui-store/app-ui-store-facade.service' ; import { capitalizeEachWord } from './utils' ; @ Injectable ( ) export class LocalizationService { private locale = 'enUS' ; private useHighResImages : boolean ; private translate : TranslateService ; constructor ( private readonly store , private readonly allCards , private readonly ow ) { } public async start ( ) { await this . store . initComplete ( ) ; this . translate = this . ow . getMainWindow ( ) . translateService ; this . store . listen$ ( ( [ main , nav , prefs ] ) => prefs ?. locale ) . pipe ( map ( ( [ pref ] ) => pref ) ) . subscribe ( ( pref ) => { this . locale = pref ; } ) ; this . store . listen$ ( ( [ main , nav , prefs ] ) => prefs . collectionUseHighResImages ) . pipe ( map ( ( [ pref ] ) => pref ) ) . subscribe ( ( pref ) => { this . useHighResImages = pref ; } ) ; window [ 'localizationService' ] = this ; } public getCardImage ( cardId , options ? ) { if ( ! cardId ) { return null ; } const bgs = options ?. isBgs ? 'bgs/' : '' ; const heroSkin = options ?. isHeroSkin ? 'heroSkins/' : '' ; const highRes = this . useHighResImages || options ?. isHighRes ? '512' : '256' ; const base = `https://static.firestoneapp.com/cards/${ bgs }${ heroSkin }${ this . locale }/${ highRes }` ; const suffix = `${ cardId }${ options ?. isPremium ? '_golden' : '' }.png` ; return `${ base }/${ suffix }?v=2` ; } public getNonLocalizedCardImage ( cardId , options ? ) { if ( ! cardId ) { return null ; } const base = `https://static.firestoneapp.com/cards` ; const suffix = `${ cardId }${ options ?. isPremium ? '_golden' : '' }.png` ; return `${ base }/${ suffix }?v=2` ; } public getCardName ( cardId , defaultName = null ) { const card = this . allCards . getCard ( cardId ) ; return card ?. name ?? defaultName ; } public getCreatedByCardName ( creatorCardId ) { return `Created by ${ this . getCardName ( creatorCardId ) ?? 'unknown' }` ; } public getUnknownCardName ( i18n , playerClass = null ) { return playerClass ? `Unknown ${ formatClass ( playerClass , i18n ) } card` : 'Unknown Card' ; } public getUnknownManaSpellName ( manaCost ) { return `Unknown ${ manaCost } mana spell` ; } public getUnknownRaceName ( race ) { return `Unknown ${ capitalizeEachWord ( race ) }` ; } public translateString ( key , params = null ) { return this . translate . instant ( key , params ) ; } public formatCurrentLocale ( ) { switch ( this . locale ) { case 'frFR' : return 'fr-FR' ; default : return 'en-US' ; } } } export interface ImageLocalizationOptions { readonly isBgs ? : boolean ; readonly isPremium ? : boolean ; readonly isHighRes ? : boolean ; readonly isHeroSkin ? : boolean ; }