Skip to content

Commit

Permalink
Badges were moved from const to cfg (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-myles authored May 23, 2024
1 parent 878ea1b commit 3524bc0
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 392 deletions.
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,17 @@ linters-settings:
ignore-map-index-ok: true
ignore-chan-recv-ok: true

mnd:
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '24'

linters:
disable:
# TODO remove asap!
Expand Down
57 changes: 29 additions & 28 deletions application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,80 +62,81 @@ friends-invited_test:
<<: *friendsInvitedMessageBroker
consumingTopics: *friendsInvitedMessageBrokerTopics
consumerGroup: santa-local-friends-invited-test

badges: &badges
milestones:
l1:
levels:
- name: Wave Starter
toInclusive: 1
l2:
- name: Beach Walker
fromInclusive: 2
toInclusive: 3
l3:
- name: Rhythm Keeper
fromInclusive: 4
toInclusive: 5
l4:
- name: Dance Captain
fromInclusive: 6
toInclusive: 7
l5:
- name: Vibe Master
fromInclusive: 8
toInclusive: 9
l6:
- name: Festival Guru
fromInclusive: 10
c1:
coins:
- name: Rookie Raver
toInclusive: 10
c2:
- name: Beats Saver
fromInclusive: 20
toInclusive: 30
c3:
- name: Tune Tracker
fromInclusive: 40
toInclusive: 50
c4:
- name: Rhythm Collector
fromInclusive: 60
toInclusive: 70
c5:
- name: Bass Booster
fromInclusive: 80
toInclusive: 90
c6:
- name: Melody Maker
fromInclusive: 100
toInclusive: 110
c7:
- name: Harmony Holder
fromInclusive: 120
toInclusive: 130
c8:
- name: Sound Seeker
fromInclusive: 140
toInclusive: 150
c9:
- name: Vibe Crafter
fromInclusive: 160
toInclusive: 170
c10:
- name: Festival Icon
fromInclusive: 180
s1:
socials:
- name: Meet Greeter
toInclusive: 1
s2:
- name: Friend Finder
fromInclusive: 2
toInclusive: 3
s3:
- name: Party Starter
fromInclusive: 4
toInclusive: 5
s4:
- name: Crowd Mixer
fromInclusive: 6
toInclusive: 7
s5:
- name: Dance Circle King
fromInclusive: 8
toInclusive: 9
s6:
- name: Wave Rider
fromInclusive: 10
toInclusive: 11
s7:
- name: Night Owl
fromInclusive: 12
toInclusive: 13
s8:
- name: Beach Buddy
fromInclusive: 14
toInclusive: 15
s9:
- name: Sunset Chaser
fromInclusive: 16
toInclusive: 17
s10:
- name: Dance Floor Legend
fromInclusive: 18
wintr/connectors/storage/v2:
runDDL: true
Expand Down
56 changes: 29 additions & 27 deletions badges/.testdata/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,80 @@ logger:
encoder: console
level: info
badges: &badges
milestones:
l1:
levels:
- name: Wave Starter
toInclusive: 1
l2:
- name: Beach Walker
fromInclusive: 2
toInclusive: 3
l3:
- name: Rhythm Keeper
fromInclusive: 4
toInclusive: 5
l4:
- name: Dance Captain
fromInclusive: 6
toInclusive: 7
l5:
- name: Vibe Master
fromInclusive: 8
toInclusive: 9
l6:
- name: Festival Guru
fromInclusive: 10
c1:
coins:
- name: Rookie Raver
toInclusive: 10
c2:
- name: Beats Saver
fromInclusive: 20
toInclusive: 30
c3:
- name: Tune Tracker
fromInclusive: 40
toInclusive: 50
c4:
- name: Rhythm Collector
fromInclusive: 60
toInclusive: 70
c5:
- name: Bass Booster
fromInclusive: 80
toInclusive: 90
c6:
- name: Melody Maker
fromInclusive: 100
toInclusive: 110
c7:
- name: Harmony Holder
fromInclusive: 120
toInclusive: 130
c8:
- name: Sound Seeker
fromInclusive: 140
toInclusive: 150
c9:
- name: Vibe Crafter
fromInclusive: 160
toInclusive: 170
c10:
- name: Festival Icon
fromInclusive: 180
s1:
socials:
- name: Meet Greeter
toInclusive: 1
s2:
- name: Friend Finder
fromInclusive: 2
toInclusive: 3
s3:
- name: Party Starter
fromInclusive: 4
toInclusive: 5
s4:
- name: Crowd Mixer
fromInclusive: 6
toInclusive: 7
s5:
- name: Dance Circle King
fromInclusive: 8
toInclusive: 9
s6:
- name: Wave Rider
fromInclusive: 10
toInclusive: 11
s7:
- name: Night Owl
fromInclusive: 12
toInclusive: 13
s8:
- name: Beach Buddy
fromInclusive: 14
toInclusive: 15
s9:
- name: Sunset Chaser
fromInclusive: 16
toInclusive: 17
s10:
- name: Dance Floor Legend
fromInclusive: 18
db: &badgesDatabase
urls:
Expand Down
26 changes: 13 additions & 13 deletions badges/achieve_badges.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func (r *repository) achieveBadges(ctx context.Context, userID string) error { /
pr = new(progress)
pr.UserID = userID
}
if pr.AchievedBadges != nil && len(*pr.AchievedBadges) == len(&AllTypes) {
if pr.AchievedBadges != nil && len(*pr.AchievedBadges) == len(AllTypes) {
return nil
}
achievedBadges := pr.reEvaluateAchievedBadges(r)
achievedBadges := pr.reEvaluateAchievedBadges()
if achievedBadges != nil && pr.AchievedBadges != nil && len(*pr.AchievedBadges) == len(*achievedBadges) {
return nil
}
Expand All @@ -55,7 +55,7 @@ func (r *repository) achieveBadges(ctx context.Context, userID string) error { /
for _, achievedBadge := range *achievedBadges {
achievedBadgesCount[GroupTypeForEachType[achievedBadge]]++
}
newlyAchievedBadges := make([]*AchievedBadge, 0, len(&AllTypes))
newlyAchievedBadges := make([]*AchievedBadge, 0, len(AllTypes))
outer:
for _, achievedBadge := range *achievedBadges {
if pr.AchievedBadges != nil {
Expand Down Expand Up @@ -101,18 +101,18 @@ func (r *repository) achieveBadges(ctx context.Context, userID string) error { /
return nil
}

func (p *progress) reEvaluateAchievedBadges(repo *repository) *users.Enum[Type] { //nolint:funlen,gocognit,revive // .
if p.AchievedBadges != nil && len(*p.AchievedBadges) == len(&AllTypes) {
func (p *progress) reEvaluateAchievedBadges() *users.Enum[Type] { //nolint:funlen,gocognit,revive // .
if p.AchievedBadges != nil && len(*p.AchievedBadges) == len(AllTypes) {
return p.AchievedBadges
}
alreadyAchievedBadges := make(map[Type]any, len(&AllTypes))
alreadyAchievedBadges := make(map[Type]any, len(AllTypes))
if p.AchievedBadges != nil {
for _, badge := range *p.AchievedBadges {
alreadyAchievedBadges[badge] = struct{}{}
}
}
achievedBadges := make(users.Enum[Type], 0, len(&AllTypes))
for _, badgeType := range &AllTypes {
achievedBadges := make(users.Enum[Type], 0, len(AllTypes))
for _, badgeType := range AllTypes {
if _, alreadyAchieved := alreadyAchievedBadges[badgeType]; alreadyAchieved {
achievedBadges = append(achievedBadges, badgeType)

Expand All @@ -121,13 +121,13 @@ func (p *progress) reEvaluateAchievedBadges(repo *repository) *users.Enum[Type]
var achieved bool
switch GroupTypeForEachType[badgeType] {
case LevelGroupType:
achieved = uint64(p.CompletedLevels) >= repo.cfg.Milestones[badgeType].FromInclusive
achieved = uint64(p.CompletedLevels) >= Milestones[badgeType].FromInclusive
case CoinGroupType:
if p.Balance > 0 {
achieved = uint64(p.Balance) >= repo.cfg.Milestones[badgeType].FromInclusive
achieved = uint64(p.Balance) >= Milestones[badgeType].FromInclusive
}
case SocialGroupType:
achieved = uint64(p.FriendsInvited) >= repo.cfg.Milestones[badgeType].FromInclusive
achieved = uint64(p.FriendsInvited) >= Milestones[badgeType].FromInclusive
}
if achieved {
achievedBadges = append(achievedBadges, badgeType)
Expand Down Expand Up @@ -327,7 +327,7 @@ func (s *completedLevelsSource) upsertProgress(ctx context.Context, completedLev
}
pr, err := s.getProgress(ctx, userID, true)
if err != nil && !errors.Is(err, storage.ErrRelationNotFound) ||
(pr != nil && pr.AchievedBadges != nil && (len(*pr.AchievedBadges) == len(&AllTypes))) ||
(pr != nil && pr.AchievedBadges != nil && (len(*pr.AchievedBadges) == len(AllTypes))) ||
(pr != nil && (pr.CompletedLevels == int64(len(&levelsandroles.AllLevelTypes)) || IsBadgeGroupAchieved(pr.AchievedBadges, LevelGroupType))) {
return errors.Wrapf(err, "failed to getProgress for userID:%v", userID)
}
Expand Down Expand Up @@ -376,7 +376,7 @@ func (s *balancesTableSource) upsertProgress(ctx context.Context, balance int64,
pr, err := s.getProgress(ctx, userID, true)
if err != nil && !errors.Is(err, storage.ErrRelationNotFound) ||
(pr != nil && pr.AchievedBadges != nil &&
(balance > pr.Balance && (len(*pr.AchievedBadges) == len(&AllTypes) || IsBadgeGroupAchieved(pr.AchievedBadges, CoinGroupType)))) {
(balance > pr.Balance && (len(*pr.AchievedBadges) == len(AllTypes) || IsBadgeGroupAchieved(pr.AchievedBadges, CoinGroupType)))) {
return errors.Wrapf(err, "failed to getProgress for userID:%v", userID)
}
if pr != nil && pr.Balance == balance {
Expand Down
Loading

0 comments on commit 3524bc0

Please sign in to comment.