From 2af1804bc17688984c743ea1640b03cc9bf51303 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Wed, 27 Jan 2016 08:25:58 -0500 Subject: [PATCH] Highlight double bonus. --- entry.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/entry.js b/entry.js index 4247970..63a4c54 100644 --- a/entry.js +++ b/entry.js @@ -258,7 +258,7 @@ function display_when(condition, value) { /* Calculate bonus time. */ function calculate_bonus(laps, start_time, allotted_time, table) { - if (! joker()) return 0; + if (! joker()) return [0, false]; var time = 0; var hull_start = 0; var hull_end = 0; @@ -291,8 +291,7 @@ function calculate_bonus(laps, start_time, allotted_time, table) { else race_ineligible = true; } /* Double bonus if no repairs at all. */ - if (! race_ineligible) time *= 2; - return time; + return [time, ! race_ineligible]; } /* Calculate penalty time. */ @@ -463,7 +462,9 @@ function do_stats(table) { var start_time = from_iso8601(real_date(get_cell_input(first_row(table), first_column(table)).value)); var finish_time = from_iso8601(real_date(get_cell_input(last_station, last_lap).value)); var raced_time = finish_time - start_time; - var bonus_time = calculate_bonus(complete_laps, start_time, allotted_time, table); + var bonus_details = calculate_bonus(complete_laps, start_time, allotted_time, table); + var earned_bonus_time = bonus_details[0]; + var bonus_time = earned_bonus_time * (bonus_details[1] ? 2 : 1); if (allotted_time && raced_time > allotted_time + bonus_time) { /* Get stations past the deadline. */ var extras = []; @@ -522,7 +523,9 @@ function do_stats(table) { do_stat('total_distance', format_distance(total_distance, false), display_when(total_distance, format_distance(total_distance))); /* Times. */ do_stat('allotted_time', available_time, display_when(time_limited(), format_time(available_time))); - do_stat('bonus_time', bonus_time, display_when(joker(), format_time(bonus_time))); + var bonus_string = format_time(bonus_time); + if (bonus_details[1]) bonus_string += ' (' + format_time(earned_bonus_time) + ')'; + do_stat('bonus_time', bonus_time, display_when(joker(), bonus_string)); do_stat('penalty_time', penalty_time, display_when(time_limited(), format_time(penalty_time))); do_stat('raced_time', finish_time - start_time, display_when(time_limited() || joker(), format_difference(finish_time, start_time))); do_stat('total_time', total_time, format_time(total_time)); -- 2.7.4