Add WebAssembly support for assets and chunks, implement gameover screen rendering, and enhance server gameplay logic with dynamic speeds, team naming, and score components.
This commit is contained in:
@@ -28,11 +28,11 @@ func (g *Game) setupJavaScriptBridge() {
|
||||
g.savePlayerName(playerName)
|
||||
|
||||
if mode == "solo" {
|
||||
// Solo Mode - direkt ins Spiel
|
||||
// Solo Mode - Auto-Start wartet auf Server
|
||||
g.roomID = fmt.Sprintf("solo_%d", time.Now().UnixNano())
|
||||
g.isHost = true
|
||||
g.appState = StateGame
|
||||
log.Printf("🎮 Solo-Spiel gestartet: %s", playerName)
|
||||
g.appState = StateLobby // Warte auf Server Auto-Start
|
||||
log.Printf("🎮 Solo-Spiel gestartet: %s (warte auf Server)", playerName)
|
||||
} else if mode == "coop" && len(args) >= 5 {
|
||||
// Co-op Mode - in die Lobby
|
||||
roomID := args[2].String()
|
||||
@@ -87,12 +87,24 @@ func (g *Game) setupJavaScriptBridge() {
|
||||
return nil
|
||||
})
|
||||
|
||||
// setTeamName_WASM(teamName) - Host setzt Team-Namen
|
||||
setTeamNameFunc := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
if len(args) > 0 {
|
||||
teamName := args[0].String()
|
||||
g.teamName = teamName
|
||||
log.Printf("🏷️ Team-Name gesetzt: '%s'", teamName)
|
||||
go g.sendSetTeamNameInput(teamName)
|
||||
}
|
||||
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)
|
||||
js.Global().Set("setTeamName_WASM", setTeamNameFunc)
|
||||
|
||||
log.Println("✅ JavaScript Bridge registriert")
|
||||
}
|
||||
@@ -131,6 +143,7 @@ func (g *Game) sendLobbyPlayersToJS() {
|
||||
g.stateMutex.Lock()
|
||||
players := make([]interface{}, 0, len(g.gameState.Players))
|
||||
hostID := g.gameState.HostID
|
||||
teamName := g.gameState.TeamName
|
||||
|
||||
for id, p := range g.gameState.Players {
|
||||
name := p.Name
|
||||
@@ -151,4 +164,12 @@ func (g *Game) sendLobbyPlayersToJS() {
|
||||
updateFunc.Invoke(jsPlayers)
|
||||
log.Printf("👥 Lobby-Spieler an JavaScript gesendet: %d Spieler", len(players))
|
||||
}
|
||||
|
||||
// Team-Name an JavaScript senden
|
||||
if updateTeamFunc := js.Global().Get("updateLobbyTeamName"); !updateTeamFunc.IsUndefined() {
|
||||
myID := g.getMyPlayerID()
|
||||
isHost := (myID == hostID)
|
||||
updateTeamFunc.Invoke(teamName, isHost)
|
||||
log.Printf("🏷️ Team-Name an JavaScript gesendet: '%s' (isHost: %v)", teamName, isHost)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user