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'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return all the infos about a summoner built with the Riot API data
|
|
|
|
|
* @param {Object} RiotData : all data from the Riot API
|
|
|
|
|
* @param {Object} championsInfos : champions 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)
|
|
|
|
|
|
|
|
|
|
const userStats = RiotData.account
|
|
|
|
|
const soloQStats = RiotData.soloQ
|
|
|
|
|
const matches = RiotData.matchesDetails
|
|
|
|
|
|
2019-09-14 14:10:49 +00:00
|
|
|
const soloQ = soloQStats ? {} : null
|
|
|
|
|
if (soloQ) {
|
2019-09-14 21:19:10 +00:00
|
|
|
soloQ.rank = `${soloQStats.tier} ${soloQStats.rank}`
|
2019-09-14 14:10:49 +00:00
|
|
|
soloQ.rankImgLink = getRankImg(soloQStats)
|
|
|
|
|
soloQ.wins = soloQStats.wins
|
|
|
|
|
soloQ.losses = soloQStats.losses
|
2019-09-19 17:58:29 +00:00
|
|
|
soloQ.winrate = +(soloQ.wins * 100 / (soloQ.wins + soloQ.losses)).toFixed(1) + '%'
|
2019-09-16 19:20:48 +00:00
|
|
|
soloQ.lp = soloQStats.leaguePoints
|
2019-09-14 14:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-29 16:06:54 +00:00
|
|
|
for (const match of matches) {
|
|
|
|
|
for (let i = 0; i < match.items.length; i++) {
|
|
|
|
|
match.items[i] = getItemLink(match.items[i])
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-29 16:06:54 +00:00
|
|
|
match.firstSum = getSummonerLink(match.firstSum)
|
|
|
|
|
match.secondSum = getSummonerLink(match.secondSum)
|
2019-09-09 18:42:10 +00:00
|
|
|
|
2019-09-29 16:06:54 +00:00
|
|
|
match.date = timeDifference(match.date)
|
2019-09-20 21:32:28 +00:00
|
|
|
|
2019-09-29 16:06:54 +00:00
|
|
|
match.map = maps[match.map]
|
|
|
|
|
match.gamemode = gameModes[match.gamemode]
|
|
|
|
|
if (!match.gamemode) match.gamemode = 'Undefined gamemode'
|
2019-09-09 18:42:10 +00:00
|
|
|
} // end loop matches
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
accountId: userStats.accountId,
|
|
|
|
|
allMatches: RiotData.allMatches,
|
2019-09-29 16:06:54 +00:00
|
|
|
matches: RiotData.matchesDetails,
|
2019-09-09 18:42:10 +00:00
|
|
|
profileIconId: userStats.profileIconId,
|
|
|
|
|
name: userStats.name,
|
|
|
|
|
level: userStats.summonerLevel,
|
2019-09-14 14:10:49 +00:00
|
|
|
soloQ,
|
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
|
|
|
|
|
}
|
|
|
|
|
return `url('https://ddragon.leagueoflegends.com/cdn/${process.env.VUE_APP_PATCH}/img/item/${id}.png')`
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSummonerLink(id) {
|
|
|
|
|
const spellName = Object.entries(summonersJSON.data).find(([, spell]) => Number(spell.key) === id)[0]
|
|
|
|
|
return `https://ddragon.leagueoflegends.com/cdn/${process.env.VUE_APP_PATCH}/img/spell/${spellName}.png`
|
|
|
|
|
}
|