Skip to content

Commit de852d1

Browse files
tom00502Parsons
andauthored
feat: gaas-connect (#70)
Co-authored-by: Parsons <gongyingparsons@gmail.com>
1 parent 5fded33 commit de852d1

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

src/components/FinalScoreBoard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const gameStore = useGameStore()
66
77
const players = computed(() =>
88
gameStore.gameStatus.players.map((player, i) => ({
9-
name: player.player_id,
9+
name: player.name,
1010
score: player.score,
1111
imgSrc: imgSrcs[i],
1212
})).sort((a, b) => b.score - a.score)

src/components/MainLayout.vue

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ import axios from 'axios'
2323
import {
2424
useRouter, useRoute
2525
} from 'vue-router'
26+
const route = useRoute()
27+
const apiWithToken = axios.create({
28+
baseURL: 'https://gaas-magician-backend.azurewebsites.net/',
29+
headers: {
30+
'Content-Type': 'application/json',
31+
Authorization: 'Bearer ' + route.query.token,
32+
},
33+
})
2634
const api = axios.create({
2735
baseURL: 'https://gaas-magician-backend.azurewebsites.net/',
2836
headers: {
2937
'Content-Type': 'application/json',
3038
},
3139
})
32-
const route = useRoute()
3340
const router = useRouter()
3441
const gameStore = useGameStore()
3542
const socket = ref(null)
@@ -39,6 +46,15 @@ const playerId = ref('Leave3310')
3946
const playerIds = [ 'Leave3310', 'Momo', 'Yock', 'Tux', 'Teds' ]
4047
const showHint1 = ref(false)
4148
const showHintStart = ref(false)
49+
50+
console.log(route, 'route')
51+
console.log('gameId: ', route.params.gameId)
52+
console.log('user token: ', route.query.token)
53+
apiWithToken.get('/me').then((res) => {
54+
console.log(res.data, 'me')
55+
playerId.value = res.data.player_id
56+
})
57+
4258
const gameOver = computed(() => gameStore.gameOver)
4359
const handleConnect = () => {
4460
socket.value = io(import.meta.env.VITE_SOCKET_IO_URL, {
@@ -109,8 +125,9 @@ const showWarehouse = computed(() => {
109125
return gameStore.hoverMagic === 4
110126
})
111127
const getGameStatus = async () => {
112-
const gameRoomID = route.query.gameRoomID
113-
const player_id = route.query.playerId || playerId.value
128+
// const gameRoomID = route.query.gameRoomID
129+
const gameRoomID = route.params.gameId
130+
const player_id = playerId.value
114131
const params = {
115132
gameRoomID,
116133
player_id,
@@ -159,9 +176,11 @@ watch(
159176
)
160177
onMounted(() => {
161178
if (route.query.gameRoomID && route.query.playerId) {
162-
playerId.value = route.query.playerId
163-
handleConnect()
179+
// playerId.value = route.query.playerId
180+
// handleConnect()
164181
}
182+
handleConnect()
183+
165184
console.log('mounted')
166185
console.log(import.meta.env.VITE_SOCKET_IO_URL)
167186
})

src/components/ScoreBoard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const gameStore = useGameStore()
66
77
const players = computed(() =>
88
gameStore.gameStatus.players.map((player, i) => ({
9-
name: player.player_id,
9+
name: player.name,
1010
score: player.score,
1111
imgSrc: imgSrcs[i],
1212
}))

src/components/TableWithPlayer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const playerClasses = [
1414
const players = computed(() => {
1515
const damageInfo = gameStore.gameStatus.damage_info || [ 0, 0, 0, 0, 0 ]
1616
return gameStore.gameStatus.players.map((player, i) => ({
17-
name: player.player_id,
17+
name: player.name,
1818
hp: player.HP,
1919
score: player.score,
2020
holdStones: player.spells.length,

src/router/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const router = createRouter({
1717
name: 'panel',
1818
component: apiPanel
1919
},
20+
{
21+
path: '/:gameId',
22+
name: 'room',
23+
component: Home
24+
},
2025
{
2126
path: '/:pathMatch(.*)*', redirect: { name: 'home' }
2227
}

0 commit comments

Comments
 (0)