--- deliantra/server/ext/player-env.ext 2007/07/11 15:57:30 1.1 +++ deliantra/server/ext/player-env.ext 2007/07/11 17:09:06 1.3 @@ -3,11 +3,79 @@ # this extension provides "environmental effects", # meaning mostly background music and region messages right now. +sub parse_facelist($$) { + my ($prefix, $list) = @_; + + return undef + unless defined $list; + + #TODO + [sort grep $_, map +(cf::face::find "$prefix$_"), split /\s*,\s*/, $list] +} + +our %MUSIC_QUEUE; + +our $MUSIC_SCHEDULER = cf::async_ext { + while () { + for (keys %MUSIC_QUEUE) { + delete $MUSIC_QUEUE{$_}; + my $pl = cf::player::find_active $_ + or next; + + my $faces; + + my $map = $pl->ob->map + or next; + + # 1. update map-specific music info + unless (exists $map->{music_faces}) { + $map->{music_faces} = parse_facelist "music/", $map->{music}; + } + + my $faces = $map->{music_faces}; + + # 2. fall back to region if no map-specific music + unless ($faces) { + my $rgn = $pl->ob->region + or next; + + unless (exists $rgn->{music_faces}) { + my $par = $rgn; + while () { + last if exists $par->{music}; + $par = $par->parent + or last; + } + + $rgn->{music_faces} = parse_facelist "music/", $par->{music}; + } + + $faces = $rgn->{music_faces}; + } + + warn "music for $pl is @$faces\n" + if $faces; + + cf::cede_to_tick; + } + Coro::schedule unless %MUSIC_QUEUE; + } +}; + cf::player->attach ( on_region_change => sub { my ($pl, $new, $old) = @_; $pl->ob->message ("You are now " . $new->longname . ". H", $new->longname); + + $MUSIC_QUEUE{$pl->ob->name} = undef; + $MUSIC_SCHEDULER->ready; + }, + on_map_change => sub { + my ($pl, $new) = @_; + + $MUSIC_QUEUE{$pl->ob->name} = undef; + $MUSIC_SCHEDULER->ready; }, );