ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Games-Sokoban/Sokoban.pm
(Generate patch)

Comparing Games-Sokoban/Sokoban.pm (file contents):
Revision 1.7 by root, Wed May 12 00:16:44 2010 UTC vs.
Revision 1.9 by root, Wed May 12 10:47:12 2010 UTC

58sub detect_format($) { 58sub detect_format($) {
59 my ($data) = @_; 59 my ($data) = @_;
60 60
61 return "text" if $data =~ /^[ #\@\*\$\.\+\015\012\-_]+$/; 61 return "text" if $data =~ /^[ #\@\*\$\.\+\015\012\-_]+$/;
62 62
63 warn $data;#d#
64 return "rle" if $data =~ /^[ #\@\*\$\.\+\015\012\-_|1-9]+$/; 63 return "rle" if $data =~ /^[ #\@\*\$\.\+\015\012\-_|1-9]+$/;
65 exit 5;#d#
66 64
67 my ($a, $b) = unpack "ww", $data; 65 my ($a, $b) = unpack "ww", $data;
68 return "binpack" if defined $a && defined $b; 66 return "binpack" if defined $a && defined $b;
69 67
70 Carp::croak "unable to autodetect sokoban level format"; 68 Carp::croak "unable to autodetect sokoban level format";
71} 69}
72 70
73=item $level->data ([$new_data, [$new_data_format]]]) 71=item $level->data ([$new_data, [$new_data_format]])
74 72
75Sets the level from the given data. 73Sets the level from the given data.
76 74
77=cut 75=cut
78 76
119 117
120 } else { 118 } else {
121 Carp::croak "$format: unsupported sokoban level format requested"; 119 Carp::croak "$format: unsupported sokoban level format requested";
122 } 120 }
123 121
122 $self->{format} = $format;
124 $self->update; 123 $self->update;
125 } 124 }
126 125
127 $_[0]{data} 126 $_[0]{data}
128} 127}
162 161
163 "$self->{data}\n" 162 "$self->{data}\n"
164} 163}
165 164
166=item $binary = $level->as_binpack 165=item $binary = $level->as_binpack
166
167Binpack is a very compact binary format (usually 17% of the size of an xsb
168file), that is still reasonably easy to encode/decode.
169
170It only tries to store simplified levels with full fidelity - other levels
171can be slightly changed outside the playable area.
167 172
168=cut 173=cut
169 174
170sub as_binpack { 175sub as_binpack {
171 my ($self) = @_; 176 my ($self) = @_;
389Games::Sokoban objects in an arrayref. 394Games::Sokoban objects in an arrayref.
390 395
391=cut 396=cut
392 397
393sub load_sokevo($) { 398sub load_sokevo($) {
394 open my $fh, "<", $_[0] 399 open my $fh, "<:crlf", $_[0]
395 or Carp::croak "$_[0]: $!"; 400 or Carp::croak "$_[0]: $!";
396 401
397 my @levels; 402 my @levels;
398 403
404 # skip file header
405 local $/ = "\n\n";
406 scalar <$fh>;
407
399 while (<$fh>) { 408 while (<$fh>) {
400 if (/^##+$/) { 409 chomp;
401 my $data = $_; 410 my %meta = split /[:\n]/;
402 while (<$fh>) {
403 $data .= $_;
404 last if /^$/;
405 }
406 411
412 $_ = <$fh>;
413
414 /^##+\n/ or last;
415
407 # sokevo internally locks some cells 416 # sokevo internally locks some cells
408 $data =~ y/^%:,;-=?/ #.$* +#/; 417 y/^%:,;-=?/ #.$* +#/;
409 418
410 push @levels, new Games::Sokoban data => $data; 419 push @levels, new Games::Sokoban data => $_, meta => \%meta;
411 }
412 } 420 }
413 421
414 \@levels 422 \@levels
415} 423}
416 424

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines