… | |
… | |
21 | |
21 | |
22 | my $self = $class->SUPER::new (%arg, |
22 | my $self = $class->SUPER::new (%arg, |
23 | setup_req => { |
23 | setup_req => { |
24 | extmap => 1, |
24 | extmap => 1, |
25 | excmd => 1, |
25 | excmd => 1, |
26 | xwidget => 1, |
26 | ywidget => 1, |
27 | %{$arg{setup_req} || {}}, |
27 | %{$arg{setup_req} || {}}, |
28 | }, |
28 | }, |
29 | ); |
29 | ); |
30 | |
30 | |
31 | $self->{map_widget}->clr_commands; |
31 | $self->{map_widget}->clr_commands; |
… | |
… | |
47 | map ["$cmd$_", $text], |
47 | map ["$cmd$_", $text], |
48 | sort { (length $a) <=> (length $b) } |
48 | sort { (length $a) <=> (length $b) } |
49 | @args |
49 | @args |
50 | } sort { $a->{par} <=> $b->{par} } |
50 | } sort { $a->{par} <=> $b->{par} } |
51 | CFPlus::Pod::find command => "*"; |
51 | CFPlus::Pod::find command => "*"; |
|
|
52 | |
|
|
53 | $self->connect_ext (event_music => sub { |
|
|
54 | my ($ev) = @_; |
|
|
55 | |
|
|
56 | return unless $::CFG->{bgm_enable}; |
|
|
57 | |
|
|
58 | my $faces = $ev->{faces}; |
|
|
59 | my @songs; |
|
|
60 | |
|
|
61 | # request music from server if appropriate |
|
|
62 | if (my $faces = $ev->{faces}) { |
|
|
63 | for (@$faces) { |
|
|
64 | my ($face, $pri, $chksum) = @$_; |
|
|
65 | utf8::downgrade $chksum; |
|
|
66 | |
|
|
67 | $chksum = unpack "H*", $chksum; |
|
|
68 | $self->{music_map}{$face} = $chksum; |
|
|
69 | |
|
|
70 | # check if already cached |
|
|
71 | CFPlus::DB::get "res-metadata" => $chksum, sub { |
|
|
72 | my ($meta_json) = @_; |
|
|
73 | my $path = CFPlus::DB::path_of_res $chksum; |
|
|
74 | |
|
|
75 | if (defined $meta_json) { |
|
|
76 | my $meta = $self->{json_coder}->decode ($meta_json); |
|
|
77 | $meta->{path} = $path; |
|
|
78 | $self->{music_meta}{$chksum} = $meta; |
|
|
79 | } else { |
|
|
80 | ::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
|
|
81 | $self->ask_face ($face, -100 - $pri, undef, sub { |
|
|
82 | my $len = length $_[1]; |
|
|
83 | my ($meta_json, $data) = unpack "(w/a*)*", $_[1]; |
|
|
84 | |
|
|
85 | CFPlus::DB::write_file $path, $data, sub { |
|
|
86 | CFPlus::DB::put "res-metadata" => $chksum => $meta_json, sub { |
|
|
87 | my $meta = $self->{json_coder}->decode ($meta_json); |
|
|
88 | $meta->{path} = $path; |
|
|
89 | $self->{music_meta}{$chksum} = $meta; |
|
|
90 | |
|
|
91 | ::message ({ markup => "downloaded song #$face, size $len octets" }); |
|
|
92 | &::audio_music_set ($self->{songs}); |
|
|
93 | }; |
|
|
94 | }; |
|
|
95 | }); |
|
|
96 | } |
|
|
97 | } |
|
|
98 | } |
|
|
99 | } |
|
|
100 | |
|
|
101 | if (my $play = $ev->{play}) { |
|
|
102 | &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]); |
|
|
103 | } |
|
|
104 | }); |
52 | |
105 | |
53 | $self->connect_ext (event_capabilities => sub { |
106 | $self->connect_ext (event_capabilities => sub { |
54 | my ($cap) = @_; |
107 | my ($cap) = @_; |
55 | |
108 | |
56 | if (my $ts = $cap->{tileset}) { |
109 | if (my $ts = $cap->{tileset}) { |
… | |
… | |
712 | } |
765 | } |
713 | |
766 | |
714 | sub set_texture { |
767 | sub set_texture { |
715 | my ($self, $id, $data) = @_; |
768 | my ($self, $id, $data) = @_; |
716 | |
769 | |
|
|
770 | return unless $self->{map}; |
|
|
771 | |
717 | $self->{texture}[$id] = my $tex = |
772 | $self->{texture}[$id] = my $tex = |
718 | new_from_image CFPlus::Texture |
773 | new_from_image CFPlus::Texture |
719 | $data, minify => 1, mipmap => 1; |
774 | $data, minify => 1, mipmap => 1; |
720 | |
775 | |
721 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
776 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |