Skip to content

Commit 2900746

Browse files
authored
Merge pull request #256 from fraz3alpha/tonsofruns2
show progress when no ton badges awarded yet
2 parents 121473f + c647f96 commit 2900746

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

browser-extensions/common/js/lib/challenges.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ function challenge_stopwatch_bingo(data, params) {
19251925
return update_data_object(o)
19261926
}
19271927

1928-
// Complete 100 or 200 parkruns at the same venue
1928+
// Complete 100 or 200 parkruns at the same venue - tons of runs challenge
19291929
function challenge_single_parkrun_count(data, params) {
19301930

19311931
var parkrun_results = data.parkrun_results
@@ -1939,7 +1939,7 @@ function challenge_single_parkrun_count(data, params) {
19391939

19401940
parkruns_completed = {}
19411941
max_count = 0
1942-
max_parkrun = null
1942+
max_parkrun = undefined
19431943

19441944
parkrun_results.forEach(function (parkrun_event) {
19451945
if (!(parkrun_event.name in parkruns_completed)) {
@@ -1951,8 +1951,20 @@ function challenge_single_parkrun_count(data, params) {
19511951
}
19521952
}
19531953
parkruns_completed[parkrun_event.name].count += 1
1954+
1955+
// Identify which parkrun event is most attended
1956+
// so that we can print progress towards the badge
1957+
// if haven't already got one
1958+
if (parkruns_completed[parkrun_event.name].count > max_count) {
1959+
//console.log(parkruns_completed[parkrun_event.name])
1960+
max_parkrun = Object.create(parkruns_completed[parkrun_event.name])
1961+
max_count = parkruns_completed[parkrun_event.name].count
1962+
//console.log("max_count: "+max_count+" "+JSON.stringify(parkruns_completed[parkrun_event.name]))
1963+
}
1964+
//console.log(max_parkrun)
19541965
})
19551966

1967+
19561968
// Now we have an object showing how many times each
19571969
// parkrun has been completed
19581970

@@ -1963,12 +1975,14 @@ function challenge_single_parkrun_count(data, params) {
19631975
"awarded": false
19641976
})
19651977
})
1966-
console.log("parkruns completed: " + parkruns_completed)
1978+
console.log("parkruns completed: " + parkruns_completed)
19671979
// Now look at which completed parkruns have reached
19681980
// the 'ton' milestones
19691981
Object.keys(parkruns_completed).sort().forEach(function (name) {
19701982
var currentBadge = undefined
1971-
$.each(stages, function(index, tonMilestone) {
1983+
for(var index = 0; index < stages.length; index++){
1984+
var tonMilestone = stages[index]
1985+
//$.each(stages, function(index, tonMilestone) {
19721986
if (parkruns_completed[name].count >= tonMilestone.count) {
19731987
currentBadge = {
19741988
"index": index,
@@ -1977,7 +1991,7 @@ console.log("parkruns completed: " + parkruns_completed)
19771991
"badge_icon": tonMilestone.badge_icon
19781992
}
19791993
}
1980-
})
1994+
}
19811995
if (currentBadge !== undefined) {
19821996
// Award a badge for this parkrun event
19831997
o.subparts_detail.push({
@@ -2006,9 +2020,18 @@ console.log("parkruns completed: " + parkruns_completed)
20062020
})
20072021
}
20082022
})
2009-
20102023
o.badgesAwarded = badgesAwarded
20112024

2025+
if (max_parkrun !== undefined){
2026+
if (badgesAwarded.length == 0) {
2027+
o.subparts_detail.push({
2028+
"name": max_parkrun.name,
2029+
"info": max_count,
2030+
"subpart": "Highest so far"
2031+
})
2032+
}
2033+
}
2034+
20122035
// Display the badges above what the parkrunner has, so they can see
20132036
// what is still to come. i.e. if they have nothing, show all badges,
20142037
// if they have 100, show 200, if they already have 200
@@ -2023,17 +2046,6 @@ console.log("parkruns completed: " + parkruns_completed)
20232046
})
20242047
console.log("parkrunner has achieved max ton level of " + maxBadgeAwarded)
20252048

2026-
/*
2027-
// Identify which parkrun event is most attended
2028-
// so that we can print progress towards the badge
2029-
// if haven't already got one
2030-
if (parkruns_completed[parkrun_event.name].count > max_count) {
2031-
max_parkrun = Object.create(parkruns_completed[parkrun_event.name])
2032-
max_count = parkruns_completed[parkrun_event.name].count
2033-
}
2034-
*/
2035-
2036-
20372049
// Add the badge for any higher badges than the ones they have
20382050
$.each(stages, function(index, tonMilestone) {
20392051
if (index > maxBadgeAwarded) {

0 commit comments

Comments
 (0)