LeagueStats/client/src/mixins/liveGame.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-01-14 21:04:45 +00:00
import { gameModes } from '@/data/data.js'
import { sortTeamByRole } from '@/helpers/functions.js'
2020-01-14 21:04:45 +00:00
import { mapState } from 'vuex'
export const liveGame = {
data() {
return {
2023-09-20 20:01:43 +00:00
gameLength: 0,
2020-01-14 21:04:45 +00:00
}
},
computed: {
allyTeam() {
if (!this.current || !this.current.participants) {
return []
}
2023-09-20 20:01:43 +00:00
return this.current.participants
.filter((p) => p.teamId === this.teamColor)
.sort(this.sortTeamByRole)
},
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() {
if (!this.current || !this.current.participants) {
return []
}
2023-09-20 20:01:43 +00:00
return this.current.participants
.filter((p) => p.teamId !== this.teamColor)
.sort(this.sortTeamByRole)
2020-01-14 21:04:45 +00:00
},
gamemode() {
if (this.current.participants) {
2023-09-20 20:01:43 +00:00
return this.current.gameType === 'CUSTOM_GAME'
? { type: '', name: 'Custom Game' }
: gameModes[this.current.gameQueueConfigId]
} else {
return { type: '', name: '' }
}
2020-01-14 21:04:45 +00:00
},
gameStartTime() {
return this.current ? this.current.gameStartTime : 0
},
2020-01-14 21:04:45 +00:00
teamColor() {
2023-09-20 20:01:43 +00:00
return this.current.participants.find((p) => p.summonerId === this.account.id).teamId
2020-01-14 21:04:45 +00:00
},
...mapState({
2023-09-20 20:01:43 +00:00
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()
2023-09-20 20:01:43 +00:00
},
},
2020-01-14 21:04:45 +00:00
methods: {
updateGameLength() {
if (this.gameStartTime === 0) {
2023-09-20 20:01:43 +00:00
return (this.gameLength = 0)
}
this.gameLength = (new Date() - new Date(this.gameStartTime)) / 1000
},
2023-09-20 20:01:43 +00:00
sortTeamByRole,
},
2020-01-14 21:04:45 +00:00
}