Private
Public Access
1
0

Implement HTML-based lobby system with player list management, host controls, and real-time updates. Add JavaScript-WASM communication for lobby state changes and game start triggers.

This commit is contained in:
Sebastian Unterschütz
2026-01-04 01:56:31 +01:00
parent 3232ee7c2f
commit 41d15c60d3
7 changed files with 209 additions and 26 deletions

View File

@@ -80,11 +80,19 @@ func (g *Game) setupJavaScriptBridge() {
return nil
})
// startGameFromLobby_WASM() - Host startet Spiel aus HTML Lobby
startGameFromLobbyFunc := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
log.Println("🎮 Host startet Spiel aus HTML Lobby")
go g.sendStartRequest()
return nil
})
// Im globalen Scope registrieren
js.Global().Set("startGame", startGameFunc)
js.Global().Set("requestLeaderboard", requestLeaderboardFunc)
js.Global().Set("setMusicVolume", setMusicVolumeFunc)
js.Global().Set("setSFXVolume", setSFXVolumeFunc)
js.Global().Set("startGameFromLobby_WASM", startGameFromLobbyFunc)
log.Println("✅ JavaScript Bridge registriert")
}
@@ -117,3 +125,30 @@ func (g *Game) sendGameOverToJS(score int) {
log.Printf("💀 Game Over an JavaScript gesendet: Score=%d", score)
}
}
// Lobby Player List an JavaScript senden
func (g *Game) sendLobbyPlayersToJS() {
g.stateMutex.Lock()
players := make([]interface{}, 0, len(g.gameState.Players))
hostID := g.gameState.HostID
for id, p := range g.gameState.Players {
name := p.Name
if name == "" {
name = id
}
isHost := (id == hostID)
players = append(players, map[string]interface{}{
"name": name,
"is_host": isHost,
})
}
g.stateMutex.Unlock()
// JavaScript-Funktion aufrufen
if updateFunc := js.Global().Get("updateLobbyPlayers"); !updateFunc.IsUndefined() {
jsPlayers := js.ValueOf(players)
updateFunc.Invoke(jsPlayers)
log.Printf("👥 Lobby-Spieler an JavaScript gesendet: %d Spieler", len(players))
}
}