Private
Public Access
1
0

fix game
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 8m13s

This commit is contained in:
Sebastian Unterschütz
2026-03-21 22:18:48 +01:00
parent f81ec70f96
commit ce092c8366
3 changed files with 34 additions and 5 deletions

View File

@@ -57,10 +57,12 @@ type InputState struct {
type Game struct {
appState int
conn *nats.EncodedConn
wsConn *wsConn // WebSocket für WASM
gameState game.GameState
stateMutex sync.Mutex
connected bool
wsConn *wsConn // WebSocket für WASM
connGeneration int // Erhöht bei jedem Disconnect; macht alte WS-Handler ungültig
isConnecting bool // Guard gegen mehrfaches connectAndStart()
gameState game.GameState
stateMutex sync.Mutex
connected bool
world *game.World
assetsImages map[string]*ebiten.Image
@@ -904,6 +906,14 @@ func (g *Game) resetForNewGame() {
}
func (g *Game) connectAndStart() {
// Guard: verhindert mehrfaches gleichzeitiges Verbinden
if g.isConnecting {
log.Println("⚠️ connectAndStart bereits aktiv, ignoriere doppelten Aufruf")
return
}
g.isConnecting = true
defer func() { g.isConnecting = false }()
g.resetForNewGame()
// Verbindung über plattformspezifische Implementierung