diff --git a/src/store/index.js b/src/store/index.js index d9c45f1..c479aef 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -4,9 +4,22 @@ export default createStore({ state: { id64: '', vanityUrl: '', - matchDetails: {} + matchDetails: {}, + playerDetails: {} }, mutations: { + changeId64(state, payload) { + state.id64 = payload.id + }, + changeVanityUrl(state, payload) { + state.vanityUrl = payload.id + }, + changeMatchDetails(state, payload) { + state.matchDetails = payload.data + }, + changePlayerDetails(state, payload) { + state.playerDetails = payload.data + }, }, actions: { }, diff --git a/src/utils/Utils.js b/src/utils/Utils.js index ff57b7f..3d7f7ca 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -45,3 +45,24 @@ export const getPlayerArr = (stats, team, color) => { return arr } +export const constructAvatarUrl = (hash, size) => { + const base = 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars' + const imgSize = size ? `_${size}` : '' + const hashDir = hash.substring(0, 2) + + return `${base}/${hashDir}/${hash}${imgSize}.jpg` +} + +export const GetAvgRank = (stats) => { + let count = 0 + let fullRank = 0 + + stats.map(player => { + if (player.rank?.old) { + fullRank += player.rank?.old + count += 1 + } + }) + + return count === 0 ? 0 : Math.floor(fullRank / count) +} diff --git a/src/utils/index.js b/src/utils/index.js index 102d56a..0766fdc 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -4,7 +4,7 @@ import {SaveLastVisitedToLocalStorage} from "./LocalStorage"; import {GetHLTV_1} from "./HLTV"; import {DisplayRank, LoadImage} from "./Display"; import {GetUser, TrackMe} from "./ApiRequests"; -import {setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr} from "./Utils"; +import {setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank} from "./Utils"; export { FormatDate, FormatFullDuration, FormatFullDate, FormatDuration, @@ -13,5 +13,5 @@ export { GetHLTV_1, DisplayRank, LoadImage, GetUser, TrackMe, - setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr + setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank } diff --git a/src/views/Match.vue b/src/views/Match.vue index cb75953..6f48527 100644 --- a/src/views/Match.vue +++ b/src/views/Match.vue @@ -79,9 +79,9 @@