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:
@@ -92,6 +92,19 @@ func (g *Game) connectToServer() {
|
||||
// An JavaScript senden
|
||||
g.sendLeaderboardToJS()
|
||||
}
|
||||
|
||||
case "score_response":
|
||||
// Score Submission Response mit Proof-Code
|
||||
payloadBytes, _ := json.Marshal(msg.Payload)
|
||||
var resp game.ScoreSubmissionResponse
|
||||
if err := json.Unmarshal(payloadBytes, &resp); err == nil {
|
||||
log.Printf("🎯 Proof-Code empfangen: %s für Score: %d", resp.ProofCode, resp.Score)
|
||||
|
||||
// Proof-Code an JavaScript senden
|
||||
if saveFunc := js.Global().Get("saveHighscoreCode"); !saveFunc.IsUndefined() {
|
||||
saveFunc.Invoke(resp.Score, resp.ProofCode, g.playerName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -259,19 +272,34 @@ func (g *Game) submitScore() {
|
||||
name = g.teamName
|
||||
}
|
||||
|
||||
// Verwende Team-Name für Coop-Mode, sonst Player-Name
|
||||
displayName := name
|
||||
teamName := ""
|
||||
if g.gameMode == "coop" {
|
||||
g.stateMutex.Lock()
|
||||
teamName = g.gameState.TeamName
|
||||
g.stateMutex.Unlock()
|
||||
|
||||
if teamName != "" {
|
||||
displayName = teamName
|
||||
}
|
||||
}
|
||||
|
||||
msg := WebSocketMessage{
|
||||
Type: "score_submit",
|
||||
Payload: game.ScoreSubmission{
|
||||
PlayerName: displayName,
|
||||
PlayerCode: g.playerCode,
|
||||
Name: name,
|
||||
Name: displayName, // Für Kompatibilität
|
||||
Score: score,
|
||||
Mode: g.gameMode,
|
||||
TeamName: teamName, // Team-Name für Coop
|
||||
},
|
||||
}
|
||||
g.sendWebSocketMessage(msg)
|
||||
|
||||
g.scoreSubmitted = true
|
||||
log.Printf("📊 Score submitted: %s = %d", name, score)
|
||||
log.Printf("📊 Score submitted: %s = %d (TeamName: %s)", displayName, score, teamName)
|
||||
}
|
||||
|
||||
// Dummy-Funktionen für Kompatibilität mit anderen Teilen des Codes
|
||||
@@ -280,9 +308,41 @@ func (g *Game) sendJoinRequest() {
|
||||
}
|
||||
|
||||
func (g *Game) sendStartRequest() {
|
||||
// Warte bis WebSocket verbunden ist
|
||||
for i := 0; i < 30; i++ {
|
||||
if g.connected && g.wsConn != nil && g.wsConn.connected {
|
||||
break
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
if !g.connected {
|
||||
log.Println("❌ Kann START nicht senden - keine Verbindung")
|
||||
return
|
||||
}
|
||||
|
||||
g.startGame()
|
||||
}
|
||||
|
||||
func (g *Game) publishInput(input game.ClientInput) {
|
||||
g.sendInput(input)
|
||||
}
|
||||
|
||||
// sendSetTeamNameInput sendet SET_TEAM_NAME Input über WebSocket
|
||||
func (g *Game) sendSetTeamNameInput(teamName string) {
|
||||
if !g.connected {
|
||||
log.Println("❌ Kann Team-Name nicht senden - keine Verbindung")
|
||||
return
|
||||
}
|
||||
|
||||
myID := g.getMyPlayerID()
|
||||
input := game.ClientInput{
|
||||
Type: "SET_TEAM_NAME",
|
||||
RoomID: g.roomID,
|
||||
PlayerID: myID,
|
||||
TeamName: teamName,
|
||||
}
|
||||
|
||||
g.sendInput(input)
|
||||
log.Printf("🏷️ SET_TEAM_NAME gesendet: '%s'", teamName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user