Compare commits
3 Commits
enha/sse-t
...
master
Author | SHA1 | Date | |
---|---|---|---|
57a2abc1f9 | |||
995f9f6249 | |||
ccf0b8538f |
@ -2,12 +2,13 @@ body{
|
||||
background-color: #0C1616FF;
|
||||
color: #8896b2;
|
||||
min-width: 0px;
|
||||
margin: 2em auto !important;
|
||||
margin: 2em 2em !important;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
line-height: 1.5;
|
||||
font-size: 16px;
|
||||
font-family: Open Sans,Arial;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
display: block;
|
||||
}
|
||||
@ -22,18 +23,6 @@ tr{
|
||||
#usertable{
|
||||
display: block ruby;
|
||||
}
|
||||
.actiontable{
|
||||
display: inline flow-root;
|
||||
margin-inline: 10px;
|
||||
}
|
||||
.action_name{
|
||||
border: none;
|
||||
display: inline;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
padding: none;
|
||||
width: auto;
|
||||
}
|
||||
#errorbox{
|
||||
border: 1px solid black;
|
||||
background-color: darkorange;
|
||||
|
Binary file not shown.
@ -9,7 +9,7 @@ import (
|
||||
|
||||
// the amount of time to wait when pushing a message to
|
||||
// a slow client or a client that closed after `range clients` started.
|
||||
const patience time.Duration = time.Second * 1
|
||||
const patience time.Duration = time.Millisecond * 500
|
||||
|
||||
type (
|
||||
NotificationEvent struct {
|
||||
|
@ -3,7 +3,46 @@
|
||||
<div class="flex justify-center">
|
||||
<div class="grid grid-cols-2 sm:grid-cols-5 gap-2">
|
||||
{{range .Cards}}
|
||||
{{template "cardword" .}}
|
||||
{{if .Revealed}}
|
||||
{{if eq .Color "amber"}}
|
||||
<div id="card-{{.Word}}" class="bg-{{.Color}}-100 border-8 border-stine-400 p-4 min-w-[100px] text-center text-white cursor-pointer"
|
||||
style="text-shadow: 0 2px 4px rgba(0,0,0,0.9);"> {{.Word}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div id="card-{{.Word}}" class="bg-{{.Color}}-400 border-8 border-stone-400 p-4 min-w-[100px] text-center text-white cursor-pointer"
|
||||
style="text-shadow: 0 2px 4px rgba(0,0,0,0.9);"> {{.Word}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{else if or (.Mime) ($.IsOver)}}
|
||||
{{if eq .Color "amber"}}
|
||||
<div id="card-{{.Word}}" class="bg-{{.Color}}-100 border border-stone-400 p-4 rounded-lg min-w-[100px] text-center text-white cursor-pointer"
|
||||
style="text-shadow: 0 2px 4px rgba(0,0,0,0.9);"> {{.Word}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div id="card-{{.Word}}" class="bg-{{.Color}}-400 border border-stone-400 p-4 rounded-lg min-w-[100px] text-center text-white cursor-pointer"
|
||||
style="text-shadow: 0 2px 4px rgba(0,0,0,0.9);"> {{.Word}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{else}}
|
||||
<div id="card-{{.Word}}" class="bg-stone-400 border border-gray-500 rounded-lg min-w-[100px] cursor-pointer flex flex-col h-full">
|
||||
<div class="flex-grow text-center p-4 flex items-center justify-center text-white"
|
||||
style="text-shadow: 0 2px 4px rgba(0,0,0,0.8);"
|
||||
hx-get="/word/show-color?word={{.Word}}" hx-trigger="click" hx-swap="outerHTML transition:true swap:.05s">
|
||||
{{.Word}}
|
||||
</div>
|
||||
<div class="h-6 bg-stone-600 rounded-b flex items-center justify-center text-white text-sm cursor-pointer"
|
||||
hx-get="/mark-card?word={{.Word}}" hx-trigger="click" hx-swap="outerHTML transition:true swap:.05s">
|
||||
{{range .Marks}}
|
||||
{{ $length := len .Username }}
|
||||
{{ if lt $length 3 }}
|
||||
<span class="mx-0.5">{{.Username}}</span>
|
||||
{{else}}
|
||||
<span class="mx-0.5">{{slice .Username 0 3}}</span>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -9,7 +9,7 @@
|
||||
style="text-shadow: 0 2px 4px rgba(0,0,0,0.9);"> {{.Word}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{else if .Mime}}
|
||||
{{else if or (.Mime) }}
|
||||
{{if eq .Color "amber"}}
|
||||
<div id="card-{{.Word}}" class="bg-{{.Color}}-100 border border-stone-400 p-4 rounded-lg min-w-[100px] text-center text-white cursor-pointer"
|
||||
style="text-shadow: 0 2px 4px rgba(0,0,0,0.9);"> {{.Word}}
|
||||
|
@ -4,9 +4,9 @@
|
||||
Create a room <br/>
|
||||
or<br/>
|
||||
<button button class="justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" hx-get="/room/hideform" hx-target=".create-room-div" >Hide Form</button>
|
||||
<form hx-post="/room-create" hx-target="#main-content">
|
||||
<form hx-post="/room-create" hx-target="#main-content" class="space-y-4">
|
||||
<label For="game_time">Turn Seconds:</label><br/>
|
||||
<input type="number" id="game_time" name="game_time" class="text-center text-white" value="300"/><br/>
|
||||
<input type="number" id="game_time" name="game_time" class="text-center text-white" value="120"/><br/>
|
||||
<label For="language">Language:</label><br/>
|
||||
<div>
|
||||
<select class="form-select text-white text-center bg-gray-900" id="languages" name="language">
|
||||
|
@ -1,6 +1,6 @@
|
||||
{{define "error"}}
|
||||
<a href="/">
|
||||
<div id=errorbox class="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4" role="alert">
|
||||
<div id=errorbox class="bg-orange-100 border-l-4 border-black text-black p-4" role="alert">
|
||||
<p class="font-bold">An error from server</p>
|
||||
<p>{{.}}</p>
|
||||
<p>Click this banner to return to main page.</p>
|
||||
|
11
components/journal.html
Normal file
11
components/journal.html
Normal file
@ -0,0 +1,11 @@
|
||||
{{define "journal"}}
|
||||
<div id="systembox" class="overflow-y-auto max-h-96 border-2 border-gray-300 p-4 rounded-lg space-y-2">
|
||||
bot journal: <br>
|
||||
<ul>
|
||||
{{range .LogJournal}}
|
||||
<li>{{.Username}}: {{.Entry}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -1,19 +1,21 @@
|
||||
{{define "login"}}
|
||||
<div id="logindiv">
|
||||
<form class="space-y-6" hx-post="/login" hx-target="#main-content">
|
||||
<form hx-post="/login" hx-target="#main-content" class="space-y-4">
|
||||
<div>
|
||||
<label For="username" class="block text-sm font-medium leading-6 text-white-900">tell us your username (signup|login)</label>
|
||||
<label For="username" class="text-sm text-center font-medium leading-6 text-white-900">tell us your username (signup|login)</label>
|
||||
<div class="mt-2">
|
||||
<input id="username" name="username" hx-target="#login_notice" hx-swap="outerHTML" hx-post="/check/name" hx-trigger="input changed delay:400ms" autocomplete="username" required class="block w-full rounded-md border-0 bg-white py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 text-center"/>
|
||||
<input id="username" name="username" hx-target="#login_notice" hx-swap="outerHTML" hx-post="/check/name" hx-trigger="input changed delay:400ms" autocomplete="username" required class="text-center rounded-md border-0 bg-white py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 text-center"/>
|
||||
</div>
|
||||
<div id="login_notice">this name looks available</div>
|
||||
</div>
|
||||
<div>
|
||||
<label For="password" class="block text-sm font-medium leading-6 text-white-900">password</label>
|
||||
<input id="password" name="password" type="password" class="block w-full rounded-md border-0 bg-white py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 text-center"/>
|
||||
<label For="password" class="text-sm font-medium text-center leading-6 text-white-900">password</label>
|
||||
<div class="mt-2">
|
||||
<input id="password" name="password" type="password" class="rounded-md border-0 bg-white py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 text-center"/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Sign in</button>
|
||||
<button type="submit" class="justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Sign in</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -53,21 +53,15 @@
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="grid grid-cols-1 md:grid-cols-5 md:gap-4">
|
||||
<div hx-get="/actionhistory" hx-trigger="sse:backlog_{{.Room.ID}}" class="md:col-span-1">
|
||||
<div class="md:col-span-1">
|
||||
{{template "actionhistory" .Room.ActionHistory}}
|
||||
</div>
|
||||
<div id="cardtable" class="md:col-span-3">
|
||||
{{template "cardtable" .Room}}
|
||||
</div>
|
||||
<div class="hidden md:block md:col-span-1"></div> <!-- Spacer -->
|
||||
</div>
|
||||
<div id="systembox" class="overflow-y-auto max-h-96 border-2 border-gray-300 p-4 rounded-lg space-y-2">
|
||||
bot thought: <br>
|
||||
<ul>
|
||||
{{range .Room.LogJournal}}
|
||||
<li>{{.Username}}: {{.Entry}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
<div class="hidden md:block md:col-span-1">
|
||||
{{template "journal" .Room}}
|
||||
</div> <!-- Spacer -->
|
||||
</div>
|
||||
<div>
|
||||
{{if .Room.IsRunning}}
|
||||
|
@ -106,8 +106,9 @@ func HandleExit(w http.ResponseWriter, r *http.Request) {
|
||||
if err := repo.RoomDeleteByID(r.Context(), fi.Room.ID); err != nil {
|
||||
log.Error("failed to remove room", "error", err)
|
||||
}
|
||||
notify(models.NotifyRoomListUpdate, "")
|
||||
notify(models.NotifyRoomListUpdate, "") // why is it needed?
|
||||
} else {
|
||||
notify(models.NotifyRoomUpdatePrefix, "")
|
||||
// if regular player leaves, just exit room
|
||||
if err := repo.PlayerExitRoom(r.Context(), fi.State.Username); err != nil {
|
||||
log.Error("failed to exit room", "error", err)
|
||||
|
@ -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
|
||||
@ -23,7 +23,7 @@ func StartTurnTimer(roomID string, timeLeft uint32) {
|
||||
if err := repo.RoomUpdate(context.Background(), room); err != nil {
|
||||
logger.Error("failed to save room", "error", err)
|
||||
}
|
||||
notify(models.NotifyTurnTimerPrefix+room.ID, strconv.FormatUint(uint64(room.Settings.RoundTime), 10))
|
||||
// notify(models.NotifyTurnTimerPrefix+room.ID, strconv.FormatUint(uint64(room.Settings.RoundTime), 10))
|
||||
notifyBotIfNeeded(room)
|
||||
}
|
||||
|
||||
@ -31,9 +31,10 @@ func StartTurnTimer(roomID string, timeLeft uint32) {
|
||||
notify(models.NotifyTurnTimerPrefix+roomID, strconv.FormatUint(uint64(currentLeft), 10))
|
||||
}
|
||||
|
||||
timer.StartTurnTimer(context.Background(), roomID, timeLeft, onTurnEnd, onTick, logger)
|
||||
timer.StartTurnTimer(context.Background(), roomID, int32(timeLeft), onTurnEnd, onTick, logger)
|
||||
}
|
||||
|
||||
func StopTurnTimer(roomID string) {
|
||||
timer.StopTurnTimer(roomID)
|
||||
}
|
||||
|
||||
|
@ -173,6 +173,7 @@ func (p *openRouterParser) MakePayload(prompt string) io.Reader {
|
||||
model := models[int(p.modelIndex)%len(models)]
|
||||
strPayload := fmt.Sprintf(`{
|
||||
"model": "%s",
|
||||
"max_tokens": 300,
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
|
@ -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
|
||||
@ -24,10 +24,10 @@ func (b *Bot) StartTurnTimer(timeLeft uint32) {
|
||||
if err := repos.RP.RoomUpdate(context.Background(), room); err != nil {
|
||||
logger.Error("failed to save room", "error", err)
|
||||
}
|
||||
broker.Notifier.Notifier <- broker.NotificationEvent{
|
||||
EventName: models.NotifyTurnTimerPrefix + room.ID,
|
||||
Payload: strconv.FormatUint(uint64(room.Settings.RoundTime), 10),
|
||||
}
|
||||
// broker.Notifier.Notifier <- broker.NotificationEvent{
|
||||
// EventName: models.NotifyTurnTimerPrefix + room.ID,
|
||||
// Payload: strconv.FormatUint(uint64(room.Settings.RoundTime), 10),
|
||||
// }
|
||||
// notifyBotIfNeeded(room)
|
||||
if botName := room.WhichBotToMove(); botName != "" {
|
||||
SignalChanMap[botName] <- true
|
||||
@ -41,9 +41,10 @@ func (b *Bot) StartTurnTimer(timeLeft uint32) {
|
||||
}
|
||||
}
|
||||
|
||||
timer.StartTurnTimer(context.Background(), b.RoomID, timeLeft, onTurnEnd, onTick, logger)
|
||||
timer.StartTurnTimer(context.Background(), b.RoomID, int32(timeLeft), onTurnEnd, onTick, logger)
|
||||
}
|
||||
|
||||
func (b *Bot) StopTurnTimer() {
|
||||
timer.StopTurnTimer(b.RoomID)
|
||||
}
|
||||
|
||||
|
@ -410,12 +410,20 @@ 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"`
|
||||
// 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:"-"`
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ var (
|
||||
)
|
||||
|
||||
// StartTurnTimer initializes and starts a new turn timer for a given room.
|
||||
func StartTurnTimer(ctx context.Context, roomID string, timeLeft uint32, onTurnEnd TurnEndCallback, onTick TickCallback, logger *slog.Logger) {
|
||||
func StartTurnTimer(ctx context.Context, roomID string, timeLeft int32, onTurnEnd TurnEndCallback, onTick TickCallback, logger *slog.Logger) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
@ -62,7 +62,7 @@ func StartTurnTimer(ctx context.Context, roomID string, timeLeft uint32, onTurnE
|
||||
StopTurnTimer(roomID)
|
||||
return
|
||||
}
|
||||
rt.onTick(ctx, roomID, currentLeft)
|
||||
rt.onTick(ctx, roomID, uint32(currentLeft))
|
||||
currentLeft--
|
||||
}
|
||||
}
|
||||
|
5
todos.md
5
todos.md
@ -93,3 +93,8 @@
|
||||
- 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;
|
||||
|
||||
- timers conflict; stop timers;
|
||||
- clue snatching;
|
||||
- llm resp token amount limit;
|
||||
|
Reference in New Issue
Block a user