--- deliantra/Deliantra-Client/DC.pm 2008/09/02 17:08:44 1.190 +++ deliantra/Deliantra-Client/DC.pm 2008/09/29 03:41:58 1.195 @@ -12,8 +12,6 @@ =cut -package Deliantra::Client; # work around CPAN breakage -package App::Deliantra; # try to reserve namespace package DC; use Carp (); @@ -21,7 +19,7 @@ our $VERSION; BEGIN { - $VERSION = '0.9975'; + $VERSION = '0.9977'; use XSLoader; XSLoader::load "Deliantra::Client", $VERSION; @@ -72,7 +70,7 @@ } sub socketpipe() { - socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC + socketpair my $fh1, my $fh2, &Socket::AF_UNIX, &Socket::SOCK_STREAM, &Socket::PF_UNSPEC or die "cannot establish bidirectional pipe: $!\n"; ($fh1, $fh2) @@ -147,7 +145,9 @@ package DC; -our @RC_THEME = ("theme-blue", "."); +our $RC_THEME; +our %THEME; +our @RC_PATH; our $RC_BASE; for (grep !ref, @INC) { @@ -158,7 +158,7 @@ sub find_rcfile($) { my $path; - for (@RC_THEME) { + for (@RC_PATH, "") { $path = "$RC_BASE/$_/$_[0]"; return $path if -r $path; } @@ -166,16 +166,42 @@ die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; } -sub read_cfg { +sub load_json($) { my ($file) = @_; open my $fh, $file or return; local $/; - my $CFG = <$fh>; + JSON::XS->new->utf8->relaxed->decode (<$fh>) +} + +sub set_theme($) { + return if $RC_THEME eq $_[0]; + $RC_THEME = $_[0]; + + # kind of hacky, find the main theme file, then load all theme files and merge them + + %THEME = (); + @RC_PATH = "theme-$RC_THEME"; + + my $theme = load_json find_rcfile "theme.json" + or die "FATAL: theme resource file not found"; + + @RC_PATH = @{ $theme->{path} } if $theme->{path}; + + for (@RC_PATH, "") { + my $theme = load_json "$RC_BASE/$_/theme.json" + or next; + + %THEME = ( %$theme, %THEME ); + } +} + +sub read_cfg { + my ($file) = @_; - $::CFG = decode_json $CFG; + $::CFG = load_json $file; } sub write_cfg {