]> git.sesse.net Git - remoteglot/commitdiff
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 c8beaa463d5c58f3ae21f7b884c44257cb4d8d83..5c22aff4b9cbbb605d851717e3f70358ebb9f18b 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 0a4366cbf801180b79ab5eef25a1c515bca784fd..f3c02c6ff9cacc60ee15239e1740d720ad635d07 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);