2019-09-29 16:06:54 +00:00
|
|
|
import { timeDifference, getRankImg } from '@/helpers/functions.js'
|
2019-09-09 18:42:10 +00:00
|
|
|
import { maps, gameModes } from '@/data/data.js'
|
|
|
|
|
import summonersJSON from '@/data/summoner.json'
|
2019-10-21 13:30:48 +00:00
|
|
|
import store from '@/store'
|
2019-09-09 18:42:10 +00:00
|
|
|
|
2019-10-05 22:01:58 +00:00
|
|
|
/**
|
|
|
|
|
* Return all the infos about a list of matches built with the Riot API data
|
|
|
|
|
* @param {Object} RiotData : all data from the Riot API
|
|
|
|
|
*/
|
|
|
|
|
export function createMatchData(matches) {
|
|
|
|
|
for (const match of matches) {
|
|
|
|
|
for (let i = 0; i < match.items.length; i++) {
|
|
|
|
|
match.items[i] = getItemLink(match.items[i])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
match.firstSum = getSummonerLink(match.firstSum)
|
|
|
|
|
match.secondSum = getSummonerLink(match.secondSum)
|
|
|
|
|
|
|
|
|
|
match.date = timeDifference(match.date)
|
|
|
|
|
|
|
|
|
|
match.map = maps[match.map]
|
|
|
|
|
match.gamemode = gameModes[match.gamemode]
|
|
|
|
|
if (!match.gamemode) match.gamemode = 'Undefined gamemode'
|
|
|
|
|
} // end loop matches
|
|
|
|
|
|
|
|
|
|
return matches
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 18:42:10 +00:00
|
|
|
/**
|
|
|
|
|
* Return all the infos about a summoner built with the Riot API data
|
|
|
|
|
* @param {Object} RiotData : all data from the Riot API
|
|
|
|
|
*/
|
2019-09-29 16:06:54 +00:00
|
|
|
export function createSummonerData(RiotData) {
|
2019-09-09 18:42:10 +00:00
|
|
|
console.log('--- ALL INFOS ---')
|
|
|
|
|
console.log(RiotData)
|
|
|
|
|
|
2019-10-05 22:01:58 +00:00
|
|
|
// Ranked Stats
|
2019-10-08 19:54:32 +00:00
|
|
|
const uniqueLeagues = ['CHALLENGER', 'GRANDMASTER', 'MASTER']
|
|
|
|
|
RiotData.ranked.soloQ = getLeagueData(uniqueLeagues, RiotData.ranked.soloQ)
|
|
|
|
|
RiotData.ranked.soloQ ? RiotData.ranked.soloQ.name = 'Solo/Duo' : delete RiotData.ranked.soloQ
|
|
|
|
|
|
|
|
|
|
RiotData.ranked.flex5v5 = getLeagueData(uniqueLeagues, RiotData.ranked.flex5v5)
|
|
|
|
|
RiotData.ranked.flex5v5 ? RiotData.ranked.flex5v5.name = 'Flex 5vs5' : delete RiotData.ranked.flex5v5
|
2019-09-14 14:10:49 +00:00
|
|
|
|
2019-09-09 18:42:10 +00:00
|
|
|
return {
|
2019-10-05 22:01:58 +00:00
|
|
|
account: RiotData.account,
|
2019-10-08 19:54:32 +00:00
|
|
|
ranked: RiotData.ranked,
|
2019-10-05 22:01:58 +00:00
|
|
|
matchList: RiotData.allMatches,
|
|
|
|
|
matches: createMatchData(RiotData.matchesDetails)
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getItemLink(id) {
|
2019-09-20 21:32:28 +00:00
|
|
|
if (id === 0) {
|
2019-09-19 17:26:44 +00:00
|
|
|
return null
|
|
|
|
|
}
|
2019-10-21 13:30:48 +00:00
|
|
|
return `url('https://ddragon.leagueoflegends.com/cdn/${store.getters['ddragon/version']}/img/item/${id}.png')`
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-08 19:54:32 +00:00
|
|
|
function getLeagueData(uniqueLeagues, leagueData) {
|
|
|
|
|
if (!leagueData) return null
|
|
|
|
|
|
|
|
|
|
leagueData.rank = uniqueLeagues.includes(leagueData.tier) ? leagueData.tier : `${leagueData.tier} ${leagueData.rank}`
|
|
|
|
|
leagueData.rankImgLink = getRankImg(leagueData)
|
|
|
|
|
leagueData.winrate = +(leagueData.wins * 100 / (leagueData.wins + leagueData.losses)).toFixed(1) + '%'
|
|
|
|
|
return leagueData
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 18:42:10 +00:00
|
|
|
function getSummonerLink(id) {
|
|
|
|
|
const spellName = Object.entries(summonersJSON.data).find(([, spell]) => Number(spell.key) === id)[0]
|
2019-10-21 13:30:48 +00:00
|
|
|
return `https://ddragon.leagueoflegends.com/cdn/${store.getters['ddragon/version']}/img/spell/${spellName}.png`
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|