Squashed commit of the following:
[xonotic/xonotic-maps.pk3dir.git] / maps / desertfactory.bgs-maker.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my $dt = 0.5;
7 my $pattern = '';
8 my $time = 0;
9 my $staccato = 0.25;
10 my @script = ();
11
12 while(<DATA>)
13 {
14         chomp;
15         my (@arg) = split /\s+/, $_;
16         if($arg[0] eq 'time')
17         {
18                 $time = $arg[1];
19         }
20         elsif($arg[0] eq 'bpm')
21         {
22                 $dt = 60.0 / $arg[1];
23         }
24         elsif($arg[0] eq 'pattern')
25         {
26                 $pattern = $arg[1];
27         }
28         elsif($arg[0] eq 'range')
29         {
30                 my ($begin, $end) = ($arg[1], $arg[2]);
31                 my $n = $end - $begin;
32                 for(0..($n - 1))
33                 {
34                         my $char = substr $pattern, ($_ % length $pattern), 1;
35                         push @script, [$char, $time, 1], [$char, $time + $dt * (1 - $staccato), 0]
36                                 unless $char eq '_';
37                         $time += $dt;
38                 }
39         }
40 }
41
42 for(sort { $a->[0] cmp $b->[0] or $a->[1] <=> $b->[1] } @script)
43 {
44         printf "%s %f %d\n", @$_;
45 }
46
47 __DATA__
48 time           0.200
49 bpm            254
50 pattern        aaa_____aaa_____
51 range          0 32
52 pattern        aaa_b__caaa_bccc
53 range          32 160
54 pattern        aaa_b__caaa_b__c
55 range          160 272
56 pattern        aaa_b__caaa_b_bb
57 range          272 288
58 pattern        abc_c_c_c_c_c_c_
59 range          288 352
60 pattern        aaa_b__caaa_bccc
61 range          352 480
62 pattern        aaa_b__caaa_b__c
63 range          480 592
64 pattern        aaa_b__caaa_b_bb
65 range          592 608
66 pattern        aaa_b__caaa_b__c
67 range          608 656
68 pattern        aaa_b__caaa_b_bb
69 range          656 672
70 pattern        aaa_b__caaa_b__c
71 range          672 720
72 pattern        aaa_b__caaa_b_bb
73 range          720 736
74 pattern        aaa_b__caaa_b__c
75 range          736 864
76 pattern        a_______________
77 range          864 865