use Chess::PGN::Parse;
use EV;
use Net::Telnet;
-use FileHandle;
+use File::Slurp;
use IPC::Open2;
use Time::HiRes;
use JSON::XS;
use URI::Escape;
-use Tie::Persistent;
use DBI;
use DBD::Pg;
require 'Position.pm';
$json->{'score_history'} = \%score_history;
}
+ # Give out a list of other games going on. (Empty is fine.)
+ if (!$historic_json_only) {
+ my @games = ();
+
+ my $q = $dbh->prepare('SELECT * FROM current_games ORDER BY priority DESC, id');
+ $q->execute;
+ while (my $ref = $q->fetchrow_hashref) {
+ eval {
+ my $other_game_contents = File::Slurp::read_file($ref->{'json_path'});
+ my $other_game_json = JSON::XS::decode_json($other_game_contents);
+
+ die "Missing position" if (!exists($other_game_json->{'position'}));
+ my $white = $other_game_json->{'position'}{'player_w'} // die 'Missing white';
+ my $black = $other_game_json->{'position'}{'player_b'} // die 'Missing black';
+
+ push @games, {
+ id => $ref->{'id'},
+ name => "$white–$black",
+ url => $ref->{'url'}
+ };
+ };
+ if ($@) {
+ warn "Could not add external game " . $ref->{'json_path'} . ": $@";
+ }
+ }
+
+ if (scalar @games > 0) {
+ $json->{'games'} = \@games;
+ }
+ }
+
my $json_enc = JSON::XS->new;
$json_enc->canonical(1);
my $encoded = $json_enc->encode($json);
white_clock_target integer, -- FIXME: really timestamp with time zone
black_clock_target integer -- FIXME: really timestamp with time zone
);
+
+CREATE TABLE current_games (
+ id varchar not null primary key,
+ json_path varchar not null,
+ url varchar not null,
+ priority integer not null default 0,
+);
body {
font-family: sans-serif;
}
+h1 {
+ margin-top: 0em;
+}
h3 {
margin-top: 1em;
margin-bottom: 0;
#linenav {
display: none;
}
+
+#games {
+ font-size: smaller;
+ margin-bottom: 0.5em;
+}
+.game {
+ padding: 0.25em 1em 0.25em 1em;
+ margin: 0;
+ background: #eee;
+ border-right: 1px solid #bbb;
+}
+.game:last-of-type {
+ border-right: none;
+}
<source src="ding.opus" type="audio/ogg; codecs=opus" />
<source src="ding.mp3" type="audio/mp3" />
</audio>
+<div id="games">
+</div>
<h1 id="headline">Analysis</h1>
<div id="boardcontainer">
<div id="board"></div>
}
update_history();
+ // Games currently in progress, if any.
+ $("#games").text("");
+ if (current_data['games']) {
+ var games_div = document.getElementById('games');
+ for (var game_num = 0; game_num < current_data['games'].length; ++game_num) {
+ var game = current_data['games'][game_num];
+ var game_span = document.createElement("span");
+ game_span.setAttribute("class", "game");
+
+ var game_name = document.createTextNode(game['name']);
+ if (game['url'] === backend_url) {
+ game_span.appendChild(game_name);
+ } else {
+ var game_a = document.createElement("a");
+ game_a.setAttribute("href", "javascript:switch_backend('" + game['url'] + "')");
+ game_a.appendChild(game_name);
+ game_span.appendChild(game_a);
+ }
+ games_div.appendChild(game_span);
+ }
+ }
+
// The headline. Names are always fetched from current_data;
// the rest can depend a bit.
var headline;