first commit
This commit is contained in:
49
client/src/App.vue
Normal file
49
client/src/App.vue
Normal file
@@ -0,0 +1,49 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<Home
|
||||
v-if="currentScreen === 'home'"
|
||||
@join-game="onJoinGame"
|
||||
@show-settings="showSettings = true"
|
||||
/>
|
||||
<Game v-else-if="currentScreen === 'game'" :game-client="gameClient" />
|
||||
|
||||
<!-- Settings Modal -->
|
||||
<Settings v-if="showSettings" @close="showSettings = false" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import Home from '@/components/Home.vue'
|
||||
import Game from '@/components/Game.vue'
|
||||
import Settings from '@/components/Settings.vue'
|
||||
import { GameClient } from '@/services/gameClient'
|
||||
import { logger } from '@/services/logger'
|
||||
|
||||
const currentScreen = ref<'home' | 'game'>('home')
|
||||
const gameClient = ref<GameClient | null>(null)
|
||||
const showSettings = ref(false)
|
||||
|
||||
const onJoinGame = (client: any) => {
|
||||
gameClient.value = client
|
||||
currentScreen.value = 'game'
|
||||
logger.info('Transitioning to game screen')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
#app {
|
||||
min-height: 100vh;
|
||||
}
|
||||
</style>
|
||||
300
client/src/components/Game.vue
Normal file
300
client/src/components/Game.vue
Normal file
@@ -0,0 +1,300 @@
|
||||
<template>
|
||||
<div class="game-container">
|
||||
<!-- Waiting Phase -->
|
||||
<div v-if="gamePhase === 'waiting'" class="waiting-screen">
|
||||
<div class="waiting-content">
|
||||
<h2>Esperando jugadores...</h2>
|
||||
<div class="player-count">
|
||||
{{ playerCount }}/{{ minPlayers }} jugadores conectados
|
||||
</div>
|
||||
<div class="spinner"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Playing Phase -->
|
||||
<div v-else-if="gamePhase === 'playing'" class="game-screen">
|
||||
<!-- Scoreboard -->
|
||||
<div class="scoreboard">
|
||||
<div
|
||||
v-for="player in players"
|
||||
:key="player.id"
|
||||
class="player-score"
|
||||
:class="{ 'current-player': player.id === currentPlayerId }"
|
||||
>
|
||||
<span class="player-name">{{ player.name }}</span>
|
||||
<span class="score">{{ player.score }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Click Button -->
|
||||
<div class="click-area">
|
||||
<button
|
||||
@click="handleClick"
|
||||
class="click-button"
|
||||
:class="{ 'clicked': isClicked }"
|
||||
>
|
||||
<span class="click-text">¡CLICK!</span>
|
||||
<div class="click-effect" v-if="showEffect"></div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Current Player Info -->
|
||||
<div class="player-info">
|
||||
<p>Tu puntaje: <strong>{{ currentPlayerScore }}</strong></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted, triggerRef } from 'vue'
|
||||
import { GameClient } from '@/services/gameClient'
|
||||
import { GameState, Player } from '@/types'
|
||||
import type { Room } from 'colyseus.js'
|
||||
import { logger } from '@/services/logger'
|
||||
|
||||
const props = defineProps<{
|
||||
gameClient: any
|
||||
}>()
|
||||
|
||||
const gameState = ref<GameState | null>(null)
|
||||
const isClicked = ref(false)
|
||||
const showEffect = ref(false)
|
||||
|
||||
// Computed properties
|
||||
const gamePhase = computed(() => {
|
||||
const phase = gameState.value?.gamePhase || 'waiting'
|
||||
logger.computedProperty('gamePhase', phase)
|
||||
return phase
|
||||
})
|
||||
const minPlayers = computed(() => gameState.value?.minPlayers || 2)
|
||||
const playerCount = computed(() => {
|
||||
const count = gameState.value?.players.size || 0
|
||||
logger.computedProperty('playerCount', count)
|
||||
return count
|
||||
})
|
||||
const players = computed(() => {
|
||||
if (!gameState.value) return []
|
||||
const playerList = Array.from(gameState.value.players.values())
|
||||
logger.computedProperty('players', playerList)
|
||||
return playerList
|
||||
})
|
||||
const currentPlayerId = computed(() => props.gameClient?.currentPlayerId || '')
|
||||
const currentPlayerScore = computed(() => {
|
||||
if (!gameState.value || !currentPlayerId.value) return 0
|
||||
const player = gameState.value.players.get(currentPlayerId.value)
|
||||
return player?.score || 0
|
||||
})
|
||||
|
||||
const handleClick = () => {
|
||||
if (!props.gameClient || gamePhase.value !== 'playing') return
|
||||
|
||||
// Send click through gameClient
|
||||
props.gameClient.sendClick()
|
||||
|
||||
// Visual feedback
|
||||
isClicked.value = true
|
||||
showEffect.value = true
|
||||
|
||||
setTimeout(() => {
|
||||
isClicked.value = false
|
||||
}, 150)
|
||||
|
||||
setTimeout(() => {
|
||||
showEffect.value = false
|
||||
}, 400)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (!props.gameClient) return
|
||||
|
||||
logger.gameMounted()
|
||||
|
||||
// Subscribe to state changes
|
||||
const unsubscribeStateChange = props.gameClient.onStateChange((state: GameState) => {
|
||||
logger.gameComponentUpdate({
|
||||
gamePhase: state.gamePhase,
|
||||
playerCount: state.players.size,
|
||||
gameStarted: state.gameStarted
|
||||
})
|
||||
|
||||
// Force Vue reactivity by assigning new reference and triggering update
|
||||
gameState.value = state
|
||||
triggerRef(gameState)
|
||||
|
||||
logger.info('Reactive gameState updated and triggered:', gameState.value)
|
||||
})
|
||||
|
||||
// Subscribe to phase changes for debugging
|
||||
const unsubscribePhaseChange = props.gameClient.onGamePhaseChange((phase: string) => {
|
||||
logger.info('Game component detected phase change:', phase)
|
||||
})
|
||||
|
||||
// Cleanup on unmount
|
||||
onUnmounted(() => {
|
||||
logger.gameUnmounted()
|
||||
unsubscribeStateChange()
|
||||
unsubscribePhaseChange()
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.game-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
/* Waiting Screen */
|
||||
.waiting-screen {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.waiting-content h2 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.player-count {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 2rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border: 4px solid rgba(255, 255, 255, 0.3);
|
||||
border-top: 4px solid white;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* Game Screen */
|
||||
.game-screen {
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.scoreboard {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 2rem;
|
||||
margin-bottom: 3rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.player-score {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
padding: 1rem 1.5rem;
|
||||
border-radius: 12px;
|
||||
text-align: center;
|
||||
backdrop-filter: blur(10px);
|
||||
border: 2px solid transparent;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.player-score.current-player {
|
||||
border-color: #ffd700;
|
||||
background: rgba(255, 215, 0, 0.2);
|
||||
}
|
||||
|
||||
.player-name {
|
||||
display: block;
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.score {
|
||||
display: block;
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* Click Button */
|
||||
.click-area {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.click-button {
|
||||
position: relative;
|
||||
width: 250px;
|
||||
height: 250px;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background: linear-gradient(45deg, #ff6b6b, #ff8e53);
|
||||
color: white;
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
transition: all 0.1s ease;
|
||||
box-shadow: 0 8px 25px rgba(255, 107, 107, 0.4);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.click-button:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 12px 35px rgba(255, 107, 107, 0.6);
|
||||
}
|
||||
|
||||
.click-button.clicked {
|
||||
transform: scale(0.95);
|
||||
background: linear-gradient(45deg, #ff8e53, #ff6b6b);
|
||||
}
|
||||
|
||||
.click-text {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.click-effect {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
animation: clickRipple 0.4s ease-out;
|
||||
}
|
||||
|
||||
@keyframes clickRipple {
|
||||
0% {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
100% {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.player-info {
|
||||
text-align: center;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.player-info strong {
|
||||
color: #ffd700;
|
||||
}
|
||||
</style>
|
||||
150
client/src/components/Home.vue
Normal file
150
client/src/components/Home.vue
Normal file
@@ -0,0 +1,150 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<div class="branding">
|
||||
<img src="/assets/logo.svg" alt="Snatch Game Logo" class="logo" />
|
||||
<h1>Snatch Game</h1>
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button @click="onJoin" :disabled="isConnecting">
|
||||
{{ isConnecting ? 'Conectando...' : 'Unirse a partida' }}
|
||||
</button>
|
||||
<button @click="onSettings">Configuración</button>
|
||||
<button @click="onLogin">Iniciar sesión</button>
|
||||
</div>
|
||||
|
||||
<div v-if="connectionStatus" class="connection-status">
|
||||
{{ connectionStatus }}
|
||||
</div>
|
||||
|
||||
<div class="footer">NucleoServices</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { GameClient } from '@/services/gameClient'
|
||||
import { logger } from '@/services/logger'
|
||||
|
||||
const emit = defineEmits<{
|
||||
'join-game': [client: any]
|
||||
'show-settings': []
|
||||
}>()
|
||||
|
||||
const gameClient = ref<GameClient | null>(null)
|
||||
const isConnecting = ref(false)
|
||||
const connectionStatus = ref('')
|
||||
|
||||
onMounted(() => {
|
||||
gameClient.value = new GameClient()
|
||||
logger.info('GameClient initialized:', gameClient.value);
|
||||
})
|
||||
|
||||
const onJoin = async () => {
|
||||
if (isConnecting.value || !gameClient.value) return
|
||||
|
||||
isConnecting.value = true
|
||||
connectionStatus.value = 'Conectando...'
|
||||
|
||||
try {
|
||||
await gameClient.value.joinGame('Jugador Test', 'classic')
|
||||
connectionStatus.value = 'Conectado exitosamente!'
|
||||
logger.info('Conectado al servidor')
|
||||
|
||||
// Emit the join-game event to transition to game screen
|
||||
emit('join-game', gameClient.value)
|
||||
} catch (error) {
|
||||
connectionStatus.value = 'Error de conexión: ' + (error as Error).message
|
||||
logger.error('Error connecting:', error)
|
||||
} finally {
|
||||
isConnecting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const onSettings = () => {
|
||||
emit('show-settings')
|
||||
}
|
||||
|
||||
const onLogin = () => {
|
||||
logger.info('Iniciar sesión clicked')
|
||||
// TODO: lógica para iniciar sesión
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.branding {
|
||||
text-align: center;
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 1rem 2rem;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
color: #333;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
button:hover:not(:disabled) {
|
||||
background: white;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.connection-status {
|
||||
margin-top: 1rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 2rem;
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
246
client/src/components/Settings.vue
Normal file
246
client/src/components/Settings.vue
Normal file
@@ -0,0 +1,246 @@
|
||||
<template>
|
||||
<div class="settings-container">
|
||||
<div class="settings-header">
|
||||
<h2>Configuración</h2>
|
||||
<button @click="$emit('close')" class="close-button">
|
||||
<span>✕</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<div class="setting-section">
|
||||
<h3>Desarrollo</h3>
|
||||
|
||||
<div class="setting-item">
|
||||
<label class="checkbox-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="debugLoggingEnabled"
|
||||
@change="toggleDebugLogging"
|
||||
/>
|
||||
<span class="checkmark"></span>
|
||||
<span class="label-text">Activar logs de depuración</span>
|
||||
</label>
|
||||
<p class="setting-description">
|
||||
Muestra información detallada en la consola del navegador.
|
||||
Útil para depuración pero puede afectar el rendimiento.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-section">
|
||||
<h3>Información</h3>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Versión:</span>
|
||||
<span class="info-value">0.0.1-alpha</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Entorno:</span>
|
||||
<span class="info-value">{{ environment }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-footer">
|
||||
<button @click="$emit('close')" class="button-primary">
|
||||
Cerrar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { logger } from '@/services/logger'
|
||||
|
||||
defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
|
||||
const debugLoggingEnabled = ref(false)
|
||||
const environment = import.meta.env.MODE
|
||||
|
||||
onMounted(() => {
|
||||
debugLoggingEnabled.value = logger.isDebugEnabled()
|
||||
})
|
||||
|
||||
const toggleDebugLogging = (event: Event) => {
|
||||
const target = event.target as HTMLInputElement
|
||||
debugLoggingEnabled.value = target.checked
|
||||
logger.setDebugEnabled(target.checked)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.settings-container {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
z-index: 1000;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1.5rem;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.settings-header h2 {
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.close-button {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
background: #f5f5f5;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.close-button:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
padding: 1.5rem;
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.setting-section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.setting-section h3 {
|
||||
margin: 0 0 1rem 0;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
cursor: pointer;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.checkbox-label input[type="checkbox"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.checkmark {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 4px;
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
margin-top: 1px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.checkbox-label input[type="checkbox"]:checked + .checkmark {
|
||||
background: #667eea;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 6px;
|
||||
top: 2px;
|
||||
width: 6px;
|
||||
height: 10px;
|
||||
border: solid white;
|
||||
border-width: 0 2px 2px 0;
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
.label-text {
|
||||
font-weight: 500;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
margin: 0.5rem 0 0 2.75rem;
|
||||
font-size: 0.9rem;
|
||||
color: #666;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0.5rem 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.info-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-weight: 500;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #333;
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.settings-footer {
|
||||
padding: 1.5rem;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.button-primary {
|
||||
padding: 0.75rem 1.5rem;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.button-primary:hover {
|
||||
background: #5a6fd8;
|
||||
}
|
||||
|
||||
/* Overlay */
|
||||
.settings-container::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: -1;
|
||||
}
|
||||
</style>
|
||||
4
client/src/main.ts
Normal file
4
client/src/main.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
145
client/src/services/gameClient.ts
Normal file
145
client/src/services/gameClient.ts
Normal file
@@ -0,0 +1,145 @@
|
||||
import { Client, Room } from 'colyseus.js'
|
||||
import { GameState, Player } from '../types'
|
||||
import type { GameRoomOptions } from '../types'
|
||||
import { logger } from './logger'
|
||||
|
||||
export class GameClient {
|
||||
public client: Client
|
||||
public room: Room<GameState> | null = null
|
||||
|
||||
// Current state
|
||||
public gameState: GameState | null = null
|
||||
public currentPlayerId: string = ''
|
||||
public isConnected: boolean = false
|
||||
|
||||
// Event callbacks
|
||||
private onStateChangeCallbacks: ((state: GameState) => void)[] = []
|
||||
private onGamePhaseChangeCallbacks: ((phase: string) => void)[] = []
|
||||
|
||||
constructor() {
|
||||
const serverUrl = import.meta.env.VITE_SERVER_URL || 'ws://localhost:2567'
|
||||
this.client = new Client(serverUrl)
|
||||
logger.info('Game client initialized with server:', serverUrl)
|
||||
}
|
||||
|
||||
async joinGame(playerName: string, gameMode: string = 'classic'): Promise<Room<GameState>> {
|
||||
try {
|
||||
logger.info('Attempting to join game room...')
|
||||
|
||||
const options: GameRoomOptions = {
|
||||
playerName,
|
||||
gameMode
|
||||
}
|
||||
|
||||
this.room = await this.client.joinOrCreate<GameState>('game', options)
|
||||
this.currentPlayerId = this.room.sessionId
|
||||
this.isConnected = true
|
||||
|
||||
logger.info('Successfully joined room:', this.room)
|
||||
logger.info('Player ID:', this.currentPlayerId)
|
||||
|
||||
this.room.onStateChange((state) => {
|
||||
logger.gameStateChange({
|
||||
gamePhase: state.gamePhase,
|
||||
playerCount: state.players.size,
|
||||
gameStarted: state.gameStarted
|
||||
})
|
||||
|
||||
const previousPhase = this.gameState?.gamePhase
|
||||
this.gameState = state
|
||||
|
||||
// Notify all state change callbacks
|
||||
this.onStateChangeCallbacks.forEach(callback => callback(state))
|
||||
|
||||
// Notify phase change if it changed
|
||||
if (previousPhase !== state.gamePhase) {
|
||||
logger.gamePhaseChange(previousPhase, state.gamePhase)
|
||||
this.onGamePhaseChangeCallbacks.forEach(callback => callback(state.gamePhase))
|
||||
}
|
||||
})
|
||||
|
||||
this.room.onLeave((code) => {
|
||||
logger.info('Left room with code:', code)
|
||||
this.isConnected = false
|
||||
})
|
||||
|
||||
this.room.onError((code, message) => {
|
||||
logger.error('Room error:', { code, message })
|
||||
})
|
||||
|
||||
return this.room
|
||||
} catch (error) {
|
||||
logger.error('Failed to join room:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
leaveGame(): void {
|
||||
if (this.room) {
|
||||
this.room.leave()
|
||||
this.room = null
|
||||
this.isConnected = false
|
||||
this.gameState = null
|
||||
}
|
||||
}
|
||||
|
||||
getRoom(): Room<GameState> | null {
|
||||
return this.room
|
||||
}
|
||||
|
||||
// Event subscription methods
|
||||
onStateChange(callback: (state: GameState) => void): () => void {
|
||||
this.onStateChangeCallbacks.push(callback)
|
||||
|
||||
// If we already have state, call immediately
|
||||
if (this.gameState) {
|
||||
callback(this.gameState)
|
||||
}
|
||||
|
||||
// Return unsubscribe function
|
||||
return () => {
|
||||
const index = this.onStateChangeCallbacks.indexOf(callback)
|
||||
if (index > -1) {
|
||||
this.onStateChangeCallbacks.splice(index, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onGamePhaseChange(callback: (phase: string) => void): () => void {
|
||||
this.onGamePhaseChangeCallbacks.push(callback)
|
||||
|
||||
// If we already have state, call immediately
|
||||
if (this.gameState) {
|
||||
callback(this.gameState.gamePhase)
|
||||
}
|
||||
|
||||
// Return unsubscribe function
|
||||
return () => {
|
||||
const index = this.onGamePhaseChangeCallbacks.indexOf(callback)
|
||||
if (index > -1) {
|
||||
this.onGamePhaseChangeCallbacks.splice(index, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Game actions
|
||||
sendClick(): void {
|
||||
if (this.room && this.gameState?.gamePhase === 'playing') {
|
||||
this.room.send('click')
|
||||
logger.clickSent()
|
||||
} else {
|
||||
logger.clickIgnored()
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
getCurrentPlayer(): Player | null {
|
||||
if (!this.gameState || !this.currentPlayerId) return null
|
||||
return this.gameState.players.get(this.currentPlayerId) || null
|
||||
}
|
||||
|
||||
getPlayers(): Player[] {
|
||||
if (!this.gameState) return []
|
||||
return Array.from(this.gameState.players.values())
|
||||
}
|
||||
}
|
||||
116
client/src/services/logger.ts
Normal file
116
client/src/services/logger.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
class Logger {
|
||||
private static instance: Logger
|
||||
private debugEnabled: boolean
|
||||
|
||||
private constructor() {
|
||||
// Default based on environment
|
||||
const isDevelopment = import.meta.env.MODE === 'development'
|
||||
this.debugEnabled = isDevelopment
|
||||
|
||||
// Load from localStorage if available
|
||||
const savedSetting = localStorage.getItem('debug-logging-enabled')
|
||||
if (savedSetting !== null) {
|
||||
this.debugEnabled = savedSetting === 'true'
|
||||
}
|
||||
|
||||
console.log(`🐛 Debug logging ${this.debugEnabled ? 'enabled' : 'disabled'} (environment: ${import.meta.env.MODE})`)
|
||||
}
|
||||
|
||||
static getInstance(): Logger {
|
||||
if (!Logger.instance) {
|
||||
Logger.instance = new Logger()
|
||||
}
|
||||
return Logger.instance
|
||||
}
|
||||
|
||||
setDebugEnabled(enabled: boolean): void {
|
||||
this.debugEnabled = enabled
|
||||
localStorage.setItem('debug-logging-enabled', enabled.toString())
|
||||
console.log(`🐛 Debug logging ${enabled ? 'enabled' : 'disabled'}`)
|
||||
}
|
||||
|
||||
isDebugEnabled(): boolean {
|
||||
return this.debugEnabled
|
||||
}
|
||||
|
||||
// Game-specific logging methods
|
||||
gameStateChange(data: any): void {
|
||||
if (this.debugEnabled) {
|
||||
console.log('🔄 State changed:', data)
|
||||
}
|
||||
}
|
||||
|
||||
gameComponentUpdate(data: any): void {
|
||||
if (this.debugEnabled) {
|
||||
console.log('🔄 Game component received state update:', data)
|
||||
}
|
||||
}
|
||||
|
||||
gamePhaseChange(oldPhase: string | undefined, newPhase: string): void {
|
||||
if (this.debugEnabled) {
|
||||
console.log(`🎮 Game phase changed: ${oldPhase} → ${newPhase}`)
|
||||
}
|
||||
}
|
||||
|
||||
gameMounted(): void {
|
||||
if (this.debugEnabled) {
|
||||
console.log('🎮 Game component mounted, setting up state subscription')
|
||||
}
|
||||
}
|
||||
|
||||
gameUnmounted(): void {
|
||||
if (this.debugEnabled) {
|
||||
console.log('🎮 Game component unmounting, cleaning up subscriptions')
|
||||
}
|
||||
}
|
||||
|
||||
computedProperty(name: string, value: any): void {
|
||||
if (this.debugEnabled) {
|
||||
console.log(`🔢 ${name} computed:`, value)
|
||||
}
|
||||
}
|
||||
|
||||
clickSent(): void {
|
||||
if (this.debugEnabled) {
|
||||
console.log('🖱️ Click sent to server')
|
||||
}
|
||||
}
|
||||
|
||||
clickIgnored(): void {
|
||||
if (this.debugEnabled) {
|
||||
console.log('⚠️ Click ignored - game not in playing phase or not connected')
|
||||
}
|
||||
}
|
||||
|
||||
// General logging methods
|
||||
info(message: string, data?: any): void {
|
||||
if (this.debugEnabled) {
|
||||
if (data) {
|
||||
console.log(message, data)
|
||||
} else {
|
||||
console.log(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
warn(message: string, data?: any): void {
|
||||
if (this.debugEnabled) {
|
||||
if (data) {
|
||||
console.warn(message, data)
|
||||
} else {
|
||||
console.warn(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error(message: string, data?: any): void {
|
||||
// Errors are always logged regardless of debug setting
|
||||
if (data) {
|
||||
console.error(message, data)
|
||||
} else {
|
||||
console.error(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const logger = Logger.getInstance()
|
||||
9
client/src/types/index.ts
Normal file
9
client/src/types/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
// Re-export generated schema classes
|
||||
export { Player } from './Player'
|
||||
export { GameState } from './GameState'
|
||||
|
||||
// Additional types that are not Schema classes
|
||||
export interface GameRoomOptions {
|
||||
gameMode?: string;
|
||||
playerName?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user