ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.110 by root, Tue Jun 26 05:06:01 2007 UTC vs.
Revision 1.120 by root, Sat Jul 14 13:04:42 2007 UTC

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;
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 } 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 });
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}) {
57 if (my ($default) = grep $_->[2] & 1, @$ts) { 110 if (my ($default) = grep $_->[2] & 1, @$ts) {
64 117
65 $self->setup_req (mapsize => "${w}x${h}"); 118 $self->setup_req (mapsize => "${w}x${h}");
66 } 119 }
67 } 120 }
68 }); 121 });
122
123 $self->{json_coder}
124 ->convert_blessed
125 ->filter_json_single_key_object (__widget_ref__ => sub {
126 $self->{widget}{$_[0]}
127 });
69 128
70 $self->connect_ext (ws_n => sub { 129 $self->connect_ext (ws_n => sub {
71 my ($arg) = @_; 130 my ($arg) = @_;
72 131
73 $self->{widgetset}{$arg{id}} = { 132 $self->{widgetset}{$arg{id}} = {
129 188
130 my $w = $self->{widget}{$arg->{id}} 189 my $w = $self->{widget}{$arg->{id}}
131 or return; 190 or return;
132 my $m = $arg->{name}; 191 my $m = $arg->{name};
133 192
134 my @a = map {
135 "HASH" eq ref && 1 == (scalar keys %$_) && exists $_->{__widget_ref__}
136 ? $self->{widget}{$_->{__widget_ref__}}
137 : $_
138 } @{ $arg->{args} || [] }; 193 my $a = $arg->{args} || [];
139 194
140 if (exists $arg->{rid}) { 195 if (exists $arg->{rid}) {
141 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@a)]); 196 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@$a)]);
142 } else { 197 } else {
143 $w->$m (@a); 198 $w->$m (@$a);
144 } 199 }
145 }); 200 });
146 201
147 $self->connect_ext (w_s => sub { 202 $self->connect_ext (w_s => sub {
148 my ($arg) = @_; 203 my ($arg) = @_;
710} 765}
711 766
712sub set_texture { 767sub set_texture {
713 my ($self, $id, $data) = @_; 768 my ($self, $id, $data) = @_;
714 769
770 return unless $self->{map};
771
715 $self->{texture}[$id] = my $tex = 772 $self->{texture}[$id] = my $tex =
716 new_from_image CFPlus::Texture 773 new_from_image CFPlus::Texture
717 $data, minify => 1, mipmap => 1; 774 $data, minify => 1, mipmap => 1;
718 775
719 $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}});
1130 1187
1131 (delete $self->{npc_dialog})->destroy 1188 (delete $self->{npc_dialog})->destroy
1132 if $self->{npc_dialog}; 1189 if $self->{npc_dialog};
1133 1190
1134 $self->SUPER::destroy; 1191 $self->SUPER::destroy;
1192
1193 %$self = ();
1135} 1194}
1136 1195
1137package CFPlus::NPCDialog; 1196package CFPlus::NPCDialog;
1138 1197
1139our @ISA = 'CFPlus::UI::Toplevel'; 1198our @ISA = 'CFPlus::UI::Toplevel';

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines