refactor: add types for all CDragon endpoints

This commit is contained in:
Valentin Kaelin 2020-10-11 17:57:43 +02:00
parent 0fffc8127f
commit 8769d9b5bc
3 changed files with 111 additions and 29 deletions

View file

@ -24,6 +24,7 @@ export default class CDragonRequest {
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/perks.json
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/perkstyles.json
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/summoner-spells.json
public async execute () {
const url = `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/${this.endpoint}`

View file

@ -1,6 +1,80 @@
import { JaxConfig } from '../../JaxConfig'
import CDragonRequest from '../CDragonRequest'
export interface ChampionDTO {
id: number,
name: string,
alias: string,
squarePortraitPath: string,
roles: string[]
}
export interface ItemDTO {
id: number,
name: string,
description: string,
active: boolean,
inStore: boolean,
from: number[],
to: number[],
categories: string[],
mapStringIdInclusions: string[],
maxStacks: number,
modeNameInclusions: string[],
requiredChampion: string,
requiredAlly: string,
requiredBuffCurrencyName: string,
requiredBuffCurrencyCost: number,
specialRecipe: number,
isEnchantment: boolean,
price: number,
priceTotal: number,
iconPath: string
}
export interface PerkDTO {
id: number,
name: string,
majorChangePatchVersion: string,
tooltip: string,
shortDesc: string,
longDesc: string,
iconPath: string,
endOfGameStatDescs: string[]
}
export interface PerkStyleResponse {
schemaVersion: string,
styles: PerkStyleDTO[]
}
export interface PerkStyleDTO {
id: number,
name: string,
tooltip: string,
iconPath: string,
assetMap: { [key: string]: string },
isAdvanced: boolean,
allowedSubStyles: number[],
subStyleBonus: { styleId: number, perkId: number }[],
slots: { type: string, slotLabel: string, perks: number[] }[],
defaultPageName: string,
defaultSubStyle: number,
defaultPerks: number[],
defaultPerksWhenSplashed: number[],
defaultStatModsPerSubStyle: { id: string, perks: number[] }[]
}
export interface SummonerSpellDTO {
id: number,
name: string,
description: string,
summonerLevel: number,
cooldown: number,
gameModes: string[],
iconPath: string
}
export default class CDragonEndpoint {
private config: JaxConfig
@ -8,23 +82,23 @@ export default class CDragonEndpoint {
this.config = config
}
public champions () {
public async champions (): Promise<ChampionDTO[]> {
return new CDragonRequest(this.config, 'champion-summary.json', 36000).execute()
}
public items () {
public async items (): Promise<ItemDTO[]> {
return new CDragonRequest(this.config, 'items.json', 36000).execute()
}
public perks () {
public async perks (): Promise<PerkDTO[]> {
return new CDragonRequest(this.config, 'perks.json', 36000).execute()
}
public perkstyles () {
public async perkstyles (): Promise<PerkStyleResponse> {
return new CDragonRequest(this.config, 'perkstyles.json', 36000).execute()
}
public summonerSpells () {
public async summonerSpells (): Promise<SummonerSpellDTO[]> {
return new CDragonRequest(this.config, 'summoner-spells.json', 36000).execute()
}
}

View file

@ -1,8 +1,9 @@
import { getSeasonNumber, queuesWithRole, sortTeamByRole, supportItems } from 'App/helpers'
import Jax from 'App/Services/Jax'
import { MatchDto, ParticipantDto, ParticipantTimelineDto } from 'App/Services/Jax/src/Endpoints/MatchEndpoint'
import { Item, ParticipantBasic, ParticipantDetails, PercentStats, Stats, SummonerSpell } from 'App/Models/Match'
import { Champion, Item, ParticipantBasic, ParticipantDetails, PercentStats, Stats, SummonerSpell } from 'App/Models/Match'
import RoleIdentificationService from 'App/Services/RoleIdentiticationService'
import { ChampionDTO, ItemDTO, PerkDTO, PerkStyleDTO, SummonerSpellDTO } from 'App/Services/Jax/src/Endpoints/CDragonEndpoint'
export interface PlayerRole {
champion: number,
@ -11,11 +12,11 @@ export interface PlayerRole {
}
export default abstract class MatchTransformer {
protected champions: any
protected items: any
protected perks: any
protected perkstyles: any
protected summonerSpells: any
protected champions: ChampionDTO[]
protected items: ItemDTO[]
protected perks: PerkDTO[]
protected perkstyles: PerkStyleDTO[]
protected summonerSpells: SummonerSpellDTO[]
protected championRoles: any
protected sortTeamByRole: (a: ParticipantBasic | ParticipantDetails, b: ParticipantBasic | ParticipantDetails) => number
/**
@ -42,12 +43,18 @@ export default abstract class MatchTransformer {
* Get champion specific data
* @param id of the champion
*/
public getChampion (id: number) {
const champion = { ...this.champions.find((c: any) => c.id === id) }
champion.icon = 'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/'
+ `${champion.squarePortraitPath.split('/assets/')[1].toLowerCase()}`
delete champion.squarePortraitPath
return champion
public getChampion (id: number): Champion {
const originalChampionData = this.champions.find(c => c.id === id)
const icon = 'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/'
+ originalChampionData!.squarePortraitPath.split('/assets/')[1].toLowerCase()
return {
icon,
id: originalChampionData!.id,
name: originalChampionData!.name,
alias: originalChampionData!.alias,
roles: originalChampionData!.roles,
}
}
/**
@ -149,14 +156,14 @@ export default abstract class MatchTransformer {
continue
}
const item = this.items.find((i: any) => i.id === id)
const itemUrl = item.iconPath.split('/assets/')[1].toLowerCase()
const item = this.items.find(i => i.id === id)
const itemUrl = item!.iconPath.split('/assets/')[1].toLowerCase()
items.push({
image: `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${itemUrl}`,
name: item.name,
description: item.description,
price: item.priceTotal,
name: item!.name,
description: item!.description,
price: item!.priceTotal,
})
}
@ -189,11 +196,11 @@ export default abstract class MatchTransformer {
* @param perkSubStyle secondary perks category
*/
public getPerksImages (perk0: number, perkSubStyle: number) {
const firstRune = this.perks.find((p: any) => p.id === perk0)
const firstRuneUrl = firstRune.iconPath.split('/assets/')[1].toLowerCase()
const firstRune = this.perks.find(p => p.id === perk0)
const firstRuneUrl = firstRune!.iconPath.split('/assets/')[1].toLowerCase()
const primaryRune = `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${firstRuneUrl}`
const secondRuneStyle = this.perkstyles.find((p: any) => p.id === perkSubStyle)
const secondRuneStyle = this.perkstyles.find(p => p.id === perkSubStyle)
const secondRuneStyleUrl = secondRuneStyle ? secondRuneStyle.iconPath.split('/assets/')[1].toLowerCase() : null
const secondaryRune = secondRuneStyleUrl ?
@ -305,11 +312,11 @@ export default abstract class MatchTransformer {
if (id === 0) {
return null
}
const spell = this.summonerSpells.find((s: any) => s.id === id)
const spellName = spell.iconPath.split('/assets/')[1].toLowerCase()
const spell = this.summonerSpells.find(s => s.id === id)
const spellName = spell!.iconPath.split('/assets/')[1].toLowerCase()
return {
name: spell.name,
description: spell.description,
name: spell!.name,
description: spell!.description,
icon: `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${spellName}`,
}
}