--- deliantra/Deliantra-Client/DC.pm 2006/07/24 08:23:27 1.107
+++ deliantra/Deliantra-Client/DC.pm 2006/07/30 13:16:44 1.108
@@ -1,10 +1,10 @@
=head1 NAME
-CFClient - undocumented utility garbage for our crossfire client
+CFPlus - undocumented utility garbage for our crossfire client
=head1 SYNOPSIS
- use CFClient;
+ use CFPlus;
=head1 DESCRIPTION
@@ -12,13 +12,13 @@
=cut
-package CFClient;
+package CFPlus;
BEGIN {
$VERSION = '0.1';
use XSLoader;
- XSLoader::load "CFClient", $VERSION;
+ XSLoader::load "CFPlus", $VERSION;
}
use utf8;
@@ -28,7 +28,7 @@
use BerkeleyDB;
use Pod::POM ();
use Scalar::Util ();
-use YAML ();
+use JSON::Syck ();
use Storable (); # finally
our %STAT_TOOLTIP = (
@@ -55,10 +55,10 @@
=cut
sub guard(&) {
- bless \(my $cb = $_[0]), "CFClient::Guard"
+ bless \(my $cb = $_[0]), "CFPlus::Guard"
}
-sub CFClient::Guard::DESTROY {
+sub CFPlus::Guard::DESTROY {
${$_[0]}->()
}
@@ -72,7 +72,7 @@
$_
}
-package CFClient::Database;
+package CFPlus::Database;
our @ISA = BerkeleyDB::Btree::;
@@ -94,25 +94,27 @@
$db->db_put ($key => $data)
}
-package CFClient;
+package CFPlus;
sub find_rcfile($) {
my $path;
for (grep !ref, @INC) {
- $path = "$_/CFClient/resources/$_[0]";
+ $path = "$_/CFPlus/resources/$_[0]";
return $path if -r $path;
}
die "FATAL: can't find required file $_[0]\n";
}
-sub parse_yaml {
- my $text = shift;
+$JSON::Syck::ImplicitUnicode = 1;
- utf8::decode $text;
+sub from_json {
+ JSON::Syck::Load $_[0]
+}
- YAML::Load $text
+sub to_json {
+ JSON::Syck::Dump $_[0]
}
sub read_cfg {
@@ -124,10 +126,14 @@
local $/;
my $CFG = <$fh>;
- if ($CFG =~ /^---/) {
- $::CFG = parse_yaml $CFG;
+ if ($CFG =~ /^---/) { ## TODO compatibility cruft, remove
+ require YAML;
+ utf8::decode $CFG;
+ $::CFG = YAML::Load ($CFG);
+ } elsif ($CFG =~ /^\{/) {
+ $::CFG = from_json $CFG;
} else {
- $::CFG = eval $CFG;
+ $::CFG = eval $CFG; ## todo comaptibility cruft
}
}
@@ -138,7 +144,7 @@
open my $fh, ">:utf8", $file
or return;
- print $fh YAML::Dump $::CFG;
+ print $fh to_json $::CFG;
}
our $DB_ENV;
@@ -167,7 +173,7 @@
$table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
- new CFClient::Database
+ new CFPlus::Database
-Env => $DB_ENV,
-Filename => $table,
# -Filename => "database",
@@ -177,13 +183,13 @@
or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
}
-package CFClient::Layout;
+package CFPlus::Layout;
-$CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Layout"} = sub {
+$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub {
reset_glyph_cache;
};
-package CFClient::Item;
+package CFPlus::Item;
use strict;
use Crossfire::Protocol::Constants;
@@ -227,14 +233,14 @@
sub do_n_dialog {
my ($cb) = @_;
- my $w = new CFClient::UI::FancyFrame
+ my $w = new CFPlus::UI::FancyFrame
on_delete => sub { $_[0]->destroy; 1 },
has_close_button => 1,
;
- $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center");
- $vb->add (new CFClient::UI::Label text => "Enter item count:");
- $vb->add (my $entry = new CFClient::UI::Entry
+ $w->add (my $vb = new CFPlus::UI::VBox x => "center", y => "center");
+ $vb->add (new CFPlus::UI::Label text => "Enter item count:");
+ $vb->add (my $entry = new CFPlus::UI::Entry
text => $last_enter_count,
on_activate => sub {
my ($entry) = @_;
@@ -266,10 +272,10 @@
$targ = $::CONN->{open_container};
}
- if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
+ if (($ev->{mod} & CFPlus::KMOD_SHIFT) && $ev->{button} == 1) {
$::CONN->send ("move $targ $self->{tag} 0")
if $targ || !($self->{flags} & F_LOCKED);
- } elsif (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 2) {
+ } elsif (($ev->{mod} & CFPlus::KMOD_SHIFT) && $ev->{button} == 2) {
$self->{flags} & F_LOCKED
? $::CONN->send ("lock " . pack "CN", 0, $self->{tag})
: $::CONN->send ("lock " . pack "CN", 1, $self->{tag})
@@ -310,7 +316,7 @@
),
);
- CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
+ CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
}
1
@@ -328,7 +334,7 @@
: $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5]
: undef;
- $self->{face_widget} ||= new CFClient::UI::Face
+ $self->{face_widget} ||= new CFPlus::UI::Face
can_events => 1,
can_hover => 1,
anim => $self->{anim},
@@ -346,19 +352,19 @@
. "\n\n$tooltip_std"
);
- $self->{desc_widget} ||= new CFClient::UI::Label
+ $self->{desc_widget} ||= new CFPlus::UI::Label
can_events => 1,
can_hover => 1,
ellipsise => 2,
align => -1,
on_button_down => $button_cb,
;
- my $desc = CFClient::Item::desc_string $self;
+ my $desc = CFPlus::Item::desc_string $self;
$self->{desc_widget}{bg} = $bg;
$self->{desc_widget}->set_text ($desc);
$self->{desc_widget}->set_tooltip ("$desc.\n$tooltip_std");
- $self->{weight_widget} ||= new CFClient::UI::Label
+ $self->{weight_widget} ||= new CFPlus::UI::Label
can_events => 1,
can_hover => 1,
ellipsise => 0,
@@ -366,7 +372,7 @@
on_button_down => $button_cb,
;
$self->{weight_widget}{bg} = $bg;
- $self->{weight_widget}->set_text (CFClient::Item::weight_string $self);
+ $self->{weight_widget}->set_text (CFPlus::Item::weight_string $self);
$self->{weight_widget}->set_tooltip (
"Weight.\n"
. ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ")