Enha: clear marks by room id
This commit is contained in:
@ -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 {
|
||||
|
@ -12,6 +12,7 @@ type CardMarksRepo interface {
|
||||
CardMarksAdd(ctx context.Context, cm *models.CardMark) error
|
||||
CardMarksRemove(ctx context.Context, cardID uint32, username string) error
|
||||
CardMarksByRoomID(ctx context.Context, roomID string) ([]models.CardMark, error)
|
||||
CardMarksRemoveByRoomID(ctx context.Context, roomID string) error
|
||||
}
|
||||
|
||||
func (r *RepoProvider) CardMarksByCardID(ctx context.Context, cardID uint32) ([]models.CardMark, error) {
|
||||
@ -36,3 +37,8 @@ func (r *RepoProvider) CardMarksByRoomID(ctx context.Context, roomID string) ([]
|
||||
err := sqlx.SelectContext(ctx, getDB(ctx, r.DB), &cardMarks, "SELECT * FROM card_marks WHERE card_id IN (select id from word_cards where room_id = ?)", roomID)
|
||||
return cardMarks, err
|
||||
}
|
||||
func (r *RepoProvider) CardMarksRemoveByRoomID(ctx context.Context, roomID string) error {
|
||||
db := getDB(ctx, r.DB)
|
||||
_, err := db.ExecContext(ctx, "DELETE FROM card_marks WHERE room_id = ?;", roomID)
|
||||
return err
|
||||
}
|
||||
|
2
todos.md
2
todos.md
@ -78,7 +78,7 @@
|
||||
- old cards are still around; +
|
||||
|
||||
- bot mime makes a clue -> no update in the room for players; +
|
||||
- red moves after bot gave (metal - 3) ended after two guesses (showed in logs, that opened 3. double click on the same card? or somewhere counter is not dropped?); the first guess moved counter to 2, in logs only two requests as expected;
|
||||
- red moves after bot gave (metal - 3) ended after two guesses (showed in logs, that opened 3. double click on the same card? or somewhere counter is not dropped?); the first guess moved counter to 2, in logs only two requests as expected; +
|
||||
- bot mime gve a blue -> timer did not start; timer should be in third package, maybe in crons; +
|
||||
- log journal is not shown on the page;
|
||||
- marks did not clear after end of the turn (feature?)
|
||||
|
Reference in New Issue
Block a user