Refactor tutorial progress update logic to prevent overwriting existing progress unless the new phase is greater.

This commit is contained in:
Ilya Groshev
2026-04-15 14:01:43 +03:00
parent b9367c392b
commit 31bf40a744
+6
View File
@@ -29,11 +29,14 @@ func (s *TutorialServiceServer) SetTutorialProgress(ctx context.Context, req *pb
nowMillis := gametime.NowMillis() nowMillis := gametime.NowMillis()
var grants []questflow.RewardGrant var grants []questflow.RewardGrant
user, _ := s.users.UpdateUser(userId, func(user *store.UserState) { user, _ := s.users.UpdateUser(userId, func(user *store.UserState) {
existing, exists := user.Tutorials[req.TutorialType]
if !exists || req.ProgressPhase >= existing.ProgressPhase {
user.Tutorials[req.TutorialType] = store.TutorialProgressState{ user.Tutorials[req.TutorialType] = store.TutorialProgressState{
TutorialType: req.TutorialType, TutorialType: req.TutorialType,
ProgressPhase: req.ProgressPhase, ProgressPhase: req.ProgressPhase,
ChoiceId: req.ChoiceId, ChoiceId: req.ChoiceId,
} }
}
if req.TutorialType == int32(model.TutorialTypeMenuFirst) || if req.TutorialType == int32(model.TutorialTypeMenuFirst) ||
req.TutorialType == int32(model.TutorialTypeMenuSecond) { req.TutorialType == int32(model.TutorialTypeMenuSecond) {
store.EnsureDefaultDeck(user, nowMillis) store.EnsureDefaultDeck(user, nowMillis)
@@ -74,10 +77,13 @@ func (s *TutorialServiceServer) SetTutorialProgressAndReplaceDeck(ctx context.Co
log.Printf("[TutorialService] SetTutorialProgressAndReplaceDeck: type=%d phase=%d deckType=%d deckNumber=%d", req.TutorialType, req.ProgressPhase, req.DeckType, req.UserDeckNumber) log.Printf("[TutorialService] SetTutorialProgressAndReplaceDeck: type=%d phase=%d deckType=%d deckNumber=%d", req.TutorialType, req.ProgressPhase, req.DeckType, req.UserDeckNumber)
userId := currentUserId(ctx, s.users, s.sessions) userId := currentUserId(ctx, s.users, s.sessions)
user, _ := s.users.UpdateUser(userId, func(user *store.UserState) { user, _ := s.users.UpdateUser(userId, func(user *store.UserState) {
existing, exists := user.Tutorials[req.TutorialType]
if !exists || req.ProgressPhase >= existing.ProgressPhase {
user.Tutorials[req.TutorialType] = store.TutorialProgressState{ user.Tutorials[req.TutorialType] = store.TutorialProgressState{
TutorialType: req.TutorialType, TutorialType: req.TutorialType,
ProgressPhase: req.ProgressPhase, ProgressPhase: req.ProgressPhase,
} }
}
if req.Deck != nil { if req.Deck != nil {
store.ApplyDeckReplacement(user, model.DeckType(req.DeckType), req.UserDeckNumber, deckSlotsFromProto(req.Deck), gametime.NowMillis()) store.ApplyDeckReplacement(user, model.DeckType(req.DeckType), req.UserDeckNumber, deckSlotsFromProto(req.Deck), gametime.NowMillis())
} }