Floating chat messages and remote server

This commit is contained in:
2025-01-13 14:22:24 +01:00
parent d301d597e8
commit c01b8d1c59
3 changed files with 74 additions and 4 deletions

View File

@ -23,6 +23,7 @@ type Chat struct {
isTyping bool
cursorPos int
scrollOffset int
userData interface{}
}
func NewChat() *Chat {
@ -61,6 +62,25 @@ func (c *Chat) HandleServerMessages(messages []*pb.ChatMessage) {
c.messages = c.messages[1:]
}
c.messages = append(c.messages, localMsg)
// Add floating message to the player
if game, ok := c.userData.(*Game); ok {
if msg.PlayerId == game.Player.ID {
game.Player.Lock()
game.Player.FloatingMessage = &types.FloatingMessage{
Content: msg.Content,
ExpireTime: time.Now().Add(6 * time.Second),
}
game.Player.Unlock()
} else if otherPlayer, exists := game.OtherPlayers[msg.PlayerId]; exists {
otherPlayer.Lock()
otherPlayer.FloatingMessage = &types.FloatingMessage{
Content: msg.Content,
ExpireTime: time.Now().Add(6 * time.Second),
}
otherPlayer.Unlock()
}
}
}
}
}