2020-01-14 21:04:45 +00:00
|
|
|
import { gameModes } from '@/data/data.js'
|
2020-06-12 15:45:16 +00:00
|
|
|
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() {
|
2020-06-12 15:45:16 +00:00
|
|
|
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-19 15:18:35 +00:00
|
|
|
},
|
|
|
|
|
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() {
|
2020-06-12 15:45:16 +00:00
|
|
|
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() {
|
2020-02-29 14:11:23 +00:00
|
|
|
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]
|
2020-02-29 14:11:23 +00:00
|
|
|
} else {
|
|
|
|
|
return { type: '', name: '' }
|
|
|
|
|
}
|
2020-01-14 21:04:45 +00:00
|
|
|
},
|
2020-01-15 20:55:22 +00:00
|
|
|
gameStartTime() {
|
2020-01-19 16:03:40 +00:00
|
|
|
return this.current ? this.current.gameStartTime : 0
|
2020-01-15 20:55:22 +00:00
|
|
|
},
|
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() {
|
2020-01-19 15:48:28 +00:00
|
|
|
this.updateGameLength()
|
2020-01-14 21:04:45 +00:00
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
this.gameLength++
|
|
|
|
|
}, 1000)
|
|
|
|
|
},
|
|
|
|
|
|
2020-01-19 15:48:28 +00:00
|
|
|
watch: {
|
|
|
|
|
gameStartTime() {
|
|
|
|
|
this.updateGameLength()
|
2023-09-20 20:01:43 +00:00
|
|
|
},
|
2020-01-19 15:48:28 +00:00
|
|
|
},
|
|
|
|
|
|
2020-01-14 21:04:45 +00:00
|
|
|
methods: {
|
2020-01-19 15:48:28 +00:00
|
|
|
updateGameLength() {
|
|
|
|
|
if (this.gameStartTime === 0) {
|
2023-09-20 20:01:43 +00:00
|
|
|
return (this.gameLength = 0)
|
2020-01-19 15:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|