… | |
… | |
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 (music => sub { |
53 | $self->connect_ext (ambient_music => sub { |
54 | my ($ev) = @_; |
54 | my ($songs) = @_; |
55 | |
55 | &::audio_music_set_ambient ($songs); |
56 | &::audio_music_set ($self->{songs} = $ev->{play}) |
|
|
57 | if $ev->{play}; |
|
|
58 | }); |
56 | }); |
59 | |
57 | |
60 | $self->connect_ext (capabilities => sub { |
58 | $self->connect_ext (capabilities => sub { |
61 | my (%cap) = @_; |
59 | my (%cap) = @_; |
|
|
60 | |
|
|
61 | #$self->send ("setup sound 0"); # we use a different protocol |
62 | |
62 | |
63 | $self->send_exti_msg (fx_want => { |
63 | $self->send_exti_msg (fx_want => { |
64 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
64 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
65 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
65 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
66 | }); |
66 | }); |
… | |
… | |
189 | |
189 | |
190 | # message window |
190 | # message window |
191 | $self->connect_ext (channel_info => sub { |
191 | $self->connect_ext (channel_info => sub { |
192 | my ($info) = @_; |
192 | my ($info) = @_; |
193 | $self->{channels}->{$info->{id}} = $info; |
193 | $self->{channels}->{$info->{id}} = $info; |
194 | $::MESSAGE_WINDOW->add_channel ($_[0]); |
194 | $::MESSAGE_WINDOW->add_channel ($info); |
195 | }); |
195 | }); |
196 | |
196 | |
197 | # destroy widgets on logout |
197 | # destroy widgets on logout |
198 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
198 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
199 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
199 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
… | |
… | |
733 | |
733 | |
734 | CFPlus::DB::get tilecache => $id, $cb; |
734 | CFPlus::DB::get tilecache => $id, $cb; |
735 | |
735 | |
736 | } elsif ($face->{type} & 1) { # with metadata |
736 | } elsif ($face->{type} & 1) { # with metadata |
737 | #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
737 | #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
738 | CFPlus::DB::get "res-metadata" => $face->{name}, $cb; |
738 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
739 | } |
739 | } |
740 | } |
740 | } |
741 | |
741 | |
742 | sub face_update { |
742 | sub face_update { |
743 | my ($self, $facenum, $face, $changed) = @_; |
743 | my ($self, $facenum, $face, $changed) = @_; |
… | |
… | |
756 | $self->{music_meta}{$facenum} = $face; |
756 | $self->{music_meta}{$facenum} = $face; |
757 | |
757 | |
758 | ::message ({ markup => "downloaded song #$facenum" }) |
758 | ::message ({ markup => "downloaded song #$facenum" }) |
759 | if $changed; |
759 | if $changed; |
760 | |
760 | |
761 | &::audio_music_set ($self->{songs}); |
761 | &::audio_music_push ($facenum); |
|
|
762 | }; |
|
|
763 | } elsif ($face->{type} == 5) { # FT_SOUND |
|
|
764 | $cb = sub { |
|
|
765 | $self->{sound_meta}{$facenum} = $face; |
|
|
766 | |
|
|
767 | ::message ({ markup => "downloaded sound #$facenum" }) |
|
|
768 | if $changed; |
|
|
769 | |
|
|
770 | &::audio_sound_push ($facenum); |
762 | }; |
771 | }; |
763 | } |
772 | } |
764 | |
773 | |
765 | if ($changed) { # new data |
774 | if ($changed) { # new data |
766 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
775 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
767 | my $path = CFPlus::DB::path_of_res $face->{name}; |
|
|
768 | |
776 | |
769 | CFPlus::DB::write_file $path, $data, sub { |
777 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
770 | CFPlus::DB::put "res-metadata" => $face->{name} => $meta_json, sub { |
778 | CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { |
771 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
779 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
772 | $face->{path} = $path; |
780 | ::add_license ($face); |
773 | |
|
|
774 | $cb->(); |
781 | $cb->(); |
775 | }; |
|
|
776 | }; |
782 | }; |
|
|
783 | |
777 | } else { |
784 | } else { |
778 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
785 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
786 | ::add_license ($face); |
779 | $cb->(); |
787 | $cb->(); |
780 | } |
788 | } |
781 | } |
789 | } |
782 | } |
790 | } |
783 | |
791 | |
… | |
… | |
813 | @{$self->{face_cb}{$id}}; |
821 | @{$self->{face_cb}{$id}}; |
814 | } |
822 | } |
815 | } |
823 | } |
816 | |
824 | |
817 | sub sound_play { |
825 | sub sound_play { |
818 | my ($self, $x, $y, $soundnum, $type) = @_; |
826 | my ($self, $type, $face, $dx, $dy, $vol) = @_; |
819 | |
827 | |
820 | $self->{sound_play}->($x, $y, $soundnum, $type); |
828 | &::audio_sound_play ($face, $dx, $dy, $vol) |
|
|
829 | unless $type & 1; # odd types are silent for future expansion |
821 | } |
830 | } |
822 | |
831 | |
823 | my $LAST_QUERY; # server is stupid, stupid, stupid |
832 | my $LAST_QUERY; # server is stupid, stupid, stupid |
824 | |
833 | |
825 | sub query { |
834 | sub query { |
… | |
… | |
890 | $self->{$type} = $text; |
899 | $self->{$type} = $text; |
891 | } else { |
900 | } else { |
892 | $self->logprint ("msg: ", $text); |
901 | $self->logprint ("msg: ", $text); |
893 | return if $color < 0; # negative color == ignore if not understood |
902 | return if $color < 0; # negative color == ignore if not understood |
894 | |
903 | |
895 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
904 | my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; |
896 | |
905 | |
897 | ## try to create single paragraphs of multiple lines sent by the server |
906 | ## try to create single paragraphs of multiple lines sent by the server |
898 | # no longer neecssary with TRT servers |
907 | # no longer neecssary with TRT servers |
899 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
908 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
900 | |
909 | |
901 | ::message ({ fg => $fg, markup => $_, type => $type }) |
910 | ::message ({ fg => $fg, markup => $_, type => $type, extra => [@extra] }) |
902 | for split /\n/, $text; |
911 | for split /\n/, $text; |
903 | |
912 | |
904 | $self->{statusbox}->add ($text, |
913 | $self->{statusbox}->add ($text, |
905 | group => $text, |
914 | group => $text, |
906 | fg => $fg, |
915 | fg => $fg, |
… | |
… | |
961 | my ($self) = @_; |
970 | my ($self) = @_; |
962 | |
971 | |
963 | $self->{map_widget}->clr_commands; |
972 | $self->{map_widget}->clr_commands; |
964 | |
973 | |
965 | ::stop_game (); |
974 | ::stop_game (); |
966 | } |
|
|
967 | |
|
|
968 | sub image_info { |
|
|
969 | my ($self, $numfaces) = @_; |
|
|
970 | |
|
|
971 | $self->{num_faces} = $numfaces; |
|
|
972 | $self->{face_prefetch} = [1 .. $numfaces]; |
|
|
973 | $self->face_prefetch; |
|
|
974 | } |
|
|
975 | |
|
|
976 | sub face_prefetch { |
|
|
977 | my ($self) = @_; |
|
|
978 | |
|
|
979 | return unless $::CFG->{face_prefetch}; |
|
|
980 | |
|
|
981 | if ($self->{num_faces}) { |
|
|
982 | return if @{ $self->{send_queue} || [] }; |
|
|
983 | my $todo = @{ $self->{face_prefetch} } |
|
|
984 | or return; |
|
|
985 | |
|
|
986 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
|
|
987 | |
|
|
988 | $self->send ("requestinfo image_sums $face $face"); |
|
|
989 | |
|
|
990 | $self->{statusbox}->add (CFPlus::asxml "prefetching $todo", |
|
|
991 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
|
|
992 | } elsif (!exists $self->{num_faces}) { |
|
|
993 | $self->send ("requestinfo image_info"); |
|
|
994 | |
|
|
995 | $self->{num_faces} = 0; |
|
|
996 | |
|
|
997 | $self->{statusbox}->add (CFPlus::asxml "starting to prefetch", |
|
|
998 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
|
|
999 | } |
|
|
1000 | } |
975 | } |
1001 | |
976 | |
1002 | sub update_floorbox { |
977 | sub update_floorbox { |
1003 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
978 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
1004 | return unless $::CONN; |
979 | return unless $::CONN; |
… | |
… | |
1162 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1137 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1163 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1138 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1164 | . "map size $self->{mapw}×$self->{maph}\n" |
1139 | . "map size $self->{mapw}×$self->{maph}\n" |
1165 | ); |
1140 | ); |
1166 | |
1141 | |
1167 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
|
|
1168 | } |
1142 | } |
1169 | |
1143 | |
1170 | sub logged_in { |
1144 | sub logged_in { |
1171 | my ($self) = @_; |
1145 | my ($self) = @_; |
1172 | |
1146 | |
… | |
… | |
1192 | |
1166 | |
1193 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
1167 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
1194 | $self->send_command ("output-count $::CFG->{output_count}"); |
1168 | $self->send_command ("output-count $::CFG->{output_count}"); |
1195 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1169 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1196 | $self->send_command ("pickup $::CFG->{pickup}"); |
1170 | $self->send_command ("pickup $::CFG->{pickup}"); |
1197 | } |
|
|
1198 | |
|
|
1199 | sub buildat { |
|
|
1200 | my ($self, $builditem, $x, $y) = @_; |
|
|
1201 | |
|
|
1202 | if ($self->{cfplus_ext}) { |
|
|
1203 | $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem)); |
|
|
1204 | } |
|
|
1205 | } |
1171 | } |
1206 | |
1172 | |
1207 | sub lookat { |
1173 | sub lookat { |
1208 | my ($self, $x, $y) = @_; |
1174 | my ($self, $x, $y) = @_; |
1209 | |
1175 | |