Fix chat and other players not showing up

This commit is contained in:
2025-04-16 11:13:52 +02:00
parent 5bf962a18d
commit 555b8118f2
6 changed files with 80 additions and 33 deletions
+11
View File
@@ -2,6 +2,7 @@ package game
import (
"fmt"
"log"
"sync"
"time"
@@ -54,6 +55,12 @@ func (c *Chat) HandleServerMessages(messages []*pb.ChatMessage) {
c.mutex.Lock()
defer c.mutex.Unlock()
if len(messages) == 0 {
return
}
log.Printf("Processing %d chat messages", len(messages))
// Convert protobuf messages to our local type
for _, msg := range messages {
localMsg := types.ChatMessage{
@@ -69,6 +76,7 @@ func (c *Chat) HandleServerMessages(messages []*pb.ChatMessage) {
c.messages = c.messages[1:]
}
c.messages = append(c.messages, localMsg)
log.Printf("Added chat message from %s: %s", msg.Username, msg.Content)
// Scroll to latest message if it's not already visible
visibleMessages := int((chatHeight - inputHeight) / messageHeight)
@@ -92,6 +100,9 @@ func (c *Chat) HandleServerMessages(messages []*pb.ChatMessage) {
ExpireTime: time.Now().Add(6 * time.Second),
}
otherPlayer.Unlock()
log.Printf("Added floating message to other player %d", msg.PlayerId)
} else {
log.Printf("Could not find other player %d to add floating message", msg.PlayerId)
}
}
}