Skip to content

Commit 4bb6689

Browse files
authored
Merge pull request #72 from Game-as-a-Service/feat/gaas-connect
fix: join game
2 parents a470b74 + 018aedb commit 4bb6689

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/components/MainLayout.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ const handleConnect = () => {
5858
socket.value.on('connect', () => {
5959
console.log('socket connected')
6060
joinGame()
61-
// handleJoinGame()
61+
getGameStatus().then(() => {
62+
console.log('getGameStatus')
63+
if (!gameStore.me?.joined){
64+
handleJoinGame()
65+
}
66+
})
6267
// 因為panel已經加入過玩家 這裡再加一次會失敗
6368
// 須考慮之後從大平台加入時要如何加入game
64-
getGameStatus()
6569
// socket.value.emit({ player_id: 'Leave3310' })
6670
})
6771
socket.value.on('game_update', (data) => {
@@ -132,13 +136,13 @@ const getGameStatus = async () => {
132136
})
133137
gameStore.setGameStatus(res.data)
134138
}
135-
// const handleJoinGame = async () => {
136-
// const gameRoomID = route.query.gameRoomID
137-
// const playerId = route.query.playerId || playerId.value
138-
// await api.put(`/player/${ playerId }/join`, {
139-
// gameRoomID,
140-
// })
141-
// }
139+
const handleJoinGame = async () => {
140+
const gameRoomID = route.params.gameId
141+
// const playerId = playerId.value
142+
await api.put(`/player/${ playerId.value }/join`, {
143+
gameRoomID,
144+
})
145+
}
142146
watch(
143147
() => gameStore.gameStatus.current_player,
144148
(newVal, oldVal) => {

src/stores/game.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ export const useGameStore = defineStore('useGameStore', () => {
208208
return true
209209
}
210210
})
211+
const me = computed(() => {
212+
return gameStatus.value.players.find((player) => player.player_id === playingId.value)
213+
})
211214
return {
212215
gameStatus,
213216
roundStart,
@@ -245,5 +248,6 @@ export const useGameStore = defineStore('useGameStore', () => {
245248
selectSecretEnded,
246249
spellFailed,
247250
setSpellFailed,
251+
me,
248252
}
249253
})

0 commit comments

Comments
 (0)