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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines