2019-10-21 15:37:48 +00:00
|
|
|
import { timeDifference } 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 15:37:48 +00:00
|
|
|
const leaguesNumbers = { 'I': 1, 'II': 2, 'III': 3, 'IV': 4 }
|
|
|
|
|
|
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) {
|
|
|
|
|
match.firstSum = getSummonerLink(match.firstSum)
|
|
|
|
|
match.secondSum = getSummonerLink(match.secondSum)
|
|
|
|
|
|
2019-11-28 09:06:27 +00:00
|
|
|
const date = new Date(match.date)
|
|
|
|
|
const dateOptions = { day: '2-digit', month: '2-digit', year: 'numeric' }
|
2019-12-27 17:38:43 +00:00
|
|
|
const timeOptions = { hour12: false, hour: '2-digit', minute: '2-digit' }
|
2019-11-28 09:06:27 +00:00
|
|
|
match.fullDate = { date: date.toLocaleString('fr', dateOptions), time: date.toLocaleString('fr', timeOptions) }
|
2019-10-05 22:01:58 +00:00
|
|
|
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
|
|
|
/**
|
2019-12-27 17:38:43 +00:00
|
|
|
* Return the basic infos about a summoner built with the Riot API data
|
2019-09-09 18:42:10 +00:00
|
|
|
* @param {Object} RiotData : all data from the Riot API
|
|
|
|
|
*/
|
2019-12-27 17:38:43 +00:00
|
|
|
export function createBasicSummonerData(RiotData) {
|
2019-10-05 22:01:58 +00:00
|
|
|
// Ranked Stats
|
2019-10-21 15:37:48 +00:00
|
|
|
RiotData.ranked.soloQ = getLeagueData(RiotData.ranked.soloQ, 'Solo/Duo')
|
|
|
|
|
if (!RiotData.ranked.soloQ) delete RiotData.ranked.soloQ
|
|
|
|
|
|
|
|
|
|
RiotData.ranked.flex5v5 = getLeagueData(RiotData.ranked.flex5v5, 'Flex 5vs5')
|
|
|
|
|
if (!RiotData.ranked.flex5v5) delete RiotData.ranked.flex5v5
|
|
|
|
|
|
|
|
|
|
RiotData.ranked.flex3v3 = getLeagueData(RiotData.ranked.flex3v3, 'Flex 3vs3')
|
|
|
|
|
if (!RiotData.ranked.flex3v3) delete RiotData.ranked.flex3v3
|
2019-10-08 19:54:32 +00:00
|
|
|
|
2019-10-21 15:37:48 +00:00
|
|
|
// If Summoner is Unranked
|
|
|
|
|
if (Object.entries(RiotData.ranked).length === 0) {
|
|
|
|
|
RiotData.ranked.soloQ = {
|
|
|
|
|
fullRank: 'Unranked',
|
|
|
|
|
rankImgLink: 'https://res.cloudinary.com/kln/image/upload/v1571671133/ranks/unranked.png',
|
|
|
|
|
leaguePoints: 0,
|
|
|
|
|
wins: 0,
|
|
|
|
|
losses: 0,
|
|
|
|
|
winrate: '0%',
|
|
|
|
|
name: 'Solo/Duo'
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-14 14:10:49 +00:00
|
|
|
|
2020-01-03 21:50:09 +00:00
|
|
|
return RiotData
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-12 00:35:36 +00:00
|
|
|
/**
|
|
|
|
|
* Return the formatted records of a summoner
|
|
|
|
|
* @param {Object} records : raw records from the database stats
|
|
|
|
|
*/
|
|
|
|
|
export function createRecordsData(records) {
|
|
|
|
|
const min = Math.floor(records.maxTime.time / 60)
|
|
|
|
|
let newSec = Math.floor(records.maxTime.time - min * 60)
|
|
|
|
|
newSec = newSec < 10 ? '0' + newSec : newSec
|
|
|
|
|
records.maxTime.time = `${min}:${newSec}`
|
|
|
|
|
records.maxGold.gold = records.maxGold.gold.toLocaleString()
|
|
|
|
|
records.maxDmgTaken.dmgTaken = records.maxDmgTaken.dmgTaken.toLocaleString()
|
|
|
|
|
records.maxDmgChamp.dmgChamp = records.maxDmgChamp.dmgChamp.toLocaleString()
|
|
|
|
|
records.maxDmgObj.dmgObj = records.maxDmgObj.dmgObj.toLocaleString()
|
|
|
|
|
records.maxKp.kp = `${records.maxKp.kp}%`
|
|
|
|
|
|
|
|
|
|
return records
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 15:37:48 +00:00
|
|
|
function getLeagueData(leagueData, leagueName) {
|
2019-10-08 19:54:32 +00:00
|
|
|
if (!leagueData) return null
|
|
|
|
|
|
|
|
|
|
leagueData.rankImgLink = getRankImg(leagueData)
|
2019-10-21 15:37:48 +00:00
|
|
|
leagueData.name = leagueName
|
2019-10-08 19:54:32 +00:00
|
|
|
return leagueData
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 15:37:48 +00:00
|
|
|
/**
|
|
|
|
|
* Return the link of the rank image
|
|
|
|
|
* @param leagueData : stats in soloQ of the player
|
|
|
|
|
*/
|
|
|
|
|
export function getRankImg(leagueData) {
|
|
|
|
|
return `https://res.cloudinary.com/kln/image/upload/v1571671133/ranks/${leagueData.tier}_${leaguesNumbers[leagueData.rank]}.png`
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 18:42:10 +00:00
|
|
|
function getSummonerLink(id) {
|
2019-12-27 17:38:43 +00:00
|
|
|
if (id === 0) return null
|
2019-11-25 20:15:52 +00:00
|
|
|
const spellName = summonersJSON.find(s => s.id === id).iconPath.split('/assets/')[1].toLowerCase()
|
|
|
|
|
return `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${spellName}`
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|