]> www.fi.muni.cz Git - slotcarman.git/blobdiff - SCX/Track.pm
Sound support
[slotcarman.git] / SCX / Track.pm
index f561f2a955b7a72afca109294c3f4f3be44ac3f4..90724290bc5252bd2bb7b897486d7ec23d3ef72c 100644 (file)
@@ -7,6 +7,7 @@ use Carp;
 
 use Glib qw(TRUE FALSE);
 use SCX::Car;
+use SCX::Sound;
 
 our $SEMAPHORE_STEP = 1000;
 
@@ -37,6 +38,8 @@ sub new {
        $self->{gui}->time(undef);
        $self->{gui}->best_lap(undef, undef);
 
+       $self->{sound} = new SCX::Sound;
+
        return $self;
 }
 
@@ -87,6 +90,7 @@ sub semaphore_step {
        } else {
                $self->{gui}->show_semaphore(undef);
                $self->{semaphore} = undef;
+               $self->{sound}->start();
        }
        return FALSE;
 }
@@ -115,31 +119,13 @@ sub race_setup {
        $self->{best_lap} = undef;
 
        $self->{gui}->show_semaphore(undef);
-       $self->{race_running} = 0;
-       $self->{qualification_running} = 0;
-       $self->{start_in_progress} = 0;
-
-       $self->{gui}->time(undef);
-       $self->{gui}->best_lap(undef);
-
-       for my $car (0..5) {
-               $self->car($car)->reset;
-       }
-}
-
-sub reset {
-       my ($self) = @_;
-
        $self->{race_running} = 0;
        $self->{qualification_running} = 0;
        $self->{start_in_progress} = 0;
        $self->{race_finishing} = 0;
-       $self->{best_lap} = undef;
-       $self->{round} = 0;
 
-       $self->print_rounds;
-       $self->{gui}->best_lap(undef);
        $self->{gui}->time(undef);
+       $self->{gui}->best_lap(undef);
 
        for my $car (0..5) {
                $self->car($car)->reset;
@@ -163,8 +149,8 @@ sub print_rounds {
        $self->{gui}->rounds($msg);
 }
 
-sub check_best_lap {
-       my ($self, $time, $who) = @_;
+sub notify_best_lap {
+       my ($self, $id, $time, $who) = @_;
 
        return if !defined $time || $time == 0;
 
@@ -175,6 +161,16 @@ sub check_best_lap {
                || $time < $self->{best_lap}) {
                $self->{best_lap} = $time;
                $self->{gui}->best_lap($time, $who);
+
+               for my $car (0..5) {
+                       $self->car($car)->set_global_best($car == $id);
+                       $self->car($car)->print_best_lap;
+               }
+
+               if (!$self->{race_running} || $self->{round} > 1) {
+                       # skip the first round in the race
+                       $self->{sound}->best_lap($id);
+               }
                return 1;
        }
        return 0;
@@ -239,6 +235,9 @@ sub recalc_order {
 
        if ($self->{round} && $self->{race_rounds}
                && $self->{round} > $self->{race_rounds}) {
+               if (!$self->{race_finishing}) {
+                       $self->{sound}->winner($new_order[0]);
+               }
                $self->{race_finishing} = 1;
        }