mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor: add types for all CDragon endpoints
This commit is contained in:
parent
0fffc8127f
commit
8769d9b5bc
3 changed files with 111 additions and 29 deletions
|
|
@ -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/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/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/champion-summary.json
|
||||||
|
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/summoner-spells.json
|
||||||
|
|
||||||
public async execute () {
|
public async execute () {
|
||||||
const url = `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/${this.endpoint}`
|
const url = `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/${this.endpoint}`
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,80 @@
|
||||||
import { JaxConfig } from '../../JaxConfig'
|
import { JaxConfig } from '../../JaxConfig'
|
||||||
import CDragonRequest from '../CDragonRequest'
|
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 {
|
export default class CDragonEndpoint {
|
||||||
private config: JaxConfig
|
private config: JaxConfig
|
||||||
|
|
||||||
|
|
@ -8,23 +82,23 @@ export default class CDragonEndpoint {
|
||||||
this.config = config
|
this.config = config
|
||||||
}
|
}
|
||||||
|
|
||||||
public champions () {
|
public async champions (): Promise<ChampionDTO[]> {
|
||||||
return new CDragonRequest(this.config, 'champion-summary.json', 36000).execute()
|
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()
|
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()
|
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()
|
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()
|
return new CDragonRequest(this.config, 'summoner-spells.json', 36000).execute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import { getSeasonNumber, queuesWithRole, sortTeamByRole, supportItems } from 'App/helpers'
|
import { getSeasonNumber, queuesWithRole, sortTeamByRole, supportItems } from 'App/helpers'
|
||||||
import Jax from 'App/Services/Jax'
|
import Jax from 'App/Services/Jax'
|
||||||
import { MatchDto, ParticipantDto, ParticipantTimelineDto } from 'App/Services/Jax/src/Endpoints/MatchEndpoint'
|
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 RoleIdentificationService from 'App/Services/RoleIdentiticationService'
|
||||||
|
import { ChampionDTO, ItemDTO, PerkDTO, PerkStyleDTO, SummonerSpellDTO } from 'App/Services/Jax/src/Endpoints/CDragonEndpoint'
|
||||||
|
|
||||||
export interface PlayerRole {
|
export interface PlayerRole {
|
||||||
champion: number,
|
champion: number,
|
||||||
|
|
@ -11,11 +12,11 @@ export interface PlayerRole {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default abstract class MatchTransformer {
|
export default abstract class MatchTransformer {
|
||||||
protected champions: any
|
protected champions: ChampionDTO[]
|
||||||
protected items: any
|
protected items: ItemDTO[]
|
||||||
protected perks: any
|
protected perks: PerkDTO[]
|
||||||
protected perkstyles: any
|
protected perkstyles: PerkStyleDTO[]
|
||||||
protected summonerSpells: any
|
protected summonerSpells: SummonerSpellDTO[]
|
||||||
protected championRoles: any
|
protected championRoles: any
|
||||||
protected sortTeamByRole: (a: ParticipantBasic | ParticipantDetails, b: ParticipantBasic | ParticipantDetails) => number
|
protected sortTeamByRole: (a: ParticipantBasic | ParticipantDetails, b: ParticipantBasic | ParticipantDetails) => number
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,12 +43,18 @@ export default abstract class MatchTransformer {
|
||||||
* Get champion specific data
|
* Get champion specific data
|
||||||
* @param id of the champion
|
* @param id of the champion
|
||||||
*/
|
*/
|
||||||
public getChampion (id: number) {
|
public getChampion (id: number): Champion {
|
||||||
const champion = { ...this.champions.find((c: any) => c.id === id) }
|
const originalChampionData = this.champions.find(c => c.id === id)
|
||||||
champion.icon = 'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/'
|
const icon = 'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/'
|
||||||
+ `${champion.squarePortraitPath.split('/assets/')[1].toLowerCase()}`
|
+ originalChampionData!.squarePortraitPath.split('/assets/')[1].toLowerCase()
|
||||||
delete champion.squarePortraitPath
|
|
||||||
return champion
|
return {
|
||||||
|
icon,
|
||||||
|
id: originalChampionData!.id,
|
||||||
|
name: originalChampionData!.name,
|
||||||
|
alias: originalChampionData!.alias,
|
||||||
|
roles: originalChampionData!.roles,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -149,14 +156,14 @@ export default abstract class MatchTransformer {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const item = this.items.find((i: any) => i.id === id)
|
const item = this.items.find(i => i.id === id)
|
||||||
const itemUrl = item.iconPath.split('/assets/')[1].toLowerCase()
|
const itemUrl = item!.iconPath.split('/assets/')[1].toLowerCase()
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
image: `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${itemUrl}`,
|
image: `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${itemUrl}`,
|
||||||
name: item.name,
|
name: item!.name,
|
||||||
description: item.description,
|
description: item!.description,
|
||||||
price: item.priceTotal,
|
price: item!.priceTotal,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,11 +196,11 @@ export default abstract class MatchTransformer {
|
||||||
* @param perkSubStyle secondary perks category
|
* @param perkSubStyle secondary perks category
|
||||||
*/
|
*/
|
||||||
public getPerksImages (perk0: number, perkSubStyle: number) {
|
public getPerksImages (perk0: number, perkSubStyle: number) {
|
||||||
const firstRune = this.perks.find((p: any) => p.id === perk0)
|
const firstRune = this.perks.find(p => p.id === perk0)
|
||||||
const firstRuneUrl = firstRune.iconPath.split('/assets/')[1].toLowerCase()
|
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 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 secondRuneStyleUrl = secondRuneStyle ? secondRuneStyle.iconPath.split('/assets/')[1].toLowerCase() : null
|
||||||
const secondaryRune = secondRuneStyleUrl ?
|
const secondaryRune = secondRuneStyleUrl ?
|
||||||
|
|
@ -305,11 +312,11 @@ export default abstract class MatchTransformer {
|
||||||
if (id === 0) {
|
if (id === 0) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const spell = this.summonerSpells.find((s: any) => s.id === id)
|
const spell = this.summonerSpells.find(s => s.id === id)
|
||||||
const spellName = spell.iconPath.split('/assets/')[1].toLowerCase()
|
const spellName = spell!.iconPath.split('/assets/')[1].toLowerCase()
|
||||||
return {
|
return {
|
||||||
name: spell.name,
|
name: spell!.name,
|
||||||
description: spell.description,
|
description: spell!.description,
|
||||||
icon: `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${spellName}`,
|
icon: `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${spellName}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue