Private
Public Access
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:
1 parent
ce51a2ba4f
commit
95d61bf66e
68 files changed
+913
-424
No files matched your search
+44
-9
@@ -93,7 +93,25 @@ func main() {
|
||||
log.Printf("🔍 RAW NATS: Nachricht empfangen auf game.join: %s", string(m.Data))
|
||||
})
|
||||
|
||||
// 4. HANDLER: INPUT
|
||||
// 4. HANDLER: GAME START
|
||||
_, _ = ec.Subscribe("game.start", func(req *game.StartRequest) {
|
||||
log.Printf("▶️ START empfangen: RoomID=%s", req.RoomID)
|
||||
|
||||
mu.RLock()
|
||||
room, exists := rooms[req.RoomID]
|
||||
mu.RUnlock()
|
||||
|
||||
if exists {
|
||||
room.Mutex.Lock()
|
||||
room.StartCountdown()
|
||||
room.Mutex.Unlock()
|
||||
log.Printf("🎮 Raum '%s' Countdown gestartet", req.RoomID)
|
||||
} else {
|
||||
log.Printf("❌ Raum '%s' nicht gefunden", req.RoomID)
|
||||
}
|
||||
})
|
||||
|
||||
// 5. HANDLER: INPUT
|
||||
_, _ = ec.Subscribe("game.input", func(input *game.ClientInput) {
|
||||
mu.RLock()
|
||||
room, ok := playerSessions[input.PlayerID]
|
||||
@@ -104,23 +122,40 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
// 5. HANDLER: SCORE SUBMISSION
|
||||
// 6. HANDLER: SCORE SUBMISSION
|
||||
_, _ = ec.Subscribe("score.submit", func(submission *game.ScoreSubmission) {
|
||||
log.Printf("📊 Score-Submission: %s (%s) mit %d Punkten", submission.PlayerName, submission.PlayerCode, submission.Score)
|
||||
added := server.GlobalLeaderboard.AddScore(submission.PlayerName, submission.PlayerCode, submission.Score)
|
||||
// Verwende Team-Name wenn vorhanden (Coop-Mode), sonst Player-Name (Solo-Mode)
|
||||
displayName := submission.PlayerName
|
||||
if submission.TeamName != "" {
|
||||
displayName = submission.TeamName
|
||||
}
|
||||
|
||||
log.Printf("📊 Score-Submission: %s (%s) mit %d Punkten [Mode: %s]", displayName, submission.PlayerCode, submission.Score, submission.Mode)
|
||||
added, proofCode := server.GlobalLeaderboard.AddScore(displayName, submission.PlayerCode, submission.Score)
|
||||
if added {
|
||||
log.Printf("✅ Score akzeptiert für %s", submission.PlayerName)
|
||||
log.Printf("✅ Score akzeptiert für %s (Proof: %s)", displayName, proofCode)
|
||||
|
||||
// Sende Response zurück über NATS
|
||||
response := game.ScoreSubmissionResponse{
|
||||
Success: true,
|
||||
ProofCode: proofCode,
|
||||
Score: submission.Score,
|
||||
}
|
||||
// Sende an player-spezifischen Channel
|
||||
channel := "score.response." + submission.PlayerCode
|
||||
ec.Publish(channel, &response)
|
||||
log.Printf("📤 Proof-Code gesendet an Channel: %s", channel)
|
||||
}
|
||||
})
|
||||
|
||||
// 6. HANDLER: LEADERBOARD REQUEST (alt, für Kompatibilität)
|
||||
// 7. HANDLER: LEADERBOARD REQUEST (alt, für Kompatibilität)
|
||||
_, _ = ec.Subscribe("leaderboard.get", func(subject, reply string, _ *struct{}) {
|
||||
top10 := server.GlobalLeaderboard.GetTop10()
|
||||
log.Printf("📊 Leaderboard-Request beantwortet: %d Einträge", len(top10))
|
||||
ec.Publish(reply, top10)
|
||||
})
|
||||
|
||||
// 7. HANDLER: LEADERBOARD REQUEST (neu, für WebSocket-Gateway)
|
||||
// 8. HANDLER: LEADERBOARD REQUEST (neu, für WebSocket-Gateway)
|
||||
_, _ = ec.Subscribe("leaderboard.request", func(req *game.LeaderboardRequest) {
|
||||
top10 := server.GlobalLeaderboard.GetTop10()
|
||||
log.Printf("📊 Leaderboard-Request (Mode=%s): %d Einträge", req.Mode, len(top10))
|
||||
@@ -137,7 +172,7 @@ func main() {
|
||||
|
||||
log.Println("✅ Server bereit. Warte auf Spieler...")
|
||||
|
||||
// 5. WEBSOCKET-GATEWAY STARTEN (für Browser-Clients)
|
||||
// 9. WEBSOCKET-GATEWAY STARTEN (für Browser-Clients)
|
||||
go StartWebSocketGateway("8080", ec)
|
||||
|
||||
// Block forever
|
||||
@@ -145,7 +180,7 @@ func main() {
|
||||
}
|
||||
|
||||
func loadServerAssets(w *game.World) {
|
||||
assetDir := "./cmd/client/assets"
|
||||
assetDir := "./cmd/client/web/assets"
|
||||
chunkDir := filepath.Join(assetDir, "chunks")
|
||||
|
||||
// Manifest laden
|
||||
|
||||
Reference in new issue
Block a user