]> www.fi.muni.cz Git - slotcarman.git/blob - SCX/Sound.pm
Sound support
[slotcarman.git] / SCX / Sound.pm
1 #!/usr/bin/perl -w
2
3 package SCX::Sound;
4
5 use strict;
6
7 sub new {
8         my ($class, $args) = @_;
9
10         my $self = {
11                 data_dir => $args->{data_dir} || './sounds/',
12         };
13
14         bless $self, $class;
15
16         return $self;
17 }
18
19 sub _play {
20         my ($self, @names) = @_;
21
22         @names = map { $self->{data_dir} . '/' . $_ . '.wav' } @names;
23         system (join(' ', 'aplay', @names). ' &');
24 }
25
26 sub start { shift->_play('start'); }
27 sub filled { shift->_play('filled'); }
28
29 sub winner {
30         my ($self, $car_id) = @_;
31
32         $self->_play('winner', $car_id, 'winner');
33 }
34
35 sub box {
36         my ($self, $car_id) = @_;
37
38         $self->_play('box', $car_id, 'box');
39 }
40
41 sub best_lap {
42         my ($self, $car_id) = @_;
43
44         $self->_play('bestlap', $car_id);
45 }
46
47 1;