1 |
root |
1.1 |
#! perl # mandatory |
2 |
|
|
|
3 |
|
|
# this extension provides "environmental effects", |
4 |
|
|
# meaning mostly background music and region messages right now. |
5 |
|
|
|
6 |
root |
1.2 |
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 |
|
|
}; |
32 |
|
|
|
33 |
root |
1.1 |
cf::player->attach ( |
34 |
|
|
on_region_change => sub { |
35 |
|
|
my ($pl, $new, $old) = @_; |
36 |
|
|
|
37 |
|
|
$pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname); |
38 |
root |
1.2 |
|
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; |
47 |
root |
1.1 |
}, |
48 |
|
|
); |
49 |
|
|
|
50 |
|
|
|