Skip to content

Commit 8e95c7f

Browse files
committed
🐞 fix: 修复房间创建会自动拉所有人进房间的问题
1 parent f09f686 commit 8e95c7f

File tree

9 files changed

+22
-10
lines changed

9 files changed

+22
-10
lines changed

game/frontend/src/components/common/RoomControls.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- Waiting: Player Actions -->
44
<template v-if="!isPlaying && roomPlayer.role === PlayerRole.player">
55
<button class="btn btn-circle md:btn-lg btn-soft tooltip tooltip-left"
6-
@click="game?.leaveRoom(roomPlayer.room.id)"
6+
@click="game?.leaveRoom(roomPlayer.room.id), $router.push('/')"
77
:disabled="roomPlayer.isReady"
88
data-tip="离开房间"
99
>

game/frontend/src/components/gobang/GobangLite.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<section class="flex flex-col items-center justify-center p-2 py-4" ref="containerRef">
33
<!-- 棋盘 -->
4-
<div class="inline-block p-2 m-auto border rounded shadow-2xl bg-base-300 border-base-content/20">
4+
<div class="inline-block p-2 m-auto border rounded shadow-2xl bg-base-300 border-base-content/20 select-none">
55
<!-- 顶部留白 -->
66
<div class="flex">
77
<div class="w-[4vw] md:w-6 h-[4vw] md:h-6"></div>

game/frontend/src/components/gobang/GobangRoom.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<section class="flex flex-col md:flex-row gap-4 md:h-full">
3-
<section class="flex-1 md:h-full flex flex-col items-center justify-start md:justify-center overflow-auto p-4">
3+
<section class="flex-1 md:h-full flex flex-col items-center justify-start md:justify-center overflow-auto p-4 select-none">
44
<!-- 棋盘 -->
55
<div class="inline-block bg-base-300 border border-base-content/20 p-2 rounded shadow-2xl m-auto">
66
<!-- 顶部留白 -->

game/frontend/src/components/othello/OthelloLite.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
>
66
<!-- 棋盘 -->
77
<div
8-
class="inline-block bg-base-300 border border-base-content/20 p-1 rounded shadow-2xl m-auto max-w-[99vw] max-h-[90vh]"
8+
class="inline-block bg-base-300 border border-base-content/20 p-1 rounded shadow-2xl m-auto max-w-[99vw] max-h-[90vh] select-none"
99
>
1010
<!-- 顶部横坐标 (A-H) -->
1111
<div class="flex">

game/frontend/src/components/othello/OthelloRoom.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<section class="flex flex-col md:flex-row gap-4 md:h-full">
3-
<section class="flex-1 md:h-full flex flex-col items-center justify-start md:justify-center overflow-auto p-4">
3+
<section class="flex-1 md:h-full flex flex-col items-center justify-start md:justify-center overflow-auto p-4 select-none">
44
<!-- 棋盘 -->
55
<div class="inline-block bg-base-300 border border-base-content/20 p-2 rounded shadow-2xl m-auto">
66
<!-- 顶部横坐标 (A-H) -->

game/frontend/src/stores/game.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export const useGameStore = defineStore('game', () => {
100100
rooms.value = [...data]
101101
})
102102
.onRoomCreate((room) => {
103-
router.replace('/r/' + room.id)
103+
if (room.players.find(p => p.id === player.value?.id))
104+
router.replace('/r/' + room.id)
104105
})
105106
.onPlayerReady(onPlayerReady)
106107
.onPlayerUnready(onPlayerReady)

game/frontend/src/views/Room.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import msg from "@/components/msg";
33
import { getComponent } from "@/main";
44
import { useGameStore } from "@/stores/game";
55
import { openSmallWindow } from "@/utils/dom";
6-
import { computed, onMounted } from "vue";
6+
import { computed, onMounted, watch } from "vue";
77
import { useRoute, useRouter } from "vue-router";
88
99
const gameStore = useGameStore();
@@ -42,10 +42,21 @@ function init() {
4242
}
4343
const room = computed(() => gameStore.roomPlayer?.room)
4444
45-
onMounted(() => {
45+
function load() {
4646
gameStore.game?.getRoomOneTime(roomId.value).then(() => {
4747
init();
4848
});
49+
}
50+
51+
watch(
52+
() => route.params.id,
53+
() => {
54+
load();
55+
}
56+
);
57+
58+
onMounted(() => {
59+
load();
4960
});
5061
5162
const hasLiteComponent = computed(() => {

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class Tiaoom extends EventEmitter {
206206

207207
this.rooms.push(room);
208208
this.emit("room", room);
209-
this.joinPlayer(sender, { roomId: room.id, ...sender }, true);
209+
await this.joinPlayer(sender, { roomId: room.id, ...sender }, true);
210210
return room;
211211
}
212212

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tiaoom",
3-
"version": "0.0.37",
3+
"version": "0.0.38",
44
"description": "",
55
"main": "./src/index.cjs",
66
"module": "./src/index.mjs",

0 commit comments

Comments
 (0)