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.109 by root, Mon Jun 25 05:43:37 2007 UTC vs.
Revision 1.119 by root, Sat Jul 14 12:05:53 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
74 if (defined $meta_json) {
75 my $meta = $self->{json_coder}->decode ($meta_json);
76 $meta->{path} = CFPlus::DB::path_of_res $chksum;
77 $self->{music_meta}{$chksum} = $meta;
78 } else {
79 ::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." });
80 $self->ask_face ($face, -100 - $pri, undef, sub {
81 my $len = length $_[1];
82 my ($meta_json, $data) = unpack "(w/a*)*", $_[1];
83
84 my $meta = $self->{json_coder}->decode ($meta_json);
85 $meta->{path} = CFPlus::DB::path_of_res $chksum;
86 $self->{music_meta}{$chksum} = $meta;
87
88 CFPlus::DB::write_file $meta->{path}, $data, sub { };
89 CFPlus::DB::put "res-metadata" => $chksum => $meta_json, sub { };
90
91 ::message ({ markup => "downloaded song #$face, size $len octets" });
92 });
93 }
94
95 &::audio_music_set ($self->{songs});
96 }
97 }
98 }
99
100 if (my $play = $ev->{play}) {
101 &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]);
102 }
103 });
104
53 $self->connect_ext (event_capabilities => sub { 105 $self->connect_ext (event_capabilities => sub {
54 my ($cap) = @_; 106 my ($cap) = @_;
55 107
56 if (my $ts = $cap->{tileset}) { 108 if (my $ts = $cap->{tileset}) {
57 if (my ($default) = grep $_->[2] & 1, @$ts) { 109 if (my ($default) = grep $_->[2] & 1, @$ts) {
65 $self->setup_req (mapsize => "${w}x${h}"); 117 $self->setup_req (mapsize => "${w}x${h}");
66 } 118 }
67 } 119 }
68 }); 120 });
69 121
122 $self->{json_coder}
123 ->convert_blessed
124 ->filter_json_single_key_object (__widget_ref__ => sub {
125 $self->{widget}{$_[0]}
126 });
127
70 $self->connect_ext (ws_n => sub { 128 $self->connect_ext (ws_n => sub {
71 my ($arg) = @_; 129 my ($arg) = @_;
72 130
73 $self->{widgetset}{$arg{id}} = { 131 $self->{widgetset}{$arg{id}} = {
74 w => {}, 132 w => {},
98 1 156 1
99 }; 157 };
100 } 158 }
101 159
102 if (my $widget = eval { 160 if (my $widget = eval {
161 local $SIG{__DIE__};
103 "CFPlus::UI::$arg->{class}"->new ( 162 "CFPlus::UI::$arg->{class}"->new (
104 %$args, 163 %$args,
105 s_ws => $arg->{ws}, 164 s_ws => $arg->{ws},
106 s_id => $arg->{id}, 165 s_id => $arg->{id},
107 ) 166 )
128 187
129 my $w = $self->{widget}{$arg->{id}} 188 my $w = $self->{widget}{$arg->{id}}
130 or return; 189 or return;
131 my $m = $arg->{name}; 190 my $m = $arg->{name};
132 191
133 my @a = map {
134 "HASH" eq ref && 1 == (scalar keys %$_) && exists $_->{__widget_ref__}
135 ? $self->{widget}{$_->{__widget_ref__}}
136 : $_
137 } @{ $arg->{args} || [] }; 192 my $a = $arg->{args} || [];
138 193
139 if (exists $arg->{rid}) { 194 if (exists $arg->{rid}) {
140 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@a)]); 195 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@$a)]);
141 } else { 196 } else {
142 $w->$m (@a); 197 $w->$m (@$a);
143 } 198 }
144 }); 199 });
145 200
146 $self->connect_ext (w_s => sub { 201 $self->connect_ext (w_s => sub {
147 my ($arg) = @_; 202 my ($arg) = @_;
709} 764}
710 765
711sub set_texture { 766sub set_texture {
712 my ($self, $id, $data) = @_; 767 my ($self, $id, $data) = @_;
713 768
769 return unless $self->{map};
770
714 $self->{texture}[$id] = my $tex = 771 $self->{texture}[$id] = my $tex =
715 new_from_image CFPlus::Texture 772 new_from_image CFPlus::Texture
716 $data, minify => 1, mipmap => 1; 773 $data, minify => 1, mipmap => 1;
717 774
718 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 775 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
1129 1186
1130 (delete $self->{npc_dialog})->destroy 1187 (delete $self->{npc_dialog})->destroy
1131 if $self->{npc_dialog}; 1188 if $self->{npc_dialog};
1132 1189
1133 $self->SUPER::destroy; 1190 $self->SUPER::destroy;
1191
1192 %$self = ();
1134} 1193}
1135 1194
1136package CFPlus::NPCDialog; 1195package CFPlus::NPCDialog;
1137 1196
1138our @ISA = 'CFPlus::UI::Toplevel'; 1197our @ISA = 'CFPlus::UI::Toplevel';

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines