--- deliantra/server/ext/player-env.ext 2007/07/11 15:57:30 1.1 +++ deliantra/server/ext/player-env.ext 2007/07/11 16:26:26 1.2 @@ -3,11 +3,47 @@ # this extension provides "environmental effects", # meaning mostly background music and region messages right now. +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 $map = $pl->ob->map + or next; + + # 1. update map-specific music info + unless (exists $map->{music}) { + + } + + # 2. fall back to region if no map-specific music + unless ($map->{music}) { + } + + 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; }, );