… | |
… | |
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 | |
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 | &::audio_music_set ($self->{songs}); |
|
|
80 | } else { |
|
|
81 | ::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
|
|
82 | $self->ask_face ($face, -100 - $pri, undef, sub { |
|
|
83 | my $len = length $_[1]; |
|
|
84 | my ($meta_json, $data) = unpack "(w/a*)*", $_[1]; |
|
|
85 | |
|
|
86 | CFPlus::DB::write_file $path, $data, sub { |
|
|
87 | CFPlus::DB::put "res-metadata" => $chksum => $meta_json, sub { |
|
|
88 | my $meta = $self->{json_coder}->decode ($meta_json); |
|
|
89 | $meta->{path} = $path; |
|
|
90 | $self->{music_meta}{$chksum} = $meta; |
|
|
91 | |
|
|
92 | ::message ({ markup => "downloaded song #$face, size $len octets" }); |
|
|
93 | &::audio_music_set ($self->{songs}); |
|
|
94 | }; |
|
|
95 | }; |
|
|
96 | }); |
|
|
97 | } |
|
|
98 | } |
|
|
99 | } |
|
|
100 | } |
|
|
101 | |
|
|
102 | if (my $play = $ev->{play}) { |
|
|
103 | &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]); |
|
|
104 | } |
|
|
105 | }); |
|
|
106 | |
53 | $self->connect_ext (event_capabilities => sub { |
107 | $self->connect_ext (event_capabilities => sub { |
54 | my ($cap) = @_; |
108 | my ($cap) = @_; |
55 | |
109 | |
56 | if (my $ts = $cap->{tileset}) { |
110 | if (my $ts = $cap->{tileset}) { |
57 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
111 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
… | |
… | |
71 | ->convert_blessed |
125 | ->convert_blessed |
72 | ->filter_json_single_key_object (__widget_ref__ => sub { |
126 | ->filter_json_single_key_object (__widget_ref__ => sub { |
73 | $self->{widget}{$_[0]} |
127 | $self->{widget}{$_[0]} |
74 | }); |
128 | }); |
75 | |
129 | |
|
|
130 | # widgetset new |
76 | $self->connect_ext (ws_n => sub { |
131 | $self->connect_ext (ws_n => sub { |
77 | my ($arg) = @_; |
132 | my ($arg) = @_; |
78 | |
133 | |
79 | $self->{widgetset}{$arg{id}} = { |
134 | $self->{widgetset}{$arg{id}} = { |
80 | w => {}, |
135 | w => {}, |
81 | }; |
136 | }; |
82 | }); |
137 | }); |
83 | |
138 | |
|
|
139 | # widgetset destroy |
84 | $self->connect_ext (ws_d => sub { |
140 | $self->connect_ext (ws_d => sub { |
85 | my ($arg) = @_; |
141 | my ($arg) = @_; |
86 | |
142 | |
87 | my $ws = delete $self->{widgetset}{$arg{id}} |
143 | my $ws = delete $self->{widgetset}{$arg{id}} |
88 | or return; |
144 | or return; |
89 | |
145 | |
90 | $_->destroy |
146 | $_->destroy |
91 | for values %{$ws->{w}}; |
147 | for values %{$ws->{w}}; |
92 | }); |
148 | }); |
93 | |
149 | |
|
|
150 | # widgetset destroy |
94 | $self->connect_ext (ws_c => sub { |
151 | $self->connect_ext (ws_c => sub { |
95 | my ($arg) = @_; |
152 | my ($arg) = @_; |
96 | |
153 | |
97 | my $args = $arg->{args} || {}; |
154 | my $args = $arg->{args} || {}; |
98 | |
155 | |
… | |
… | |
128 | warn "server failed creating client-side widget " . (CFPlus::to_json $arg) . ": $@\n"; |
185 | warn "server failed creating client-side widget " . (CFPlus::to_json $arg) . ": $@\n"; |
129 | $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy"); |
186 | $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy"); |
130 | } |
187 | } |
131 | }); |
188 | }); |
132 | |
189 | |
|
|
190 | # widget call |
133 | $self->connect_ext (w_c => sub { |
191 | $self->connect_ext (w_c => sub { |
134 | my ($arg) = @_; |
192 | my ($arg) = @_; |
135 | |
193 | |
136 | my $w = $self->{widget}{$arg->{id}} |
194 | my $w = $self->{widget}{$arg->{id}} |
137 | or return; |
195 | or return; |
… | |
… | |
144 | } else { |
202 | } else { |
145 | $w->$m (@$a); |
203 | $w->$m (@$a); |
146 | } |
204 | } |
147 | }); |
205 | }); |
148 | |
206 | |
|
|
207 | # widget set |
149 | $self->connect_ext (w_s => sub { |
208 | $self->connect_ext (w_s => sub { |
150 | my ($arg) = @_; |
209 | my ($arg) = @_; |
151 | |
210 | |
152 | my $w = $self->{widget}{$arg->{id}} |
211 | my $w = $self->{widget}{$arg->{id}} |
153 | or return; |
212 | or return; |
154 | |
213 | |
155 | $w->{$arg->{name}} = $arg->{value}; |
214 | $w->{$arg->{name}} = $arg->{value}; |
156 | }); |
215 | }); |
157 | |
216 | |
|
|
217 | # widget get |
158 | $self->connect_ext (w_g => sub { |
218 | $self->connect_ext (w_g => sub { |
159 | my ($arg) = @_; |
219 | my ($arg) = @_; |
160 | |
220 | |
161 | my $w = $self->{widget}{$arg->{id}} |
221 | my $w = $self->{widget}{$arg->{id}} |
162 | or return; |
222 | or return; |
163 | |
223 | |
164 | $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->{$arg->{name}}]); |
224 | $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->{$arg->{name}}]); |
165 | }); |
225 | }); |
166 | |
226 | |
|
|
227 | # destroy widgets on logout |
167 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
228 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
168 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
229 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
169 | $_->destroy |
230 | $_->destroy |
170 | for values %{delete $ws->{w} || {}}; |
231 | for values %{delete $ws->{w} || {}}; |
171 | } |
232 | } |
… | |
… | |
712 | } |
773 | } |
713 | |
774 | |
714 | sub set_texture { |
775 | sub set_texture { |
715 | my ($self, $id, $data) = @_; |
776 | my ($self, $id, $data) = @_; |
716 | |
777 | |
|
|
778 | return unless $self->{map}; |
|
|
779 | |
717 | $self->{texture}[$id] = my $tex = |
780 | $self->{texture}[$id] = my $tex = |
718 | new_from_image CFPlus::Texture |
781 | new_from_image CFPlus::Texture |
719 | $data, minify => 1, mipmap => 1; |
782 | $data, minify => 1, mipmap => 1; |
720 | |
783 | |
721 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
784 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
722 | $self->{map_widget}->update; |
785 | $self->{map_widget}->update; |
|
|
786 | |
|
|
787 | $_->() for @{(delete $self->{face_cb}{$id}) || []}; |
|
|
788 | } |
|
|
789 | |
|
|
790 | sub connect_face_update { |
|
|
791 | my ($self, $id, $cb) = @_; |
|
|
792 | |
|
|
793 | push @{$self->{face_cb}{$id}}, $cb; |
|
|
794 | |
|
|
795 | CFPlus::guard { |
|
|
796 | @{$self->{face_cb}{$id}} |
|
|
797 | = grep $_ != $cb, |
|
|
798 | @{$self->{face_cb}{$id}}; |
|
|
799 | } |
723 | } |
800 | } |
724 | |
801 | |
725 | sub sound_play { |
802 | sub sound_play { |
726 | my ($self, $x, $y, $soundnum, $type) = @_; |
803 | my ($self, $x, $y, $soundnum, $type) = @_; |
727 | |
804 | |