]> www.fi.muni.cz Git - slotcarman.git/blob - SCX/Sound.pm
Sound: joined sound files
[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                 muted => 1,
13         };
14
15         bless $self, $class;
16
17         return $self;
18 }
19
20 sub _play {
21         my ($self, @names) = @_;
22
23         return if $self->{muted};
24
25         system 'aplay', $self->{data_dir} . '/' . join('-', @names) . '.wav';
26 }
27
28 sub mute { shift->{muted} = 1; }
29 sub unmute { shift->{muted} = 0; }
30
31 sub start { shift->_play('start'); }
32 sub filled { shift->_play('filled'); }
33
34 sub winner {
35         my ($self, $car_id) = @_;
36
37         $self->_play('winner', $car_id);
38 }
39
40 sub box {
41         my ($self, $car_id) = @_;
42
43         $self->_play('box', $car_id);
44 }
45
46 sub best_lap {
47         my ($self, $car_id) = @_;
48
49         $self->_play('bestlap', $car_id);
50 }
51
52 1;