Chore: remove unused WCMap
This commit is contained in:
@ -205,10 +205,10 @@ 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
|
||||
}
|
||||
// room.WCMap = make(map[string]models.WordColor)
|
||||
// for _, card := range room.Cards {
|
||||
// room.WCMap[card.Word] = card.Color
|
||||
// }
|
||||
}
|
||||
|
||||
func recoverBots() {
|
||||
|
@ -50,7 +50,8 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
color, exists := fi.Room.WCMap[word]
|
||||
// color, exists := fi.Room.WCMap[word]
|
||||
color, exists := fi.Room.FindColor(word)
|
||||
if !exists {
|
||||
abortWithError(w, "word is not found")
|
||||
return
|
||||
@ -191,8 +192,9 @@ func HandleMarkCard(w http.ResponseWriter, r *http.Request) {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
color, exists := fi.Room.WCMap[word]
|
||||
log.Debug("got show-color request", "word", word, "color", color)
|
||||
// color, exists := fi.Room.WCMap[word]
|
||||
color, exists := fi.Room.FindColor(word)
|
||||
log.Debug("got mark-card request", "word", word, "color", color)
|
||||
if !exists {
|
||||
abortWithError(w, "word is not found")
|
||||
return
|
||||
|
@ -2,7 +2,6 @@ package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gralias/models"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
@ -55,7 +54,7 @@ func StartTurnTimer(roomID string, timeLeft uint32) {
|
||||
return
|
||||
}
|
||||
timeLeft--
|
||||
notify(models.NotifyTurnTimerPrefix+roomID, fmt.Sprintf("%d", timeLeft))
|
||||
notify(models.NotifyTurnTimerPrefix+roomID, strconv.FormatUint(uint64(timeLeft), 10))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -68,7 +68,8 @@ func (b *Bot) checkGuesses(tempMap map[string]any, room *models.Room) error {
|
||||
}
|
||||
|
||||
func (b *Bot) checkGuess(word string, room *models.Room) error {
|
||||
color, exists := room.WCMap[word]
|
||||
// color, exists := room.WCMap[word]
|
||||
color, exists := room.FindColor(word)
|
||||
b.log.Debug("bot trying to open card", "word", word, "color",
|
||||
color, "exists", exists, "limit", room.ThisTurnLimit,
|
||||
"opened", room.OpenedThisTurn)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gralias/utils"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/xid"
|
||||
@ -146,15 +147,24 @@ type Room struct {
|
||||
TeamWon UserTeam `db:"team_won"`
|
||||
RoomLink string `db:"room_link"`
|
||||
// fields not in db
|
||||
ActionHistory []Action `db:"-"`
|
||||
RedTeam Team `db:"-"`
|
||||
BlueTeam Team `db:"-"`
|
||||
Cards []WordCard `db:"-"`
|
||||
WCMap map[string]WordColor `db:"-"`
|
||||
BotMap map[string]BotPlayer `db:"-"`
|
||||
Mark CardMark `db:"-"`
|
||||
LogJournal []string `db:"-"`
|
||||
Settings GameSettings `db:"-"`
|
||||
ActionHistory []Action `db:"-"`
|
||||
RedTeam Team `db:"-"`
|
||||
BlueTeam Team `db:"-"`
|
||||
Cards []WordCard `db:"-"`
|
||||
// WCMap map[string]WordColor `db:"-"`
|
||||
BotMap map[string]BotPlayer `db:"-"`
|
||||
Mark CardMark `db:"-"`
|
||||
LogJournal []string `db:"-"`
|
||||
Settings GameSettings `db:"-"`
|
||||
}
|
||||
|
||||
func (r *Room) FindColor(word string) (WordColor, bool) {
|
||||
for _, card := range r.Cards {
|
||||
if strings.EqualFold(card.Word, word) {
|
||||
return card.Color, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func (r *Room) ClearMarks() {
|
||||
@ -386,13 +396,13 @@ type WordCard struct {
|
||||
|
||||
// table: settings
|
||||
type GameSettings struct {
|
||||
ID uint32 `json:"id" db:"id"`
|
||||
RoomID string `db:"room_id"`
|
||||
Language string `json:"language" example:"en" form:"language" db:"language"`
|
||||
RoomPass string `json:"room_pass" db:"room_pass"`
|
||||
ID uint32 `json:"id" db:"id"`
|
||||
RoomID string `db:"room_id"`
|
||||
Language string `json:"language" example:"en" form:"language" db:"language"`
|
||||
RoomPass string `json:"room_pass" db:"room_pass"`
|
||||
|
||||
RoundTime uint32 `json:"round_time" db:"turn_time"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
RoundTime uint32 `json:"round_time" db:"turn_time"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
}
|
||||
|
||||
// =====
|
||||
|
Reference in New Issue
Block a user