LeagueStats/client/src/mixins/liveGame.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-01-14 21:04:45 +00:00
import { gameModes } from '@/data/data.js'
import { mapState } from 'vuex'
export const liveGame = {
data() {
return {
gameLength: 0
}
},
computed: {
allyTeam() {
return this.current && this.current.participants ? this.current.participants.filter(p => p.teamId === this.teamColor) : []
},
displayStartTime() {
if (this.current.gameStartTime === 0) {
return 'Not started yet'
}
return this.$options.filters.secToTime(this.gameLength, true)
2020-01-14 21:04:45 +00:00
},
enemyTeam() {
return this.current && this.current.participants ? this.current.participants.filter(p => p.teamId !== this.teamColor) : []
2020-01-14 21:04:45 +00:00
},
gamemode() {
return gameModes[this.current.gameQueueConfigId]
},
gameStartTime() {
return this.current ? this.current.gameStartTime : 0
},
2020-01-14 21:04:45 +00:00
teamColor() {
return this.current.participants.find(p => p.summonerId === this.account.id).teamId
},
...mapState({
account: state => state.summoner.basic.account,
current: state => state.summoner.live.match,
2020-01-14 21:04:45 +00:00
})
},
created() {
this.updateGameLength()
2020-01-14 21:04:45 +00:00
setInterval(() => {
this.gameLength++
}, 1000)
},
watch: {
gameStartTime() {
this.updateGameLength()
}
},
2020-01-14 21:04:45 +00:00
methods: {
updateGameLength() {
if (this.gameStartTime === 0) {
return this.gameLength = 0
}
this.gameLength = (new Date() - new Date(this.gameStartTime)) / 1000
},
2020-01-14 21:04:45 +00:00
}
}