--- deliantra/Deliantra/Deliantra.pm 2006/08/03 10:51:26 1.69 +++ deliantra/Deliantra/Deliantra.pm 2006/08/27 16:33:19 1.70 @@ -21,6 +21,18 @@ read_pak read_arch *ARCH TILESIZE $TILE *FACE editor_archs arch_extents ); +use JSON::Syck (); #TODO#d# replace by JSON::PC when it becomes available == working + +sub from_json($) { + $JSON::Syck::ImplicitUnicode = 1; + JSON::Syck::Load $_[0] +} + +sub to_json($) { + $JSON::Syck::ImplicitUnicode = 0; + JSON::Syck::Dump $_[0] +} + our $LIB = $ENV{CROSSFIRE_LIBDIR}; our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire"; @@ -46,7 +58,7 @@ # same as in server save routine, to (hopefully) be compatible # to the other editors. our @FIELD_ORDER_MAP = (qw( - name swap_time reset_timeout fixed_resettime difficulty region + name attach swap_time reset_timeout fixed_resettime difficulty region shopitems shopgreed shopmin shopmax shoprace darkness width height enter_x enter_y msg maplore unique template @@ -57,7 +69,7 @@ our @FIELD_ORDER = (qw( elevation - name name_pl custom_name title race + name name_pl custom_name attach title race slaying skill msg lore other_arch face #todo-events animation is_animated @@ -288,6 +300,24 @@ $ob } +sub attr_thaw($) { + my ($ob) = @_; + + $ob->{attach} = from_json $ob->{attach} + if exists $ob->{attach}; + + $ob +} + +sub attr_freeze($) { + my ($ob) = @_; + + $ob->{attach} = Crossfire::to_json $ob->{attach} + if exists $ob->{attach}; + + $ob +} + sub read_pak($) { my ($path) = @_; @@ -324,7 +354,7 @@ if (/^end$/i) { last; } elsif (/^arch (\S+)$/i) { - push @{ $arc{inventory} }, normalize_arch $parse_block->(_name => $1); + push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1); } elsif (/^lore$/i) { while (<$fh>) { last if /^endlore\s*$/i; @@ -359,7 +389,7 @@ $more = $prev; } elsif (/^object (\S+)$/i) { my $name = $1; - my $arc = normalize_object $parse_block->(_name => $name); + my $arc = attr_thaw normalize_object $parse_block->(_name => $name); if ($more) { $more->{more} = $arc; @@ -370,7 +400,7 @@ $more = undef; } elsif (/^arch (\S+)$/i) { my $name = $1; - my $arc = normalize_arch $parse_block->(_name => $name); + my $arc = attr_thaw normalize_arch $parse_block->(_name => $name); if ($more) { $more->{more} = $arc;