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.3 |
sub parse_facelist($$) { |
7 |
|
|
my ($prefix, $list) = @_; |
8 |
|
|
|
9 |
|
|
return undef |
10 |
|
|
unless defined $list; |
11 |
|
|
|
12 |
|
|
#TODO |
13 |
|
|
[sort grep $_, map +(cf::face::find "$prefix$_"), split /\s*,\s*/, $list] |
14 |
|
|
} |
15 |
|
|
|
16 |
root |
1.2 |
our %MUSIC_QUEUE; |
17 |
|
|
|
18 |
|
|
our $MUSIC_SCHEDULER = cf::async_ext { |
19 |
|
|
while () { |
20 |
|
|
for (keys %MUSIC_QUEUE) { |
21 |
|
|
delete $MUSIC_QUEUE{$_}; |
22 |
|
|
my $pl = cf::player::find_active $_ |
23 |
|
|
or next; |
24 |
|
|
|
25 |
root |
1.3 |
my $faces; |
26 |
|
|
|
27 |
root |
1.2 |
my $map = $pl->ob->map |
28 |
|
|
or next; |
29 |
|
|
|
30 |
|
|
# 1. update map-specific music info |
31 |
root |
1.3 |
unless (exists $map->{music_faces}) { |
32 |
|
|
$map->{music_faces} = parse_facelist "music/", $map->{music}; |
33 |
|
|
} |
34 |
root |
1.2 |
|
35 |
root |
1.3 |
my $faces = $map->{music_faces}; |
36 |
root |
1.2 |
|
37 |
|
|
# 2. fall back to region if no map-specific music |
38 |
root |
1.3 |
unless ($faces) { |
39 |
|
|
my $rgn = $pl->ob->region |
40 |
|
|
or next; |
41 |
|
|
|
42 |
|
|
unless (exists $rgn->{music_faces}) { |
43 |
|
|
my $par = $rgn; |
44 |
|
|
while () { |
45 |
|
|
last if exists $par->{music}; |
46 |
|
|
$par = $par->parent |
47 |
|
|
or last; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
$rgn->{music_faces} = parse_facelist "music/", $par->{music}; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
$faces = $rgn->{music_faces}; |
54 |
root |
1.2 |
} |
55 |
|
|
|
56 |
root |
1.3 |
warn "music for $pl is @$faces\n" |
57 |
|
|
if $faces; |
58 |
|
|
|
59 |
root |
1.2 |
cf::cede_to_tick; |
60 |
|
|
} |
61 |
|
|
Coro::schedule unless %MUSIC_QUEUE; |
62 |
|
|
} |
63 |
|
|
}; |
64 |
|
|
|
65 |
root |
1.1 |
cf::player->attach ( |
66 |
|
|
on_region_change => sub { |
67 |
|
|
my ($pl, $new, $old) = @_; |
68 |
|
|
|
69 |
|
|
$pl->ob->message ("You are now " . $new->longname . ". H<Use whereami for more details.>", $new->longname); |
70 |
root |
1.2 |
|
71 |
|
|
$MUSIC_QUEUE{$pl->ob->name} = undef; |
72 |
|
|
$MUSIC_SCHEDULER->ready; |
73 |
|
|
}, |
74 |
|
|
on_map_change => sub { |
75 |
|
|
my ($pl, $new) = @_; |
76 |
|
|
|
77 |
|
|
$MUSIC_QUEUE{$pl->ob->name} = undef; |
78 |
|
|
$MUSIC_SCHEDULER->ready; |
79 |
root |
1.1 |
}, |
80 |
|
|
); |
81 |
|
|
|
82 |
|
|
|