From 995f9f6249032281204ecec5b1018a20cfafd5bf Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Wed, 16 Jul 2025 11:06:13 +0300 Subject: [PATCH] Fix: timers and styles --- components/cardtable.html | 41 +++++++++++++++++++++++++++++++++- components/cardword.html | 2 +- components/createroomform.html | 4 ++-- components/login.html | 6 ++--- handlers/timer.go | 5 +++-- llmapi/timer.go | 5 +++-- models/main.go | 22 ++++++++++++------ todos.md | 1 + 8 files changed, 68 insertions(+), 18 deletions(-) diff --git a/components/cardtable.html b/components/cardtable.html index 2bc037c..3af5a08 100644 --- a/components/cardtable.html +++ b/components/cardtable.html @@ -3,7 +3,46 @@
{{range .Cards}} - {{template "cardword" .}} + {{if .Revealed}} + {{if eq .Color "amber"}} +
{{.Word}} +
+ {{else}} +
{{.Word}} +
+ {{end}} + {{else if or (.Mime) ($.IsOver)}} + {{if eq .Color "amber"}} +
{{.Word}} +
+ {{else}} +
{{.Word}} +
+ {{end}} + {{else}} +
+
+ {{.Word}} +
+
+ {{range .Marks}} + {{ $length := len .Username }} + {{ if lt $length 3 }} + {{.Username}} + {{else}} + {{slice .Username 0 3}} + {{end}} + {{end}} +
+
+ {{end}} {{end}}
diff --git a/components/cardword.html b/components/cardword.html index 0aad880..641ddc7 100644 --- a/components/cardword.html +++ b/components/cardword.html @@ -9,7 +9,7 @@ style="text-shadow: 0 2px 4px rgba(0,0,0,0.9);"> {{.Word}} {{end}} -{{else if .Mime}} +{{else if or (.Mime) }} {{if eq .Color "amber"}}
{{.Word}} diff --git a/components/createroomform.html b/components/createroomform.html index 69f825b..b56c495 100644 --- a/components/createroomform.html +++ b/components/createroomform.html @@ -4,9 +4,9 @@ Create a room
or
-
+
-
+

this name looks available
- +
diff --git a/handlers/timer.go b/handlers/timer.go index 3f9d945..7807439 100644 --- a/handlers/timer.go +++ b/handlers/timer.go @@ -12,7 +12,7 @@ func StartTurnTimer(roomID string, timeLeft uint32) { logger := slog.Default().With("room_id", roomID) onTurnEnd := func(ctx context.Context, roomID string) { - room, err := repo.RoomGetByID(context.Background(), roomID) + room, err := repo.RoomGetExtended(context.Background(), roomID) if err != nil { logger.Error("failed to get room by id", "error", err) return @@ -36,4 +36,5 @@ func StartTurnTimer(roomID string, timeLeft uint32) { func StopTurnTimer(roomID string) { timer.StopTurnTimer(roomID) -} \ No newline at end of file +} + diff --git a/llmapi/timer.go b/llmapi/timer.go index 21bf0fa..5c1d30c 100644 --- a/llmapi/timer.go +++ b/llmapi/timer.go @@ -13,7 +13,7 @@ func (b *Bot) StartTurnTimer(timeLeft uint32) { logger := b.log.With("room_id", b.RoomID) onTurnEnd := func(ctx context.Context, roomID string) { - room, err := repos.RP.RoomGetByID(context.Background(), roomID) + room, err := repos.RP.RoomGetExtended(context.Background(), roomID) if err != nil { logger.Error("failed to get room by id", "error", err) return @@ -46,4 +46,5 @@ func (b *Bot) StartTurnTimer(timeLeft uint32) { func (b *Bot) StopTurnTimer() { timer.StopTurnTimer(b.RoomID) -} \ No newline at end of file +} + diff --git a/models/main.go b/models/main.go index e53d395..ffc78f7 100644 --- a/models/main.go +++ b/models/main.go @@ -410,14 +410,22 @@ func (r *Room) RevealSpecificWord(word string) uint32 { return 0 } +func (r *Room) SetGameOverToCards(isover bool) { + for i := range r.Cards { + r.Cards[i].IsOver = isover + } +} + type WordCard struct { - ID uint32 `json:"id" db:"id"` - RoomID string `json:"room_id" db:"room_id"` - Word string `json:"word" db:"word"` - Color WordColor `json:"color" db:"color"` - Revealed bool `json:"revealed" db:"revealed"` - Mime bool `json:"mime" db:"mime_view"` // user who sees that card is mime - Marks []CardMark `json:"marks" db:"-"` + ID uint32 `json:"id" db:"id"` + RoomID string `json:"room_id" db:"room_id"` + Word string `json:"word" db:"word"` + Color WordColor `json:"color" db:"color"` + Revealed bool `json:"revealed" db:"revealed"` + // pain; but at the end of the game players should see color of unopen cards + IsOver bool + Mime bool `json:"mime" db:"mime_view"` // user who sees that card is mime + Marks []CardMark `json:"marks" db:"-"` } // table: settings diff --git a/todos.md b/todos.md index e725224..a86e3cf 100644 --- a/todos.md +++ b/todos.md @@ -93,3 +93,4 @@ - journal still does not work; + - lose/win game; then exit room (while being the creator), then press to stats -> cannot find session in db, although cookie in place and session in db; + - exit endpoints delets player from db; + +- timer end did not update the page;