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.121 by root, Sat Jul 14 13:08:40 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 &::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) {
65 $self->setup_req (mapsize => "${w}x${h}"); 119 $self->setup_req (mapsize => "${w}x${h}");
66 } 120 }
67 } 121 }
68 }); 122 });
69 123
124 $self->{json_coder}
125 ->convert_blessed
126 ->filter_json_single_key_object (__widget_ref__ => sub {
127 $self->{widget}{$_[0]}
128 });
129
70 $self->connect_ext (ws_n => sub { 130 $self->connect_ext (ws_n => sub {
71 my ($arg) = @_; 131 my ($arg) = @_;
72 132
73 $self->{widgetset}{$arg{id}} = { 133 $self->{widgetset}{$arg{id}} = {
74 w => {}, 134 w => {},
98 1 158 1
99 }; 159 };
100 } 160 }
101 161
102 if (my $widget = eval { 162 if (my $widget = eval {
163 local $SIG{__DIE__};
103 "CFPlus::UI::$arg->{class}"->new ( 164 "CFPlus::UI::$arg->{class}"->new (
104 %$args, 165 %$args,
105 s_ws => $arg->{ws}, 166 s_ws => $arg->{ws},
106 s_id => $arg->{id}, 167 s_id => $arg->{id},
107 ) 168 )
128 189
129 my $w = $self->{widget}{$arg->{id}} 190 my $w = $self->{widget}{$arg->{id}}
130 or return; 191 or return;
131 my $m = $arg->{name}; 192 my $m = $arg->{name};
132 193
133 my @a = map {
134 "HASH" eq ref && 1 == (scalar keys %$_) && exists $_->{__widget_ref__}
135 ? $self->{widget}{$_->{__widget_ref__}}
136 : $_
137 } @{ $arg->{args} || [] }; 194 my $a = $arg->{args} || [];
138 195
139 if (exists $arg->{rid}) { 196 if (exists $arg->{rid}) {
140 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@a)]); 197 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@$a)]);
141 } else { 198 } else {
142 $w->$m (@a); 199 $w->$m (@$a);
143 } 200 }
144 }); 201 });
145 202
146 $self->connect_ext (w_s => sub { 203 $self->connect_ext (w_s => sub {
147 my ($arg) = @_; 204 my ($arg) = @_;
709} 766}
710 767
711sub set_texture { 768sub set_texture {
712 my ($self, $id, $data) = @_; 769 my ($self, $id, $data) = @_;
713 770
771 return unless $self->{map};
772
714 $self->{texture}[$id] = my $tex = 773 $self->{texture}[$id] = my $tex =
715 new_from_image CFPlus::Texture 774 new_from_image CFPlus::Texture
716 $data, minify => 1, mipmap => 1; 775 $data, minify => 1, mipmap => 1;
717 776
718 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 777 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
1129 1188
1130 (delete $self->{npc_dialog})->destroy 1189 (delete $self->{npc_dialog})->destroy
1131 if $self->{npc_dialog}; 1190 if $self->{npc_dialog};
1132 1191
1133 $self->SUPER::destroy; 1192 $self->SUPER::destroy;
1193
1194 %$self = ();
1134} 1195}
1135 1196
1136package CFPlus::NPCDialog; 1197package CFPlus::NPCDialog;
1137 1198
1138our @ISA = 'CFPlus::UI::Toplevel'; 1199our @ISA = 'CFPlus::UI::Toplevel';

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines