Skip to content

Commit 11ad54d

Browse files
feat: add support for new highscore categories (#563)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 32a6caa commit 11ad54d

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/validation/highscore.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
var (
99
// validHighscoreCatregories stores all valid highscore categories
10-
validHighscoreCategories = []string{"achievements", "achievement", "axe", "axefighting", "charm", "charms", "charmpoints", "charmspoints", "club", "clubfighting", "distance", "distancefighting", "fishing", "fist", "fistfighting", "goshnar", "goshnars", "goshnarstaint", "loyalty", "loyaltypoints", "magic", "mlvl", "magiclevel", "shielding", "shield", "sword", "swordfighting", "drome", "dromescore", "experience", "boss", "bosses", "bosspoints"}
10+
validHighscoreCategories = []string{"achievements", "achievement", "axe", "axefighting", "charm", "charms", "charmpoints", "charmspoints", "club", "clubfighting", "distance", "distancefighting", "fishing", "fist", "fistfighting", "goshnar", "goshnars", "goshnarstaint", "loyalty", "loyaltypoints", "magic", "mlvl", "magiclevel", "shielding", "shield", "sword", "swordfighting", "drome", "dromescore", "experience", "boss", "bosses", "bosspoints", "bountypoints", "bountypoint", "bountypointsearned", "weeklytasks", "weeklytask", "weeklytaskscompleted"}
1111
)
1212

1313
// IsHighscoreCategoryValid reports wheter the provided string represents a valid highscore category
@@ -40,11 +40,13 @@ const (
4040
HighScoreSwordfighting
4141
HighScoreDromescore
4242
HighScoreBosspoints
43+
HighScoreBountypoints
44+
HighScoreWeeklytasks
4345
)
4446

4547
func (hc HighscoreCategory) String() (string, error) {
46-
seasons := [...]string{"achievements", "axefighting", "charmpoints", "clubfighting", "distancefighting", "experience", "fishing", "fistfighting", "goshnarstaint", "loyaltypoints", "magiclevel", "shielding", "swordfighting", "dromescore", "bosspoints"}
47-
if hc < HighScoreAchievements || hc > HighScoreBosspoints {
48+
seasons := [...]string{"achievements", "axefighting", "charmpoints", "clubfighting", "distancefighting", "experience", "fishing", "fistfighting", "goshnarstaint", "loyaltypoints", "magiclevel", "shielding", "swordfighting", "dromescore", "bosspoints", "bountypoints", "weeklytasks"}
49+
if hc < HighScoreAchievements || hc > HighScoreWeeklytasks {
4850
return "", errors.New("invalid HighscoreCategory value")
4951
}
5052
return seasons[hc-1], nil
@@ -82,6 +84,10 @@ func HighscoreCategoryFromString(input string) HighscoreCategory {
8284
return HighScoreDromescore
8385
case "boss", "bosses", "bosspoints":
8486
return HighScoreBosspoints
87+
case "bountypoints", "bountypoint", "bountypointsearned":
88+
return HighScoreBountypoints
89+
case "weeklytasks", "weeklytask", "weeklytaskscompleted":
90+
return HighScoreWeeklytasks
8591
default:
8692
return HighScoreExperience
8793
}

src/validation/highscore_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ func TestHighscoreCategoryBosspointsString(t *testing.T) {
4949
assert.Equal(HighscoreCategory(15), highscoreCategory)
5050
}
5151

52+
func TestHighscoreCategoryBountypointsString(t *testing.T) {
53+
assert := assert.New(t)
54+
highscoreCategory := HighScoreBountypoints
55+
stringValue, err := highscoreCategory.String()
56+
57+
assert.Nil(err)
58+
assert.Equal("bountypoints", stringValue)
59+
assert.Equal(HighscoreCategory(16), highscoreCategory)
60+
}
61+
62+
func TestHighscoreCategoryWeeklytasksString(t *testing.T) {
63+
assert := assert.New(t)
64+
highscoreCategory := HighScoreWeeklytasks
65+
stringValue, err := highscoreCategory.String()
66+
67+
assert.Nil(err)
68+
assert.Equal("weeklytasks", stringValue)
69+
assert.Equal(HighscoreCategory(17), highscoreCategory)
70+
}
71+
5272
func TestHighscoreCategoryInvalidValueString(t *testing.T) {
5373
assert := assert.New(t)
5474

@@ -125,6 +145,14 @@ func TestHighscoreCategoryFromString(t *testing.T) {
125145
inputs: []string{"boss", "bosses", "bosspoints"},
126146
expected: HighScoreBosspoints,
127147
},
148+
"Bountypoints": {
149+
inputs: []string{"bountypoints", "bountypoint", "bountypointsearned"},
150+
expected: HighscoreBountypoints,
151+
},
152+
"Weeklytasks": {
153+
inputs: []string{"weeklytasks", "weeklytask", "weeklytaskscompleted"},
154+
expected: HighscoreWeeklytasks,
155+
},
128156
}
129157

130158
for category, data := range categoryTests {

src/webserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func tibiaGuildsOverview(c *gin.Context) {
499499
// @Accept json
500500
// @Produce json
501501
// @Param world path string true "The world" default(all) extensions(x-example=Antica)
502-
// @Param category path string true "The category" default(experience) Enums(achievements, axefighting, charmpoints, clubfighting, distancefighting, experience, fishing, fistfighting, goshnarstaint, loyaltypoints, magiclevel, shielding, swordfighting, dromescore, bosspoints) extensions(x-example=fishing)
502+
// @Param category path string true "The category" default(experience) Enums(achievements, axefighting, charmpoints, clubfighting, distancefighting, experience, fishing, fistfighting, goshnarstaint, loyaltypoints, magiclevel, shielding, swordfighting, dromescore, bosspoints, bountypoints, weeklytasks) extensions(x-example=fishing)
503503
// @Param vocation path string true "The vocation" default(all) Enums(all, knights, paladins, sorcerers, druids, monks) extensions(x-example=all)
504504
// @Param page path int true "The current page" default(1) minimum(1) extensions(x-example=1)
505505
// @Success 200 {object} HighscoresResponse

0 commit comments

Comments
 (0)