2021-09-13 22:06:12 +00:00
|
|
|
import Jax from 'App/Services/Jax'
|
|
|
|
|
import {
|
|
|
|
|
ChampionDTO,
|
|
|
|
|
ItemDTO,
|
|
|
|
|
PerkDTO,
|
|
|
|
|
PerkStyleDTO,
|
|
|
|
|
SummonerSpellDTO,
|
|
|
|
|
} from 'App/Services/Jax/src/Endpoints/CDragonEndpoint'
|
|
|
|
|
import RoleIdentificationService, {
|
|
|
|
|
ChampionsPlayRate,
|
|
|
|
|
} from 'App/Services/RoleIdentificationService'
|
|
|
|
|
|
2021-09-14 11:31:35 +00:00
|
|
|
interface Identifiable {
|
|
|
|
|
id: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CDragonCache<T> {
|
2021-09-14 14:03:08 +00:00
|
|
|
[id: string]: T
|
2021-09-14 11:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-13 22:06:12 +00:00
|
|
|
class CDragonService {
|
2021-09-14 11:31:35 +00:00
|
|
|
public champions: CDragonCache<ChampionDTO>
|
|
|
|
|
public items: CDragonCache<ItemDTO>
|
|
|
|
|
public perks: CDragonCache<PerkDTO>
|
|
|
|
|
public perkstyles: CDragonCache<PerkStyleDTO>
|
|
|
|
|
public summonerSpells: CDragonCache<SummonerSpellDTO>
|
2021-09-13 22:06:12 +00:00
|
|
|
public championRoles: ChampionsPlayRate
|
|
|
|
|
|
2021-09-14 11:31:35 +00:00
|
|
|
public readonly BASE_URL =
|
|
|
|
|
'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/'
|
|
|
|
|
|
|
|
|
|
private setupCache<T extends Identifiable>(dto: T[]) {
|
|
|
|
|
return dto.reduce((obj, item) => ((obj[item.id] = item), obj), {})
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 22:06:12 +00:00
|
|
|
/**
|
|
|
|
|
* Get global Context with CDragon Data
|
|
|
|
|
*/
|
|
|
|
|
public async getContext() {
|
|
|
|
|
const items = await Jax.CDragon.items()
|
|
|
|
|
const champions = await Jax.CDragon.champions()
|
|
|
|
|
const perks = await Jax.CDragon.perks()
|
|
|
|
|
const perkstyles = await Jax.CDragon.perkstyles()
|
|
|
|
|
const summonerSpells = await Jax.CDragon.summonerSpells()
|
|
|
|
|
const championRoles = await RoleIdentificationService.pullData().catch(() => {})
|
|
|
|
|
|
2021-09-14 11:31:35 +00:00
|
|
|
this.champions = this.setupCache(champions)
|
|
|
|
|
this.items = this.setupCache(items)
|
|
|
|
|
this.perks = this.setupCache(perks)
|
|
|
|
|
this.perkstyles = this.setupCache(perkstyles.styles)
|
|
|
|
|
this.summonerSpells = this.setupCache(summonerSpells)
|
2021-09-13 22:06:12 +00:00
|
|
|
this.championRoles = championRoles as ChampionsPlayRate
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new CDragonService()
|