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