Enha: clear marks by room id

This commit is contained in:
Grail Finder
2025-07-07 07:53:12 +03:00
parent a796b5b5de
commit 7ae255cc04
3 changed files with 17 additions and 6 deletions

View File

@ -87,6 +87,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
// if opened card is of color of opp team, change turn
oppositeColor := fi.Room.GetOppositeTeamColor()
var clearMarks bool
fi.Room.OpenedThisTurn++
log.Debug("got show-color request", "word", word, "color", color,
"limit", fi.Room.ThisTurnLimit, "opened", fi.Room.OpenedThisTurn,
@ -98,7 +99,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
fi.Room.MimeDone = false
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
fi.Room.ClearMarks()
clearMarks = true
StopTurnTimer(fi.Room.ID)
}
switch string(color) {
@ -118,7 +119,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
fi.Room.ClearMarks()
clearMarks = true
StopTurnTimer(fi.Room.ID)
case string(models.WordColorWhite), string(oppositeColor):
log.Debug("opened white or opposite color word", "word", word, "opposite-color", oppositeColor)
@ -127,6 +128,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
fi.Room.MimeDone = false
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
clearMarks = true
StopTurnTimer(fi.Room.ID)
// check if no cards left => game over
if fi.Room.BlueCounter == 0 {
@ -142,7 +144,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
Action: models.ActionTypeGameOver,
}
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
fi.Room.ClearMarks()
}
if fi.Room.RedCounter == 0 {
// red won
@ -157,7 +158,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
Action: models.ActionTypeGameOver,
}
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
fi.Room.ClearMarks()
}
default: // same color as the team
// check if game over
@ -173,7 +173,12 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
Action: models.ActionTypeGameOver,
}
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
fi.Room.ClearMarks()
}
}
if clearMarks {
fi.Room.ClearMarks()
if err := repo.CardMarksRemoveByRoomID(r.Context(), fi.Room.ID); err != nil {
log.Error("failed to remove marks", "error", err, "room_id", fi.Room.ID)
}
}
if err := saveFullInfo(r.Context(), fi); err != nil {