diff --git a/src/components/Nav.vue b/src/components/Nav.vue index a7bf224..6da69f6 100644 --- a/src/components/Nav.vue +++ b/src/components/Nav.vue @@ -1,12 +1,19 @@ diff --git a/src/utils/DateTime.js b/src/utils/DateTime.js new file mode 100644 index 0000000..128ab7e --- /dev/null +++ b/src/utils/DateTime.js @@ -0,0 +1,48 @@ +import {DateTime, Duration} from "luxon/build/es6/luxon"; + +export const FormatDuration = (d) => { + const duration = Duration.fromObject({hours: 0, minutes: 0, seconds: d}).normalize().toObject() + + if (duration.hours > 1) + return `${duration.hours} h ${duration.minutes} min` + else if (duration.hours < 1) + return `${duration.minutes} min` +} + +export const FormatFullDuration = (d) => { + const duration = Duration.fromObject({hours: 0, minutes: 0, seconds: d}).normalize() + + if (duration.hours > 1) + return duration.toFormat('hh:mm:ss') + else if (duration.hours < 1) + return duration.toFormat('mm:ss') +} + +export const FormatDate = (date) => { + const matchDate = DateTime.fromISO(date) + const diff = DateTime.now().diff(matchDate) + + if (diff.as('days') > 10) + return matchDate.toLocaleString({weekday: 'short', day: '2-digit', month: '2-digit', year: 'numeric'}) + else if (diff.as('days') < 1) + if (diff.as('hours') < 1) + return Math.floor(diff.as('minutes')) + ' minutes ago' + else + return Math.floor(diff.as('hours')) + ' hours ago' + else + return Math.floor(diff.as('days')) + ' days ago' +} + +export const FormatFullDate = (date) => { + const matchDate = DateTime.fromISO(date) + + return matchDate.toLocaleString({ + weekday: 'short', + day: '2-digit', + month: '2-digit', + year: 'numeric', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }) +} \ No newline at end of file diff --git a/src/utils/Display.js b/src/utils/Display.js new file mode 100644 index 0000000..b6329c5 --- /dev/null +++ b/src/utils/Display.js @@ -0,0 +1,24 @@ +export const DisplayRank = (rankNr = 0) => { + const rankMap = new Map([ + [0, 'Unranked'], + [1, 'Silver I'], + [2, 'Silver II'], + [3, 'Silver III'], + [4, 'Silver IV'], + [5, 'Silver Elite'], + [6, 'Silver Elite Master'], + [7, 'Gold Nova I'], + [8, 'Gold Nova II'], + [9, 'Gold Nova III'], + [10, 'Gold Nova IV'], + [11, 'Master Guardian I'], + [12, 'Master Guardian II'], + [13, 'Master Guardian Elite'], + [14, 'Distinguished Master Guardian'], + [15, 'Legendary Eagle'], + [16, 'Legendary Eagle Master'], + [17, 'Supreme Master First Class'], + [18, 'Global Elite'], + ]) + return [require(`../images/rank_icons/skillgroup${rankNr}.svg`), rankMap.get(rankNr)] +} \ No newline at end of file diff --git a/src/utils/GoTo.js b/src/utils/GoTo.js new file mode 100644 index 0000000..43425d6 --- /dev/null +++ b/src/utils/GoTo.js @@ -0,0 +1,9 @@ +import router from "../router"; + +export const GoToMatch = (id) => { + router.push(`/match/${id}`) +} + +export const GoToPlayer = (id) => { + router.push(`/player/${id}`) +} \ No newline at end of file diff --git a/src/utils/HLTV.js b/src/utils/HLTV.js new file mode 100644 index 0000000..61aa04f --- /dev/null +++ b/src/utils/HLTV.js @@ -0,0 +1,12 @@ +export const GetHLTV_1 = (kills = 0, rounds, deaths = 0, k2 = 0, k3 = 0, k4 = 0, k5 = 0) => { + const k1 = kills - k2 - k3 - k4 - k5 + const Weight_KPR = 0.679 // weight kills per round + const Weight_SPR = 0.317 // weight survived rounds per round + const Weight_RMK = 1.277 // weight value calculated from rounds with multiple kills (1k + 4*2k + 9*3k + 16*4k + 25*5k) + + const KillRating = kills / rounds / Weight_KPR + const SurvivalRating = (rounds - deaths) / rounds / Weight_SPR + const RoundsWithMultipleKillsRating = (k1 + 4 * k2 + 9 * k3 + 16 * k4 + 25 * k5) / rounds / Weight_RMK + + return ((KillRating + 0.7 * SurvivalRating + RoundsWithMultipleKillsRating) / 2.7).toFixed(2) +} \ No newline at end of file diff --git a/src/utils/LocalStorage.js b/src/utils/LocalStorage.js new file mode 100644 index 0000000..55293ef --- /dev/null +++ b/src/utils/LocalStorage.js @@ -0,0 +1,25 @@ +export const SaveLastVisitedToLocalStorage = (data) => { + let a = JSON.parse(localStorage.getItem('recent-visited')) || []; + + if (a.length === 0) { + a.push(data); + } else if (a.length === 9) { + if (a.find(p => p.steamid64 === data.steamid64)) { + a.shift() + a.splice(a.findIndex(i => i.steamid64 === data.steamid64), 1) + a.push(data) + } else if (!a.find(p => p.steamid64 === data.steamid64)) { + a.shift() + a.push(data) + } + } else if (a.length > 0 && a.length < 9) { + if (a.find(p => p.steamid64 === data.steamid64)) { + a.splice(a.findIndex(i => i.steamid64 === data.steamid64), 1) + a.push(data) + } else if (!a.find(p => p.steamid64 === data.steamid64)) { + a.push(data) + } + } + + localStorage.setItem('recent-visited', JSON.stringify(a)); +} \ No newline at end of file diff --git a/src/utils/index.js b/src/utils/index.js index c9f2767..a805929 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,96 +1,13 @@ -import {DateTime, Duration} from "luxon/build/es6/luxon"; -import router from '../router' +import {FormatDate, FormatDuration, FormatFullDate, FormatFullDuration} from "./DateTime"; +import {GoToMatch, GoToPlayer} from "./GoTo"; +import {SaveLastVisitedToLocalStorage} from "./LocalStorage"; +import {GetHLTV_1} from "./HLTV"; +import {DisplayRank} from "./Display"; -export const FormatDuration = (d) => { - const duration = Duration.fromObject({hours: 0, minutes: 0, seconds: d}).normalize().toObject() - - if (duration.hours > 1) - return `${duration.hours} h ${duration.minutes} min` - else if (duration.hours < 1) - return `${duration.minutes} min` -} - -export const FormatFullDuration = (d) => { - const duration = Duration.fromObject({hours: 0, minutes: 0, seconds: d}).normalize() - - if (duration.hours > 1) - return duration.toFormat('hh:mm:ss') - else if (duration.hours < 1) - return duration.toFormat('mm:ss') -} - -export const FormatDate = (date) => { - const matchDate = DateTime.fromISO(date) - const diff = DateTime.now().diff(matchDate) - - if (diff.as('days') > 10) - return matchDate.toLocaleString({weekday: 'short', day: '2-digit', month: '2-digit', year: 'numeric'}) - else if (diff.as('days') < 1) - if (diff.as('hours') < 1) - return Math.floor(diff.as('minutes')) + ' minutes ago' - else - return Math.floor(diff.as('hours')) + ' hours ago' - else - return Math.floor(diff.as('days')) + ' days ago' -} - -export const FormatFullDate = (date) => { - const matchDate = DateTime.fromISO(date) - - return matchDate.toLocaleString({ - weekday: 'short', - day: '2-digit', - month: '2-digit', - year: 'numeric', - hour: '2-digit', - minute: '2-digit', - second: '2-digit' - }) -} - -export const GoToMatch = (id) => { - router.push(`/match/${id}`) -} - -export const GoToPlayer = (id) => { - router.push(`/player/${id}`) -} - -export const GetHLTV_1 = (kills = 0, rounds, deaths = 0, k2 = 0, k3 = 0, k4 = 0, k5 = 0) => { - const k1 = kills - k2 - k3 - k4 - k5 - const Weight_KPR = 0.679 // weight kills per round - const Weight_SPR = 0.317 // weight survived rounds per round - const Weight_RMK = 1.277 // weight value calculated from rounds with multiple kills (1k + 4*2k + 9*3k + 16*4k + 25*5k) - - const KillRating = kills / rounds / Weight_KPR - const SurvivalRating = (rounds - deaths) / rounds / Weight_SPR - const RoundsWithMultipleKillsRating = (k1 + 4 * k2 + 9 * k3 + 16 * k4 + 25 * k5) / rounds / Weight_RMK - - return ((KillRating + 0.7 * SurvivalRating + RoundsWithMultipleKillsRating) / 2.7).toFixed(2) -} - -export const SaveLastVisitedToLocalStorage = (data) => { - let a = JSON.parse(localStorage.getItem('recent-visited')) || []; - - if (a.length === 0) { - a.push(data); - } else if (a.length === 9) { - if (a.find(p => p.steamid64 === data.steamid64)) { - a.shift() - a.splice(a.findIndex(i => i.steamid64 === data.steamid64), 1) - a.push(data) - } else if (!a.find(p => p.steamid64 === data.steamid64)) { - a.shift() - a.push(data) - } - } else if (a.length > 0 && a.length < 9) { - if (a.find(p => p.steamid64 === data.steamid64)) { - a.splice(a.findIndex(i => i.steamid64 === data.steamid64), 1) - a.push(data) - } else if (!a.find(p => p.steamid64 === data.steamid64)) { - a.push(data) - } - } - - localStorage.setItem('recent-visited', JSON.stringify(a)); +export { + FormatDate, FormatFullDuration, FormatFullDate, FormatDuration, + GoToMatch, GoToPlayer, + SaveLastVisitedToLocalStorage, + GetHLTV_1, + DisplayRank } \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index c9f2624..d96a703 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -57,9 +57,13 @@ export default { setup() { document.title = 'Home | csgoWTF' - const recentVisited = JSON.parse(localStorage.getItem('recent-visited')) - if (recentVisited !== null) - recentVisited.reverse() + let recentVisited = JSON.parse(localStorage.getItem('recent-visited')) + if (recentVisited !== null) { + recentVisited.reverse() + if (window.innerWidth < 768) { + recentVisited = recentVisited.filter(i => recentVisited.indexOf(i) < 6) + } + } return {recentVisited, GoToPlayer} } @@ -129,9 +133,6 @@ export default { @media screen and (max-width: 768px) { .recent-search { - max-height: 240px; - overflow: hidden; - .player-card { height: 60px; img { diff --git a/src/views/Match.vue b/src/views/Match.vue index aa7a1f3..122b338 100644 --- a/src/views/Match.vue +++ b/src/views/Match.vue @@ -1,7 +1,6 @@ @@ -37,7 +37,7 @@