]> git.sesse.net Git - ultimatescore/blobdiff - carousel.js
Fix an issue where newer browsers would squeeze the secondary scorebugs.
[ultimatescore] / carousel.js
index f8f2f8c69728e54f9a820f3c29d84be01fd5e3d6..109f21a72f684c2c6cb68ed6ba81e162b73815eb 100644 (file)
@@ -1,12 +1,17 @@
 'use strict';
 
+function jsonclone(x)
+{
+       return JSON.parse(JSON.stringify(x));
+}
+
 // Log with deep clone, so that the browser will show the object at time of log,
 // instead of what it looks like at time of view.
 function dlog()
 {
        let args = [];
        for (const arg of arguments) {
-               args.push(JSON.parse(JSON.stringify(arg)));
+               args.push(jsonclone(arg));
        }
        console.log(args);
 }
@@ -404,9 +409,21 @@ function parse_games_from_spreadsheet(response, group_name, include_unplayed) {
        return games;
 };
 
-function apply_games_to_teams(games, teams)
+function apply_games_to_teams(games, teams, ignored_teams, ret_ignored_games)
 {
        let teams_to_idx = make_teams_to_idx(teams);
+       let ignored_teams_idx;
+       if (ignored_teams === undefined) {
+               ignored_teams_idx = [];
+       } else {
+               ignored_teams_idx = make_teams_to_idx(ignored_teams);
+       }
+       for (let i = 0; i < teams.length; ++i) {
+               teams[i].nplayed = 0;
+               teams[i].goals = 0;
+               teams[i].gd = 0;
+               teams[i].pts = 0;
+       }
        for (let i = 0; i < games.length; ++i) {
                let idx1 = teams_to_idx[games[i].name1];
                let idx2 = teams_to_idx[games[i].name2];
@@ -416,6 +433,23 @@ function apply_games_to_teams(games, teams)
                    games[i].score1 == games[i].score2) {
                        continue;
                }
+
+               let ignored_idx1 = ignored_teams_idx[games[i].name1];
+               let ignored_idx2 = ignored_teams_idx[games[i].name2];
+               if (ignored_idx1 !== undefined || ignored_idx2 !== undefined) {
+                       if (ret_ignored_games !== undefined) {
+                               // Figure out whether the fifth we're ignoring was only picked out arbitrarily
+                               // (ie., there's a tie for 5th); if so, mark it as such.
+                               let arbitrary = false;
+                               if (ignored_idx1 !== undefined && ignored_teams[ignored_idx1].rank < 5) {
+                                       arbitrary = true;
+                               } else if (ignored_idx2 !== undefined && ignored_teams[ignored_idx2].rank < 5) {
+                                       arbitrary = true;
+                               }
+                               ret_ignored_games.push([teams[idx1].shortname, teams[idx2].shortname, arbitrary]);
+                       }
+                       continue;
+               }
                ++teams[idx1].nplayed;
                ++teams[idx2].nplayed;
                teams[idx1].goals += games[i].score1;
@@ -683,7 +717,14 @@ function showschedule(page)
 {
        let teams = [];
        let games = [];
-       let num_left = 5;
+       let groups_to_get = [
+               'Group A',
+               'Group B',
+               // 'Group C',
+               // 'Playoffs 9th-13th',
+               'Playoffs'
+       ];
+       let num_left = groups_to_get.length;
 
        let cb = function(response, group_name) {
                teams = teams.concat(parse_teams_from_spreadsheet(response));
@@ -693,11 +734,9 @@ function showschedule(page)
                }
        };
 
-       get_group('Group A', cb);
-       get_group('Group B', cb);
-       get_group('Group C', cb);
-       get_group('Playoffs', cb);
-       get_group('Playoffs 9th-13th', cb);
+       for (const group of groups_to_get) {
+               get_group(group, cb);
+       }
 };
 
 function do_series(series)
@@ -719,7 +758,14 @@ function showcarousel()
        let games_per_group = [];
        let combined_teams = [];
        let combined_games = [];
-       let num_left = 5;
+       let groups_to_get = [
+               'Group A',
+               'Group B',
+               // 'Group C',
+               // 'Playoffs 9th-13th',
+               'Playoffs'
+       ];
+       let num_left = groups_to_get.length;
 
        let cb = function(response, group_name) {
                let teams = parse_teams_from_spreadsheet(response);
@@ -735,10 +781,6 @@ function showcarousel()
                                [ 13000, function() { display_group_parsed(teams_per_group['Group A'], games_per_group['Group A'], 'Group A'); } ],
                                [ 2000, function() { hidetable(); } ],
                                [ 13000, function() { display_group_parsed(teams_per_group['Group B'], games_per_group['Group B'], 'Group B'); } ],
-                               [ 2000, function() { hidetable(); } ],
-                               [ 13000, function() { display_group_parsed(teams_per_group['Group C'], games_per_group['Group C'], 'Group C'); } ],
-                               [ 2000, function() { hidetable(); } ],
-                               [ 13000, function() { display_group_parsed(teams_per_group['Playoffs 9th-13th'], games_per_group['Playoffs 9th-13th'], 'Playoffs 9th–13th'); } ],
                                [ 2000, function() { hidetable(); } ]
                        ];
                        let num_pages = find_num_pages(combined_games);
@@ -751,11 +793,9 @@ function showcarousel()
                }
        };
 
-       get_group('Group A', cb);
-       get_group('Group B', cb);
-       get_group('Group C', cb);
-       get_group('Playoffs 9th-13th', cb);
-       get_group('Playoffs', cb);
+       for (const group of groups_to_get) {
+               get_group(group, cb);
+       }
 };
 
 function stopcarousel()