Show result for finished games in title, and in the list of other games.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 22 Mar 2016 17:43:50 +0000 (18:43 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 22 Mar 2016 17:43:50 +0000 (18:43 +0100)
remoteglot.pl
www/js/remoteglot.js

index c8beaa4..5c22aff 100755 (executable)
@@ -309,7 +309,9 @@ sub handle_pgn {
                                push @repretty_moves, $pretty;
                                $pos = $npos;
                        }
-                       $pos->{'result'} = $pgn->result;
+                       if ($pgn->result eq '1-0' || $pgn->result eq '1/2-1/2' || $pgn->result eq '0-1') {
+                               $pos->{'result'} = $pgn->result;
+                       }
                        $pos->{'pretty_history'} = \@repretty_moves;
 
                        extract_clock($pgn, $pos);
@@ -930,13 +932,18 @@ sub output_json {
                                my $white = $other_game_json->{'position'}{'player_w'} // die 'Missing white';
                                my $black = $other_game_json->{'position'}{'player_b'} // die 'Missing black';
 
-                               push @games, {
+                               my $game = {
                                        id => $ref->{'id'},
                                        name => "$white–$black",
                                        url => $ref->{'url'},
                                        hashurl => $ref->{'hash_url'},
-                                       score => $other_game_json->{'score'}
                                };
+                               if (defined($other_game_json->{'position'}{'result'})) {
+                                       $game->{'result'} = $other_game_json->{'position'}{'result'};
+                               } else {
+                                       $game->{'score'} = $other_game_json->{'score'};
+                               }
+                               push @games, $game;
                        };
                        if ($@) {
                                warn "Could not add external game " . $ref->{'json_path'} . ": $@";
index 0a4366c..f3c02c6 100644 (file)
@@ -7,7 +7,7 @@
  * @type {Number}
  * @const
  * @private */
-var SCRIPT_VERSION = 2016032200;
+var SCRIPT_VERSION = 2016032201;
 
 /**
  * The current backend URL.
@@ -48,7 +48,8 @@ var displayed_analysis_data = null;
  *      name: string,
  *      url: string,
  *      id: string,
- *      score: Object
+ *      score: =Object,
+ *      result: =string,
  * }>}
  * @private
  */
@@ -897,7 +898,12 @@ var update_game_list = function(games) {
                        game_span.appendChild(game_a);
                }
 
-               var score = " (" + format_short_score(game['score']) + ")";
+               var score;
+               if (game['result']) {
+                       score = " (" + game['result'] + ")";
+               } else {
+                       score = " (" + format_short_score(game['score']) + ")";
+               }
                game_span.appendChild(document.createTextNode(score));
 
                games_div.appendChild(game_span);
@@ -1028,8 +1034,10 @@ var update_board = function() {
 
        // The <title> contains a very brief headline.
        var title_elems = [];
-       if (data['score']) {
-               title_elems.push(format_short_score(data['score']).replace(/^ /, ""));
+       if (data['position'] && data['position']['result']) {
+               title_elems.push(data['position']['result']);
+       } else if (data['score']) {
+               title_elems.push(format_short_score(data['score']));
        }
        if (last_move !== null) {
                title_elems.push(last_move);