]> www.fi.muni.cz Git - slotcarman.git/blobdiff - gui.pl
My own defaults in gui.pl
[slotcarman.git] / gui.pl
diff --git a/gui.pl b/gui.pl
index 8a00f244e431475dde98e9fe407c90da46ee1b4f..0efe3f30da91ee6c46ad0376b56454013893989b 100755 (executable)
--- a/gui.pl
+++ b/gui.pl
@@ -9,20 +9,84 @@ use Glib qw(TRUE FALSE);
 use SCX::GUI;
 use SCX::Track;
 use SCX::Reader;
+use SCX::RaceParser;
 
-my $no_reader = 0;
-
-my $gui = SCX::GUI->new;
+my $gui = SCX::GUI->new({ img_height => 100 });
 my $track = SCX::Track->new({ gui => $gui });
 
-if (!$no_reader) {
-       my $reader = SCX::Reader->new({
-               portname   => '/dev/ttyUSB0',
-               logfile    => 'log',
-               track      => $track,
+my $logfile = 'log';
+my $tty = '/dev/ttyUSB0';
+
+if (defined $ARGV[0] && $ARGV[0] eq '-') {
+       $logfile = undef;
+       $tty = '-';
+}
+
+my $parser = SCX::RaceParser->new({
+       track => $track,
+       logfile => $logfile,
+});
+
+my $reader = eval {
+       SCX::Reader->new({
+               filename   => $tty,
+               parser     => $parser,
        });
+};
+
+if ($@) {
+       print STDERR "Demo mode only: $@";
+}
+
+$track->car(0)->set_model('F1 Ferrari');
+$track->car(1)->set_model('F1 McLaren');
+#$track->car(2)->set_model('F1 Williams');
+$track->car(2)->set_model('Citroen Xsara');
+$track->car(3)->set_model('Chevrolet Corvette gelb');
+$track->car(4)->set_model('Ferrari 360 Red Bull');
+$track->car(5)->set_model('Ferrari 360 Cric Crac');
 
+$track->car(0)->set_driver('Ferrari');
+$track->car(1)->set_driver('McLaren');
+$track->car(2)->set_driver('Xsara');
+
+if ($reader) {
        Glib::IO->add_watch(fileno($reader->fh), 'in', \&scx_read, $reader);
+} else {
+       # Just display some random values
+
+       $gui->rounds('5/13');
+       $gui->time('53.4');
+       $gui->best_lap('12.3');
+
+       my $now = time;
+       $track->{race_running_since} = $now;
+       $track->{race_running} = 1;
+
+       $track->finish_line($now + 0.5, 1, 2);
+       $track->finish_line($now + 0.7, 1, 1);
+       $track->finish_line($now + 4.9, 1, 1);
+       $track->finish_line($now + 5.3, 1, 2);
+       $track->finish_line($now + 7.2, 1, 1);
+       $track->finish_line($now + 8.1, 0, 2);
+#      $track->car(0)->set_lap(13);
+#      $track->car(1)->set_lap(11);
+#      $track->car(2)->set_lap(10);
+#      $track->car(3)->set_lap(undef);
+#      $track->car(4)->set_lap(undef);
+#      $track->car(5)->set_lap(undef);
+
+       $track->car(0)->set_laptime(9.12322);
+       $track->car(1)->set_laptime(15.313);
+       $track->car(2)->set_laptime(5.989);
+
+       $track->car(0)->set_fuel(6);
+       $track->car(1)->set_fuel(2);
+       $track->car(2)->set_fuel(8);
+
+       $track->car(0)->set_throttle(0);
+       $track->car(1)->set_throttle(8, 1);
+       $track->car(2)->set_throttle(12);
 }
 
 $gui->show;