2021-09-13 23:19:47 +00:00
|
|
|
import { createCDragonAssetUrl, secToTime, timeDifference } from '@/helpers/functions.js'
|
2019-09-09 18:42:10 +00:00
|
|
|
import { maps, gameModes } from '@/data/data.js'
|
2021-09-13 23:19:47 +00:00
|
|
|
import store from '@/store'
|
2019-09-09 18:42:10 +00:00
|
|
|
|
2019-10-21 15:37:48 +00:00
|
|
|
const leaguesNumbers = { 'I': 1, 'II': 2, 'III': 3, 'IV': 4 }
|
|
|
|
|
|
2021-09-16 15:10:09 +00:00
|
|
|
/**
|
2021-09-17 20:57:57 +00:00
|
|
|
* Get the url of the of the player primary rune
|
2021-09-16 15:10:09 +00:00
|
|
|
* @param {Object} perks : from the API
|
|
|
|
|
*/
|
2021-09-17 20:57:57 +00:00
|
|
|
export function getPrimarRune(perks) {
|
2021-09-16 15:10:09 +00:00
|
|
|
const primaryRune = perks.selected.length ? store.state.cdragon.runes.perks[perks.selected[0]] : null
|
2021-09-17 20:57:57 +00:00
|
|
|
return primaryRune ? createCDragonAssetUrl(primaryRune.icon) : null
|
|
|
|
|
}
|
2021-09-16 15:10:09 +00:00
|
|
|
|
2021-09-17 20:57:57 +00:00
|
|
|
/**
|
|
|
|
|
* Get the url of the of the player secondary rune
|
|
|
|
|
* @param {Object} perks : from the API
|
|
|
|
|
*/
|
|
|
|
|
export function getSecondaryRune(perks) {
|
|
|
|
|
const secondaryRune = store.state.cdragon.runes.perkstyles[perks.secondaryStyle]
|
|
|
|
|
return secondaryRune ? createCDragonAssetUrl(secondaryRune.icon) : null
|
2021-09-16 15:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-05 22:01:58 +00:00
|
|
|
/**
|
2022-02-01 20:38:19 +00:00
|
|
|
* Return all the infos about a list of matches built with the api data
|
|
|
|
|
* @param {Object} matches : all data from the api matches endpoint
|
2019-10-05 22:01:58 +00:00
|
|
|
*/
|
|
|
|
|
export function createMatchData(matches) {
|
|
|
|
|
for (const match of matches) {
|
2021-09-13 23:19:47 +00:00
|
|
|
// Runes
|
2021-09-17 20:57:57 +00:00
|
|
|
match.primaryRune = getPrimarRune(match.perks)
|
|
|
|
|
match.secondaryRune = getSecondaryRune(match.perks)
|
2021-09-13 23:19:47 +00:00
|
|
|
|
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' }
|
2020-04-03 10:40:22 +00:00
|
|
|
match.fullDate = { date: date.toLocaleString(undefined, dateOptions), time: date.toLocaleString(undefined, timeOptions) }
|
2019-10-05 22:01:58 +00:00
|
|
|
match.date = timeDifference(match.date)
|
|
|
|
|
|
|
|
|
|
match.map = maps[match.map]
|
|
|
|
|
match.gamemode = gameModes[match.gamemode]
|
2021-07-25 20:52:59 +00:00
|
|
|
if (!match.gamemode) {
|
|
|
|
|
match.gamemode = { name: 'Unknown gamemode' }
|
|
|
|
|
}
|
2022-02-01 20:38:19 +00:00
|
|
|
}
|
2019-10-05 22:01:58 +00:00
|
|
|
|
|
|
|
|
return matches
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 18:42:10 +00:00
|
|
|
/**
|
2022-02-01 20:38:19 +00:00
|
|
|
* Return the formatted basic info for a summoner
|
|
|
|
|
* @param {Object} summonerBasic : all data from the api basic endpoint
|
2019-09-09 18:42:10 +00:00
|
|
|
*/
|
2022-02-01 20:38:19 +00:00
|
|
|
export function createBasicSummonerData(summonerBasic) {
|
2019-10-05 22:01:58 +00:00
|
|
|
// Ranked Stats
|
2022-02-01 20:38:19 +00:00
|
|
|
summonerBasic.ranked.soloQ = getLeagueData(summonerBasic.ranked.soloQ, 'Solo/Duo')
|
|
|
|
|
if (!summonerBasic.ranked.soloQ) delete summonerBasic.ranked.soloQ
|
2019-10-21 15:37:48 +00:00
|
|
|
|
2022-02-01 20:38:19 +00:00
|
|
|
summonerBasic.ranked.flex5v5 = getLeagueData(summonerBasic.ranked.flex5v5, 'Flex 5vs5')
|
|
|
|
|
if (!summonerBasic.ranked.flex5v5) delete summonerBasic.ranked.flex5v5
|
2019-10-21 15:37:48 +00:00
|
|
|
|
2022-02-01 20:38:19 +00:00
|
|
|
summonerBasic.ranked.flex3v3 = getLeagueData(summonerBasic.ranked.flex3v3, 'Flex 3vs3')
|
|
|
|
|
if (!summonerBasic.ranked.flex3v3) delete summonerBasic.ranked.flex3v3
|
2019-10-08 19:54:32 +00:00
|
|
|
|
2019-10-21 15:37:48 +00:00
|
|
|
// If Summoner is Unranked
|
2022-02-01 20:38:19 +00:00
|
|
|
if (Object.entries(summonerBasic.ranked).length === 0) {
|
|
|
|
|
summonerBasic.ranked.soloQ = {
|
2019-10-21 15:37:48 +00:00
|
|
|
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
|
|
|
|
2022-02-01 20:38:19 +00:00
|
|
|
return summonerBasic
|
2019-09-09 18:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-12 00:35:36 +00:00
|
|
|
/**
|
|
|
|
|
* Return the formatted records of a summoner
|
2021-09-16 12:23:09 +00:00
|
|
|
* @param {Object} recordsDto : raw records from the database stats
|
2020-01-12 00:35:36 +00:00
|
|
|
*/
|
2021-09-16 12:23:09 +00:00
|
|
|
export function createRecordsData(recordsDto) {
|
|
|
|
|
const records = recordsDto.reduce((acc, record) => {
|
|
|
|
|
acc[record.what] = record
|
|
|
|
|
return acc
|
|
|
|
|
}, {})
|
|
|
|
|
|
|
|
|
|
records.game_duration.amount = secToTime(records.game_duration.amount)
|
|
|
|
|
records.gold.amount = records.gold.amount.toLocaleString()
|
|
|
|
|
records.damage_taken.amount = records.damage_taken.amount.toLocaleString()
|
|
|
|
|
records.damage_dealt_champions.amount = records.damage_dealt_champions.amount.toLocaleString()
|
|
|
|
|
records.damage_dealt_objectives.amount = records.damage_dealt_objectives.amount.toLocaleString()
|
|
|
|
|
records.kp.amount = `${records.kp.amount}%`
|
|
|
|
|
records.time_spent_living.amount = secToTime(records.time_spent_living.amount)
|
|
|
|
|
records.heal.amount = records.heal.amount.toLocaleString()
|
2020-08-28 10:09:28 +00:00
|
|
|
|
2020-01-12 00:35:36 +00:00
|
|
|
return records
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 20:38:19 +00:00
|
|
|
/**
|
|
|
|
|
* Add rank img and ranked data
|
|
|
|
|
* @param {Object} leagueData
|
|
|
|
|
* @param {String} leagueName
|
|
|
|
|
*/
|
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`
|
|
|
|
|
}
|