boton de salir cierra la sala

This commit is contained in:
2025-08-16 17:31:46 -06:00
parent 627f2e0608
commit abe0d3d81f
2 changed files with 38 additions and 3 deletions

View File

@@ -329,9 +329,39 @@ function onP2Action(action: 'accept'|'reject'|'snatch') { colyseusService.p2Acti
function onReport(val: boolean) { colyseusService.report(val); } function onReport(val: boolean) { colyseusService.report(val); }
function onAssignShame(val: boolean) { colyseusService.assignShame(val); } function onAssignShame(val: boolean) { colyseusService.assignShame(val); }
function leaveGame() { async function leaveGame() {
console.log('[DemoGame] User manually leaving game'); // Ask for confirmation before closing the room for both players
colyseusService.leaveGame(); if (!confirm('¿Cerrar la sala para ambos jugadores? Esto terminará el juego inmediatamente.')) {
return;
}
console.log('[DemoGame] User closing room for both players');
try {
// Close the room for both players using the admin API
const response = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3000/api'}/rooms/${roomId.value}/close`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
if (!response.ok) {
console.error('Failed to close room via API');
// Fallback to normal leave if API fails
colyseusService.leaveGame();
} else {
console.log(`Room ${roomId.value} closed successfully for both players`);
// Just leave locally, the server will handle disconnecting both players
if (colyseusService.gameRoom.value) {
colyseusService.gameRoom.value.leave();
}
}
} catch (error) {
console.error('Error closing room:', error);
// Fallback to normal leave if error occurs
colyseusService.leaveGame();
}
// Navigate back to lobby
router.push(`/${routeUuid.value}`); router.push(`/${routeUuid.value}`);
} }
</script> </script>

View File

@@ -95,6 +95,11 @@ const previewPlayer = computed(() => ({
color: colorInput.value || playerColor.value color: colorInput.value || playerColor.value
})); }));
// Define missing reactive variables
const availableRooms = ref<any[]>([]);
const totalPlayers = ref(0);
const onlinePlayers = ref<any[]>([]);
onMounted(async () => { onMounted(async () => {
try { try {
const room = await colyseusService.joinLobby(); const room = await colyseusService.joinLobby();