usuarios pre configurados
This commit is contained in:
@@ -83,12 +83,13 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted, computed, watch } from 'vue';
|
||||
import PlayerStats from './games/PlayerStats.vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { colyseusService } from '../services/colyseus';
|
||||
import { getStateCallbacks } from 'colyseus.js';
|
||||
import { localDB } from '../services/db';
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const routeUuid = computed(() => (route.params as any)?.uuid as string || '');
|
||||
const inputName = ref('');
|
||||
const isJoining = ref(false);
|
||||
const colorInput = ref('#667eea');
|
||||
@@ -111,25 +112,9 @@ const previewPlayer = computed(() => ({
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
// Try reconnect to an ongoing game first
|
||||
const reconnected = await colyseusService.tryReconnectToOngoingGame();
|
||||
if (reconnected) {
|
||||
router.push('/demo');
|
||||
return;
|
||||
}
|
||||
const room = await colyseusService.joinLobby();
|
||||
colorInput.value = colyseusService.playerColor.value || '#667eea';
|
||||
|
||||
// Initialize local DB and prefill inputs if available
|
||||
try {
|
||||
await localDB.init();
|
||||
const profile = localDB.getLocalPlayer();
|
||||
if (profile?.name) inputName.value = profile.name;
|
||||
if (profile?.color) colorInput.value = profile.color;
|
||||
} catch (e) {
|
||||
console.warn('Local DB not available', e);
|
||||
}
|
||||
|
||||
// Keep color input synced with server-updated color
|
||||
watch(() => colyseusService.playerColor.value, (c) => {
|
||||
if (c && c !== colorInput.value) colorInput.value = c;
|
||||
@@ -190,7 +175,6 @@ onUnmounted(() => {
|
||||
async function updateName() {
|
||||
// Send even if empty; server will assign a default unique name when empty
|
||||
const name = inputName.value.trim();
|
||||
try { localDB.setName(name); } catch {}
|
||||
await colyseusService.setPlayerName(name);
|
||||
}
|
||||
|
||||
@@ -205,7 +189,7 @@ async function handleQuickPlay() {
|
||||
console.log('Starting quickPlay...');
|
||||
try {
|
||||
const gameRoom = await colyseusService.quickPlay();
|
||||
console.log('Game room joined:', gameRoom?.id, 'Full room object:', gameRoom);
|
||||
console.log('Game room joined. Full room object:', gameRoom);
|
||||
|
||||
// Leave the lobby room before navigating
|
||||
if (colyseusService.lobbyRoom.value) {
|
||||
@@ -214,8 +198,8 @@ async function handleQuickPlay() {
|
||||
colyseusService.lobbyRoom.value = null;
|
||||
}
|
||||
|
||||
console.log('Navigating to /demo...');
|
||||
await router.push('/demo');
|
||||
console.log('Navigating to /:uuid/demo...');
|
||||
await router.push(`/${routeUuid.value}/demo`);
|
||||
console.log('Navigation complete');
|
||||
} catch (error) {
|
||||
console.error('Failed to join game:', error);
|
||||
@@ -234,7 +218,7 @@ async function joinRoom(roomId: string) {
|
||||
colyseusService.lobbyRoom.value.leave();
|
||||
colyseusService.lobbyRoom.value = null;
|
||||
}
|
||||
router.push('/demo');
|
||||
router.push(`/${routeUuid.value}/demo`);
|
||||
} catch (error) {
|
||||
console.error('Failed to join room:', error);
|
||||
isJoining.value = false;
|
||||
|
||||
Reference in New Issue
Block a user