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.185 by root, Fri Aug 1 13:50:08 2008 UTC vs.
Revision 1.195 by root, Mon Sep 29 03:41:58 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
19our $VERSION;
20
21BEGIN { 21BEGIN {
22 $VERSION = '0.9974'; 22 $VERSION = '0.9977';
23 23
24 use XSLoader; 24 use XSLoader;
25 XSLoader::load "Deliantra::Client", $VERSION; 25 XSLoader::load "Deliantra::Client", $VERSION;
26} 26}
27 27
28use utf8; 28use utf8;
29use strict qw(vars subs);
29 30
30use AnyEvent (); 31use AnyEvent ();
31use Pod::POM (); 32use Pod::POM ();
32use File::Path (); 33use File::Path ();
33use Storable (); # finally 34use Storable (); # finally
67 68
68 $_ 69 $_
69} 70}
70 71
71sub socketpipe() { 72sub socketpipe() {
72 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
73 or die "cannot establish bidirectional pipe: $!\n"; 74 or die "cannot establish bidirectional pipe: $!\n";
74 75
75 ($fh1, $fh2) 76 ($fh1, $fh2)
76} 77}
77 78
142 print $msg, "\n"; 143 print $msg, "\n";
143} 144}
144 145
145package DC; 146package DC;
146 147
148our $RC_THEME;
149our %THEME;
150our @RC_PATH;
151our $RC_BASE;
152
153for (grep !ref, @INC) {
154 $RC_BASE = "$_/Deliantra/Client/private/resources";
155 last if -d $RC_BASE;
156}
157
147sub find_rcfile($) { 158sub find_rcfile($) {
148 my $path; 159 my $path;
149 160
150 for (grep !ref, @INC) { 161 for (@RC_PATH, "") {
151 $path = "$_/Deliantra/Client/private/resources/$_[0]"; 162 $path = "$RC_BASE/$_/$_[0]";
152 return $path if -r $path; 163 return $path if -r $path;
153 } 164 }
154 165
155 die "FATAL: can't find required file $_[0]\n"; 166 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n";
167}
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 }
156} 199}
157 200
158sub read_cfg { 201sub read_cfg {
159 my ($file) = @_; 202 my ($file) = @_;
160 203
161 open my $fh, $file 204 $::CFG = load_json $file;
162 or return;
163
164 local $/;
165 my $CFG = <$fh>;
166
167 $::CFG = decode_json $CFG;
168} 205}
169 206
170sub write_cfg { 207sub write_cfg {
171 my $file = "$Deliantra::VARDIR/client.cf"; 208 my $file = "$Deliantra::VARDIR/client.cf";
172 209

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines