Fix: show color; add bot [WIP]
This commit is contained in:
@ -260,5 +260,8 @@ func loadCards(room *models.Room) {
|
||||
fmt.Println("failed to load cards", "error", err)
|
||||
}
|
||||
room.Cards = cards
|
||||
|
||||
room.WCMap = make(map[string]models.WordColor)
|
||||
for _, card := range room.Cards {
|
||||
room.WCMap[card.Word] = card.Color
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"golias/llmapi"
|
||||
"golias/models"
|
||||
"html/template"
|
||||
"net/http"
|
||||
@ -55,7 +56,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
|
||||
abortWithError(w, "wait for the clue")
|
||||
return
|
||||
}
|
||||
color, exists := roundWords[word]
|
||||
color, exists := fi.Room.WCMap[word]
|
||||
log.Debug("got show-color request", "word", word, "color", color)
|
||||
if !exists {
|
||||
abortWithError(w, "word is not found")
|
||||
@ -63,7 +64,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
cardword := models.WordCard{
|
||||
Word: word,
|
||||
Color: models.StrToWordColor(color),
|
||||
Color: color,
|
||||
Revealed: true,
|
||||
}
|
||||
fi.Room.RevealSpecificWord(word)
|
||||
@ -71,14 +72,14 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
|
||||
action := models.Action{
|
||||
Actor: fi.State.Username,
|
||||
ActorColor: string(fi.State.Team),
|
||||
WordColor: color,
|
||||
WordColor: string(color),
|
||||
Action: "guessed",
|
||||
Word: word,
|
||||
}
|
||||
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
|
||||
// if opened card is of color of opp team, change turn
|
||||
oppositeColor := fi.Room.GetOppositeTeamColor()
|
||||
switch color {
|
||||
switch string(color) {
|
||||
case "black":
|
||||
// game over
|
||||
fi.Room.IsRunning = false
|
||||
@ -122,3 +123,21 @@ func HandleActionHistory(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
tmpl.ExecuteTemplate(w, "actionhistory", fi.Room.ActionHistory)
|
||||
}
|
||||
|
||||
func HandleAddBot(w http.ResponseWriter, r *http.Request) {
|
||||
// get team; // get role; make up a name
|
||||
team := r.URL.Query().Get("team")
|
||||
role := r.URL.Query().Get("role")
|
||||
fi, err := getFullInfoByCtx(r.Context())
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
bot, err := llmapi.NewBot(role, team, "bot1", fi.Room.ID, cfg)
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
bot.StartBot()
|
||||
notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "")
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ func init() {
|
||||
}))
|
||||
memcache = cache.MemCache
|
||||
cfg = config.LoadConfigOrDefault("")
|
||||
Notifier = broker.NewBroker()
|
||||
go Notifier.Listen()
|
||||
Notifier = broker.Notifier
|
||||
// go Notifier.Listen()
|
||||
}
|
||||
|
||||
var roundWords = map[string]string{
|
||||
|
Reference in New Issue
Block a user