--- deliantra/Deliantra-Client/DC.pm 2008/01/13 08:47:00 1.172 +++ deliantra/Deliantra-Client/DC.pm 2008/09/03 06:07:39 1.191 @@ -12,18 +12,23 @@ =cut +package Deliantra::Client; # work around CPAN breakage +package App::Deliantra; # try to reserve namespace package DC; use Carp (); +our $VERSION; + BEGIN { - $VERSION = '0.9964'; + $VERSION = '0.9975'; use XSLoader; XSLoader::load "Deliantra::Client", $VERSION; } use utf8; +use strict qw(vars subs); use AnyEvent (); use Pod::POM (); @@ -142,15 +147,42 @@ package DC; +our $RC_THEME; +our $THEME; +our @RC_PATH; +our $RC_BASE; + +for (grep !ref, @INC) { + $RC_BASE = "$_/Deliantra/Client/private/resources"; + last if -d $RC_BASE; +} + sub find_rcfile($) { my $path; - for (grep !ref, @INC) { - $path = "$_/Deliantra/Client/private/resources/$_[0]"; + for (@RC_PATH, "") { + $path = "$RC_BASE/$_/$_[0]"; return $path if -r $path; } - die "FATAL: can't find required file $_[0]\n"; + die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; +} + +sub set_theme($) { + return if $RC_THEME eq $_[0]; + $RC_THEME = $_[0]; + + @RC_PATH = "theme-$RC_THEME"; + + { + open my $fh, "<:raw", find_rcfile "theme.json" + or die "cannot open theme description file"; + + local $/; + $THEME = JSON::XS->new->utf8->relaxed->decode (<$fh>); + } + + @RC_PATH = @{ $THEME->{path} } if $THEME->{path}; } sub read_cfg { @@ -166,13 +198,13 @@ } sub write_cfg { - my ($file) = @_; + my $file = "$Deliantra::VARDIR/client.cf"; $::CFG->{VERSION} = $::VERSION; open my $fh, ">:utf8", $file or return; - print $fh encode_json $::CFG; + print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); } sub http_proxy { @@ -225,7 +257,6 @@ } else { fcntl $fh, &Fcntl::F_SETFL, $nb ? &Fcntl::O_NONBLOCK : 0; } - } package DC::Layout;