]> www.fi.muni.cz Git - slotcarman.git/blobdiff - SCX/Sound.pm
Sound support
[slotcarman.git] / SCX / Sound.pm
diff --git a/SCX/Sound.pm b/SCX/Sound.pm
new file mode 100644 (file)
index 0000000..5c501c3
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/perl -w
+
+package SCX::Sound;
+
+use strict;
+
+sub new {
+       my ($class, $args) = @_;
+
+       my $self = {
+               data_dir => $args->{data_dir} || './sounds/',
+       };
+
+       bless $self, $class;
+
+       return $self;
+}
+
+sub _play {
+       my ($self, @names) = @_;
+
+       @names = map { $self->{data_dir} . '/' . $_ . '.wav' } @names;
+       system (join(' ', 'aplay', @names). ' &');
+}
+
+sub start { shift->_play('start'); }
+sub filled { shift->_play('filled'); }
+
+sub winner {
+       my ($self, $car_id) = @_;
+
+       $self->_play('winner', $car_id, 'winner');
+}
+
+sub box {
+       my ($self, $car_id) = @_;
+
+       $self->_play('box', $car_id, 'box');
+}
+
+sub best_lap {
+       my ($self, $car_id) = @_;
+
+       $self->_play('bestlap', $car_id);
+}
+
+1;