1 | #! perl # mandatory |
1 | #! perl # mandatory |
2 | |
2 | |
3 | # this extension provides "environmental effects", |
3 | # this extension provides "environmental effects", |
4 | # meaning mostly background music and region messages right now. |
4 | # meaning mostly background music and region messages right now. |
|
|
5 | |
|
|
6 | our %MUSIC_QUEUE; |
|
|
7 | |
|
|
8 | our $MUSIC_SCHEDULER = cf::async_ext { |
|
|
9 | while () { |
|
|
10 | for (keys %MUSIC_QUEUE) { |
|
|
11 | delete $MUSIC_QUEUE{$_}; |
|
|
12 | my $pl = cf::player::find_active $_ |
|
|
13 | or next; |
|
|
14 | |
|
|
15 | my $map = $pl->ob->map |
|
|
16 | or next; |
|
|
17 | |
|
|
18 | # 1. update map-specific music info |
|
|
19 | unless (exists $map->{music}) { |
|
|
20 | |
|
|
21 | } |
|
|
22 | |
|
|
23 | # 2. fall back to region if no map-specific music |
|
|
24 | unless ($map->{music}) { |
|
|
25 | } |
|
|
26 | |
|
|
27 | cf::cede_to_tick; |
|
|
28 | } |
|
|
29 | Coro::schedule unless %MUSIC_QUEUE; |
|
|
30 | } |
|
|
31 | }; |
5 | |
32 | |
6 | cf::player->attach ( |
33 | cf::player->attach ( |
7 | on_region_change => sub { |
34 | on_region_change => sub { |
8 | my ($pl, $new, $old) = @_; |
35 | my ($pl, $new, $old) = @_; |
9 | |
36 | |
10 | $pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname); |
37 | $pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname); |
|
|
38 | |
|
|
39 | $MUSIC_QUEUE{$pl->ob->name} = undef; |
|
|
40 | $MUSIC_SCHEDULER->ready; |
|
|
41 | }, |
|
|
42 | on_map_change => sub { |
|
|
43 | my ($pl, $new) = @_; |
|
|
44 | |
|
|
45 | $MUSIC_QUEUE{$pl->ob->name} = undef; |
|
|
46 | $MUSIC_SCHEDULER->ready; |
11 | }, |
47 | }, |
12 | ); |
48 | ); |
13 | |
49 | |
14 | |
50 | |