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.191 by root, Wed Sep 3 06:07:39 2008 UTC vs.
Revision 1.194 by root, Wed Sep 24 02:39:47 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 = '0.9976';
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
146} 144}
147 145
148package DC; 146package DC;
149 147
150our $RC_THEME; 148our $RC_THEME;
151our $THEME; 149our %THEME;
152our @RC_PATH; 150our @RC_PATH;
153our $RC_BASE; 151our $RC_BASE;
154 152
155for (grep !ref, @INC) { 153for (grep !ref, @INC) {
156 $RC_BASE = "$_/Deliantra/Client/private/resources"; 154 $RC_BASE = "$_/Deliantra/Client/private/resources";
166 } 164 }
167 165
168 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";
169} 167}
170 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
171sub set_theme($) { 179sub set_theme($) {
172 return if $RC_THEME eq $_[0]; 180 return if $RC_THEME eq $_[0];
173 $RC_THEME = $_[0]; 181 $RC_THEME = $_[0];
174 182
183 # kind of hacky, find the main theme file, then load all theme files and merge them
184
185 %THEME = ();
175 @RC_PATH = "theme-$RC_THEME"; 186 @RC_PATH = "theme-$RC_THEME";
176 187
177 { 188 my $theme = load_json find_rcfile "theme.json"
178 open my $fh, "<:raw", find_rcfile "theme.json" 189 or die "FATAL: theme resource file not found";
179 or die "cannot open theme description file";
180 190
181 local $/;
182 $THEME = JSON::XS->new->utf8->relaxed->decode (<$fh>);
183 }
184
185 @RC_PATH = @{ $THEME->{path} } if $THEME->{path}; 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 }
186} 199}
187 200
188sub read_cfg { 201sub read_cfg {
189 my ($file) = @_; 202 my ($file) = @_;
190 203
191 open my $fh, $file 204 $::CFG = load_json $file;
192 or return;
193
194 local $/;
195 my $CFG = <$fh>;
196
197 $::CFG = decode_json $CFG;
198} 205}
199 206
200sub write_cfg { 207sub write_cfg {
201 my $file = "$Deliantra::VARDIR/client.cf"; 208 my $file = "$Deliantra::VARDIR/client.cf";
202 209

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines