2019-09-09 18:42:10 +00:00
|
|
|
import { timeDifference, secToTime, getRankImg } from '@/helpers/functions.js'
|
|
|
|
|
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-16 19:20:48 +00:00
|
|
|
export function createSummonerData(RiotData, championsInfos, runesInfos) {
|
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-09 18:42:10 +00:00
|
|
|
const matchesInfos = []
|
|
|
|
|
// Loop on all matches
|
|
|
|
|
for (let i = 0; i < matches.length; i++) {
|
|
|
|
|
const currentMatch = matches[i]
|
2019-09-19 17:26:44 +00:00
|
|
|
const participantId = currentMatch.participantIdentities.find((p) => p.player.currentAccountId === userStats.accountId).participantId
|
|
|
|
|
const player = currentMatch.participants[participantId - 1]
|
|
|
|
|
const teamId = player.teamId
|
2019-09-09 18:42:10 +00:00
|
|
|
|
2019-09-16 19:20:48 +00:00
|
|
|
let win = currentMatch.teams.find((t) => t.teamId === teamId).win
|
2019-09-24 16:08:03 +00:00
|
|
|
let status = win === 'Win' ? 'Victory' : 'Defeat'
|
2019-09-16 19:20:48 +00:00
|
|
|
|
|
|
|
|
// Match less than 5min
|
|
|
|
|
if (currentMatch.gameDuration < 300) {
|
|
|
|
|
win = 'Remake'
|
2019-09-24 16:08:03 +00:00
|
|
|
status = 'Remake'
|
2019-09-16 19:20:48 +00:00
|
|
|
}
|
2019-09-09 18:42:10 +00:00
|
|
|
|
|
|
|
|
const map = maps[currentMatch.mapId]
|
|
|
|
|
let mode = gameModes[currentMatch.queueId]
|
|
|
|
|
if (!mode)
|
|
|
|
|
mode = 'Undefined gamemode'
|
2019-09-20 21:32:28 +00:00
|
|
|
const champion = (({ id, name }) => ({ id, name }))(Object.entries(championsInfos).find(([, champion]) => Number(champion.key) === player.championId)[1])
|
|
|
|
|
const role = getRoleName(player.timeline)
|
2019-09-19 17:26:44 +00:00
|
|
|
|
2019-09-09 18:42:10 +00:00
|
|
|
const timeAgo = timeDifference(currentMatch.gameCreation)
|
|
|
|
|
const time = secToTime(currentMatch.gameDuration)
|
2019-09-19 17:26:44 +00:00
|
|
|
const kills = player.stats.kills
|
|
|
|
|
const deaths = player.stats.deaths
|
|
|
|
|
const assists = player.stats.assists
|
2019-09-22 15:39:29 +00:00
|
|
|
let kda
|
|
|
|
|
if (kills + assists !== 0 && deaths === 0) {
|
|
|
|
|
kda = '∞'
|
|
|
|
|
} else {
|
|
|
|
|
kda = +(deaths === 0 ? 0 : ((kills + assists) / deaths)).toFixed(2)
|
|
|
|
|
}
|
2019-09-19 17:26:44 +00:00
|
|
|
const level = player.stats.champLevel
|
2019-09-19 17:58:29 +00:00
|
|
|
const damage = +(player.stats.totalDamageDealtToChampions / 1000).toFixed(1) + 'k'
|
2019-09-16 19:20:48 +00:00
|
|
|
|
2019-09-19 17:26:44 +00:00
|
|
|
const primaryRuneCategory = runesInfos.find(r => r.id === player.stats.perkPrimaryStyle)
|
2019-09-16 19:20:48 +00:00
|
|
|
let primaryRune
|
|
|
|
|
for (const subCat of primaryRuneCategory.slots) {
|
2019-09-19 17:26:44 +00:00
|
|
|
primaryRune = subCat.runes.find(r => r.id === player.stats.perk0)
|
2019-09-16 19:20:48 +00:00
|
|
|
if (primaryRune) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
primaryRune = `https://ddragon.leagueoflegends.com/cdn/img/${primaryRune.icon}`
|
2019-09-19 17:26:44 +00:00
|
|
|
let secondaryRune = runesInfos.find(r => r.id === player.stats.perkSubStyle)
|
2019-09-16 19:20:48 +00:00
|
|
|
secondaryRune = `https://ddragon.leagueoflegends.com/cdn/img/${secondaryRune.icon}`
|
|
|
|
|
|
|
|
|
|
const totalKills = currentMatch.participants.reduce((prev, current) => {
|
|
|
|
|
if (current.teamId !== teamId) {
|
|
|
|
|
return prev
|
|
|
|
|
}
|
|
|
|
|
return prev + current.stats.kills
|
|
|
|
|
}, 0)
|
2019-09-19 17:58:29 +00:00
|
|
|
const kp = +((kills + assists) * 100 / totalKills).toFixed(1) + '%'
|
2019-09-09 18:42:10 +00:00
|
|
|
|
|
|
|
|
const items = []
|
|
|
|
|
for (let i = 0; i < 6; i++) {
|
|
|
|
|
const currentItem = 'item' + i
|
2019-09-19 17:26:44 +00:00
|
|
|
items.push(getItemLink(player.stats[currentItem]))
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-19 17:58:29 +00:00
|
|
|
const gold = +(player.stats.goldEarned / 1000).toFixed(1) + 'k'
|
2019-09-19 17:26:44 +00:00
|
|
|
const minions = player.stats.totalMinionsKilled + player.stats.neutralMinionsKilled
|
2019-09-09 18:42:10 +00:00
|
|
|
|
2019-09-19 17:26:44 +00:00
|
|
|
const firstSum = player.spell1Id
|
|
|
|
|
const secondSum = player.spell2Id
|
2019-09-09 18:42:10 +00:00
|
|
|
|
2019-09-20 21:32:28 +00:00
|
|
|
const allyTeam = []
|
|
|
|
|
const enemyTeam = []
|
|
|
|
|
for (let summoner of currentMatch.participantIdentities) {
|
|
|
|
|
const allData = currentMatch.participants[summoner.participantId - 1]
|
|
|
|
|
const playerInfos = {
|
|
|
|
|
name: summoner.player.summonerName,
|
|
|
|
|
role: getRoleName(allData.timeline),
|
|
|
|
|
champion: (({ id, name }) => ({ id, name }))(Object.entries(championsInfos).find(([, champion]) => Number(champion.key) === allData.championId)[1])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (allData.teamId === teamId) {
|
|
|
|
|
allyTeam.push(playerInfos)
|
|
|
|
|
} else {
|
|
|
|
|
enemyTeam.push(playerInfos)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
allyTeam.sort(sortTeamByRole)
|
|
|
|
|
enemyTeam.sort(sortTeamByRole)
|
|
|
|
|
|
2019-09-09 18:42:10 +00:00
|
|
|
matchesInfos.push({
|
|
|
|
|
result: win,
|
2019-09-24 16:08:03 +00:00
|
|
|
status,
|
2019-09-20 21:32:28 +00:00
|
|
|
map,
|
2019-09-09 18:42:10 +00:00
|
|
|
gamemode: mode,
|
2019-09-20 21:32:28 +00:00
|
|
|
champion,
|
|
|
|
|
role,
|
2019-09-16 19:20:48 +00:00
|
|
|
primaryRune,
|
|
|
|
|
secondaryRune,
|
2019-09-09 18:42:10 +00:00
|
|
|
date: timeAgo,
|
2019-09-20 21:32:28 +00:00
|
|
|
time,
|
|
|
|
|
kills,
|
|
|
|
|
deaths,
|
|
|
|
|
assists,
|
2019-09-16 19:20:48 +00:00
|
|
|
kda,
|
2019-09-20 21:32:28 +00:00
|
|
|
level,
|
2019-09-16 19:20:48 +00:00
|
|
|
damage,
|
|
|
|
|
kp,
|
2019-09-20 21:32:28 +00:00
|
|
|
items,
|
|
|
|
|
gold,
|
|
|
|
|
minions,
|
2019-09-09 18:42:10 +00:00
|
|
|
firstSum: getSummonerLink(firstSum),
|
2019-09-20 21:32:28 +00:00
|
|
|
secondSum: getSummonerLink(secondSum),
|
|
|
|
|
allyTeam,
|
|
|
|
|
enemyTeam
|
2019-09-09 18:42:10 +00:00
|
|
|
})
|
|
|
|
|
} // end loop matches
|
|
|
|
|
console.log('matches infos just below')
|
|
|
|
|
console.log(matchesInfos)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
accountId: userStats.accountId,
|
|
|
|
|
allMatches: RiotData.allMatches,
|
|
|
|
|
matches: matchesInfos,
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2019-09-20 21:32:28 +00:00
|
|
|
function getRoleName(timeline) {
|
|
|
|
|
if (timeline.lane === 'BOTTOM' && timeline.role.includes('SUPPORT')) {
|
|
|
|
|
return 'SUPPORT'
|
|
|
|
|
}
|
|
|
|
|
return timeline.lane
|
|
|
|
|
}
|
|
|
|
|
|
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`
|
|
|
|
|
}
|
2019-09-20 21:32:28 +00:00
|
|
|
|
|
|
|
|
function sortTeamByRole(a, b) {
|
2019-09-22 15:39:29 +00:00
|
|
|
const sortingArr = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
|
2019-09-20 21:32:28 +00:00
|
|
|
return sortingArr.indexOf(a.role) - sortingArr.indexOf(b.role)
|
|
|
|
|
}
|