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

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.189 by root, Tue Sep 2 16:50:06 2008 UTC vs.
Revision 1.199 by root, Wed Dec 24 04:13:13 2008 UTC

10 10
11=over 4 11=over 4
12 12
13=cut 13=cut
14 14
15package Deliantra::Client; # work around CPAN breakage
16package App::Deliantra; # try to reserve namespace
17package DC; 15package DC;
18 16
19use Carp (); 17use Carp ();
20 18
21our $VERSION; 19our $VERSION;
22 20
23BEGIN { 21BEGIN {
24 $VERSION = '0.9975'; 22 $VERSION = '2.02';
25 23
26 use XSLoader; 24 use XSLoader;
27 XSLoader::load "Deliantra::Client", $VERSION; 25 XSLoader::load "Deliantra::Client", $VERSION;
28} 26}
29 27
70 68
71 $_ 69 $_
72} 70}
73 71
74sub socketpipe() { 72sub socketpipe() {
75 socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC 73 socketpair my $fh1, my $fh2, &Socket::AF_UNIX, &Socket::SOCK_STREAM, &Socket::PF_UNSPEC
76 or die "cannot establish bidirectional pipe: $!\n"; 74 or die "cannot establish bidirectional pipe: $!\n";
77 75
78 ($fh1, $fh2) 76 ($fh1, $fh2)
79} 77}
80 78
145 print $msg, "\n"; 143 print $msg, "\n";
146} 144}
147 145
148package DC; 146package DC;
149 147
150our @RC_THEME = ("theme-plain", "."); 148our $RC_THEME;
149our %THEME;
150our @RC_PATH;
151our $RC_BASE; 151our $RC_BASE;
152 152
153for (grep !ref, @INC) { 153for (grep !ref, @INC) {
154 $RC_BASE = "$_/Deliantra/Client/private/resources"; 154 $RC_BASE = "$_/Deliantra/Client/private/resources";
155 last if -d $RC_BASE; 155 last if -d $RC_BASE;
156} 156}
157 157
158sub find_rcfile($) { 158sub find_rcfile($) {
159 my $path; 159 my $path;
160 160
161 for (@RC_THEME) { 161 for (@RC_PATH, "") {
162 $path = "$RC_BASE/$_/$_[0]"; 162 $path = "$RC_BASE/$_/$_[0]";
163 return $path if -r $path; 163 return $path if -r $path;
164 } 164 }
165 165
166 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; 166 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n";
167} 167}
168 168
169sub load_json($) {
170 my ($file) = @_;
171
172 open my $fh, $file
173 or return;
174
175 local $/;
176 JSON::XS->new->utf8->relaxed->decode (<$fh>)
177}
178
179sub set_theme($) {
180 return if $RC_THEME eq $_[0];
181 $RC_THEME = $_[0];
182
183 # kind of hacky, find the main theme file, then load all theme files and merge them
184
185 %THEME = ();
186 @RC_PATH = "theme-$RC_THEME";
187
188 my $theme = load_json find_rcfile "theme.json"
189 or die "FATAL: theme resource file not found";
190
191 @RC_PATH = @{ $theme->{path} } if $theme->{path};
192
193 for (@RC_PATH, "") {
194 my $theme = load_json "$RC_BASE/$_/theme.json"
195 or next;
196
197 %THEME = ( %$theme, %THEME );
198 }
199}
200
169sub read_cfg { 201sub read_cfg {
170 my ($file) = @_; 202 my ($file) = @_;
171 203
172 open my $fh, $file 204 $::CFG = load_json $file;
173 or return;
174
175 local $/;
176 my $CFG = <$fh>;
177
178 $::CFG = decode_json $CFG;
179} 205}
180 206
181sub write_cfg { 207sub write_cfg {
182 my $file = "$Deliantra::VARDIR/client.cf"; 208 my $file = "$Deliantra::VARDIR/client.cf";
183 209

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines