mirror of
https://github.com/tiennm99/noitu.git
synced 2026-10-15 14:16:31 +00:00
feat(online): seat the chat beside the game and score the series
A room screen wide enough for it is two columns now: the game or the lobby on one side and the room's conversation on the other, so neither has to be scrolled past to reach the other. A phone keeps one column, the game first, with the chat folded behind an unread count while a game is on. One chat panel spans both phases by staying in the same place in the markup — a remounted panel reopened having read nothing, and handed the reader the lobby's conversation back as unread mail. The room also keeps the score of the series. PlayerSlot carries the games a seat has won since the room opened, credited before the lobby is broadcast so the players see it the moment a game ends, and shown in the lobby and beside each player's score on the board. It belongs to the seat rather than to the room, because vacating one is exactly when the name on it stops meaning the same person. The conversation reads as a log — one line per message, "name: text", each seat in its own colour — rather than as a stack of bubbles, which stops being legible once four people are talking. ChatMessage carries the seat that spoke, so a line is coloured by what the server said rather than by matching display names, and a line whose seat has been vacated is in nobody's colour. The board's word button gets a test id of its own: it and the chat's send button both read "Gửi", and the two are now on screen together.
This commit is contained in:
1 parent
4e2e9e1433
commit
e19b083dc0
24 files changed
+521
-104
No files matched your search
@@ -176,6 +176,11 @@ type seat struct {
|
||||
// filled. A replay starts there, which is what keeps a stranger who walks
|
||||
// in with the code from being handed what the last two people said.
|
||||
chatFrom uint64
|
||||
// wins counts the games this seat has taken since it was filled. A room
|
||||
// outlives its games, so a running tally has to live on something that
|
||||
// does too; the seat is the shortest-lived thing that still spans them,
|
||||
// and vacating it is exactly when the tally stops meaning one player.
|
||||
wins uint32
|
||||
// graceUntil is when this seat stops being held for the player who dropped
|
||||
// out of it, and zero while they are connected. Per seat rather than per
|
||||
// room because any number of them can be waiting at once.
|
||||
@@ -983,6 +988,12 @@ func (r *room) broadcastGameOver(state game.State) {
|
||||
reason = r.wireEndReason(state.Eliminated[n-1])
|
||||
}
|
||||
|
||||
// Credited before anything is sent, so the RoomState the run loop
|
||||
// broadcasts after a finished game already carries the game just won.
|
||||
if s := r.seatOf(state.Winner); s != nil {
|
||||
s.wins++
|
||||
}
|
||||
|
||||
ranks := make(map[game.PlayerID]int, len(state.Standings))
|
||||
order := make([]game.PlayerID, 0, len(state.Standings))
|
||||
for _, standing := range state.Standings {
|
||||
@@ -1258,6 +1269,9 @@ func chatMessageFor(entry chatEntry, id game.PlayerID) *noituv1.ServerMessage {
|
||||
return &noituv1.ServerMessage{Payload: &noituv1.ServerMessage_ChatMessage{
|
||||
ChatMessage: &noituv1.ChatMessage{
|
||||
FromMe: entry.author != "" && entry.author == id,
|
||||
// Empty together with the name for a vacated seat: a line nobody
|
||||
// owns must not be coloured as somebody's either.
|
||||
PlayerId: string(entry.author),
|
||||
Author: entry.name,
|
||||
Text: entry.text,
|
||||
SentUnixMs: entry.at.UnixMilli(),
|
||||
@@ -1453,6 +1467,7 @@ func (r *room) playerSlots(me game.PlayerID) []*noituv1.PlayerSlot {
|
||||
IsOwner: s.id == r.owner,
|
||||
Ready: s.ready,
|
||||
Connected: s.sess != nil,
|
||||
Wins: s.wins,
|
||||
})
|
||||
}
|
||||
return slots
|
||||
|
||||
Reference in new issue
Block a user