ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra.pm
(Generate patch)

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.69 by root, Thu Aug 3 10:51:26 2006 UTC vs.
Revision 1.70 by root, Sun Aug 27 16:33:19 2006 UTC

18use Storable qw(freeze thaw); 18use Storable qw(freeze thaw);
19 19
20our @EXPORT = qw( 20our @EXPORT = qw(
21 read_pak read_arch *ARCH TILESIZE $TILE *FACE editor_archs arch_extents 21 read_pak read_arch *ARCH TILESIZE $TILE *FACE editor_archs arch_extents
22); 22);
23
24use JSON::Syck (); #TODO#d# replace by JSON::PC when it becomes available == working
25
26sub from_json($) {
27 $JSON::Syck::ImplicitUnicode = 1;
28 JSON::Syck::Load $_[0]
29}
30
31sub to_json($) {
32 $JSON::Syck::ImplicitUnicode = 0;
33 JSON::Syck::Dump $_[0]
34}
23 35
24our $LIB = $ENV{CROSSFIRE_LIBDIR}; 36our $LIB = $ENV{CROSSFIRE_LIBDIR};
25 37
26our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire"; 38our $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire";
27 39
44 qw(move_type move_block move_allow move_on move_off move_slow); 56 qw(move_type move_block move_allow move_on move_off move_slow);
45 57
46# same as in server save routine, to (hopefully) be compatible 58# same as in server save routine, to (hopefully) be compatible
47# to the other editors. 59# to the other editors.
48our @FIELD_ORDER_MAP = (qw( 60our @FIELD_ORDER_MAP = (qw(
49 name swap_time reset_timeout fixed_resettime difficulty region 61 name attach swap_time reset_timeout fixed_resettime difficulty region
50 shopitems shopgreed shopmin shopmax shoprace 62 shopitems shopgreed shopmin shopmax shoprace
51 darkness width height enter_x enter_y msg maplore 63 darkness width height enter_x enter_y msg maplore
52 unique template 64 unique template
53 outdoor temp pressure humid windspeed winddir sky nosmooth 65 outdoor temp pressure humid windspeed winddir sky nosmooth
54 tile_path_1 tile_path_2 tile_path_3 tile_path_4 66 tile_path_1 tile_path_2 tile_path_3 tile_path_4
55)); 67));
56 68
57our @FIELD_ORDER = (qw( 69our @FIELD_ORDER = (qw(
58 elevation 70 elevation
59 71
60 name name_pl custom_name title race 72 name name_pl custom_name attach title race
61 slaying skill msg lore other_arch face 73 slaying skill msg lore other_arch face
62 #todo-events 74 #todo-events
63 animation is_animated 75 animation is_animated
64 str dex con wis pow cha int 76 str dex con wis pow cha int
65 hp maxhp sp maxsp grace maxgrace 77 hp maxhp sp maxsp grace maxgrace
286 } 298 }
287 299
288 $ob 300 $ob
289} 301}
290 302
303sub attr_thaw($) {
304 my ($ob) = @_;
305
306 $ob->{attach} = from_json $ob->{attach}
307 if exists $ob->{attach};
308
309 $ob
310}
311
312sub attr_freeze($) {
313 my ($ob) = @_;
314
315 $ob->{attach} = Crossfire::to_json $ob->{attach}
316 if exists $ob->{attach};
317
318 $ob
319}
320
291sub read_pak($) { 321sub read_pak($) {
292 my ($path) = @_; 322 my ($path) = @_;
293 323
294 my %pak; 324 my %pak;
295 325
322 while (<$fh>) { 352 while (<$fh>) {
323 s/\s+$//; 353 s/\s+$//;
324 if (/^end$/i) { 354 if (/^end$/i) {
325 last; 355 last;
326 } elsif (/^arch (\S+)$/i) { 356 } elsif (/^arch (\S+)$/i) {
327 push @{ $arc{inventory} }, normalize_arch $parse_block->(_name => $1); 357 push @{ $arc{inventory} }, attr_thaw normalize_arch $parse_block->(_name => $1);
328 } elsif (/^lore$/i) { 358 } elsif (/^lore$/i) {
329 while (<$fh>) { 359 while (<$fh>) {
330 last if /^endlore\s*$/i; 360 last if /^endlore\s*$/i;
331 $arc{lore} .= $_; 361 $arc{lore} .= $_;
332 } 362 }
357 s/\s+$//; 387 s/\s+$//;
358 if (/^more$/i) { 388 if (/^more$/i) {
359 $more = $prev; 389 $more = $prev;
360 } elsif (/^object (\S+)$/i) { 390 } elsif (/^object (\S+)$/i) {
361 my $name = $1; 391 my $name = $1;
362 my $arc = normalize_object $parse_block->(_name => $name); 392 my $arc = attr_thaw normalize_object $parse_block->(_name => $name);
363 393
364 if ($more) { 394 if ($more) {
365 $more->{more} = $arc; 395 $more->{more} = $arc;
366 } else { 396 } else {
367 $arc{$name} = $arc; 397 $arc{$name} = $arc;
368 } 398 }
369 $prev = $arc; 399 $prev = $arc;
370 $more = undef; 400 $more = undef;
371 } elsif (/^arch (\S+)$/i) { 401 } elsif (/^arch (\S+)$/i) {
372 my $name = $1; 402 my $name = $1;
373 my $arc = normalize_arch $parse_block->(_name => $name); 403 my $arc = attr_thaw normalize_arch $parse_block->(_name => $name);
374 404
375 if ($more) { 405 if ($more) {
376 $more->{more} = $arc; 406 $more->{more} = $arc;
377 } else { 407 } else {
378 push @{ $arc{arch} }, $arc; 408 push @{ $arc{arch} }, $arc;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines