… | |
… | |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
15 | use Carp (); |
15 | use Carp (); |
16 | use Storable; |
16 | use Storable; |
|
|
17 | use File::Spec; |
17 | use List::Util qw(min max); |
18 | use List::Util qw(min max); |
18 | |
19 | |
19 | #XXX: The map_* procedures scream for a map-object |
20 | #XXX: The map_* procedures scream for a map-object |
20 | |
21 | |
21 | our @EXPORT = |
22 | our @EXPORT = |
… | |
… | |
24 | our $LIB = $ENV{CROSSFIRE_LIBDIR} |
25 | our $LIB = $ENV{CROSSFIRE_LIBDIR} |
25 | or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n"; |
26 | or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n"; |
26 | |
27 | |
27 | sub TILESIZE (){ 32 } |
28 | sub TILESIZE (){ 32 } |
28 | |
29 | |
29 | our $CACHEDIR; |
30 | our $VARDIR; |
30 | our %ARCH; |
31 | our %ARCH; |
31 | our %FACE; |
32 | our %FACE; |
32 | our $TILE; |
33 | our $TILE; |
33 | |
34 | |
34 | our %FIELD_MULTILINE = ( |
35 | our %FIELD_MULTILINE = ( |
… | |
… | |
112 | sub read_pak($;$) { |
113 | sub read_pak($;$) { |
113 | my ($path, $cache) = @_; |
114 | my ($path, $cache) = @_; |
114 | |
115 | |
115 | eval { |
116 | eval { |
116 | defined $cache |
117 | defined $cache |
|
|
118 | && -e $cache |
117 | && -M $cache < -M $path |
119 | && -M $cache < -M $path |
118 | && Storable::retrieve $cache |
120 | && Storable::retrieve ($cache) |
119 | } or do { |
121 | } or do { |
120 | my %pak; |
122 | my %pak; |
121 | |
123 | |
122 | open my $fh, "<:raw", $path |
124 | open my $fh, "<:raw", $path |
123 | or Carp::croak "$_[0]: $!"; |
125 | or Carp::croak "$_[0]: $!"; |
… | |
… | |
125 | my ($type, $id, $len, $path) = split; |
127 | my ($type, $id, $len, $path) = split; |
126 | $path =~ s/.*\///; |
128 | $path =~ s/.*\///; |
127 | read $fh, $pak{$path}, $len; |
129 | read $fh, $pak{$path}, $len; |
128 | } |
130 | } |
129 | |
131 | |
130 | Storable::nstore \%pak, $cache |
132 | Storable::nstore (\%pak, $cache) |
131 | if defined $cache; |
133 | if defined $cache; |
132 | |
134 | |
133 | \%pak |
135 | \%pak |
134 | } |
136 | } |
135 | } |
137 | } |
… | |
… | |
137 | sub read_arch($;$) { |
139 | sub read_arch($;$) { |
138 | my ($path, $cache) = @_; |
140 | my ($path, $cache) = @_; |
139 | |
141 | |
140 | eval { |
142 | eval { |
141 | defined $cache |
143 | defined $cache |
|
|
144 | && -e $cache |
142 | && -M $cache < -M $path |
145 | && -M $cache < -M $path |
143 | && Storable::retrieve $cache |
146 | && Storable::retrieve ($cache) |
144 | } or do { |
147 | } or do { |
145 | my %arc; |
148 | my %arc; |
146 | my ($more, $prev); |
149 | my ($more, $prev); |
147 | |
150 | |
148 | open my $fh, "<:raw", $path |
151 | open my $fh, "<:raw", $path |
… | |
… | |
203 | } |
206 | } |
204 | } |
207 | } |
205 | |
208 | |
206 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
209 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
207 | |
210 | |
|
|
211 | warn "hoi\n";#d# |
208 | Storable::nstore \%arc, $cache |
212 | Storable::nstore (\%arc, $cache) |
209 | if defined $cache; |
213 | if defined $cache; |
|
|
214 | warn "hox\n";#d# |
210 | |
215 | |
211 | \%arc |
216 | \%arc |
212 | } |
217 | } |
213 | } |
218 | } |
214 | |
219 | |
… | |
… | |
264 | # single face |
269 | # single face |
265 | return (0, 0, 0, 0); |
270 | return (0, 0, 0, 0); |
266 | } |
271 | } |
267 | } |
272 | } |
268 | |
273 | |
269 | sub init($) { |
|
|
270 | my ($cachedir) = @_; |
|
|
271 | |
|
|
272 | return if %ARCH; |
|
|
273 | |
|
|
274 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
|
|
275 | } |
|
|
276 | |
|
|
277 | =item $data = arch_attr $arch |
274 | =item $type = arch_attr $arch |
278 | |
275 | |
279 | Returns a hashref describing the object and its attributes. It can contain |
276 | Returns a hashref describing the object and its attributes. It can contain |
280 | the following keys: |
277 | the following keys: |
281 | |
278 | |
282 | name the name, suitable for display purposes |
279 | name the name, suitable for display purposes |
283 | ignore |
280 | ignore |
284 | attr |
281 | attr |
285 | desc |
282 | desc |
286 | use |
283 | use |
287 | section => [name => \%attr, name => \%attr] |
284 | section => [name => \%attr, name => \%attr] |
|
|
285 | import |
288 | |
286 | |
289 | =cut |
287 | =cut |
290 | |
288 | |
291 | sub arch_attr($) { |
289 | sub arch_attr($) { |
292 | my ($arch) = @_; |
290 | my ($arch) = @_; |
… | |
… | |
312 | |
310 | |
313 | $attr = $_; |
311 | $attr = $_; |
314 | } |
312 | } |
315 | } |
313 | } |
316 | |
314 | |
317 | use PApp::Util; |
315 | $attr || \%Crossfire::Data::DEFAULT_ATTR; |
318 | warn PApp::Util::dumpval $attr; |
|
|
319 | } |
316 | } |
320 | |
317 | |
321 | sub arch_edit_sections { |
318 | sub arch_edit_sections { |
322 | # if (edit_type == IGUIConstants.TILE_EDIT_NONE) |
319 | # if (edit_type == IGUIConstants.TILE_EDIT_NONE) |
323 | # edit_type = 0; |
320 | # edit_type = 0; |
… | |
… | |
377 | # return(edit_type); |
374 | # return(edit_type); |
378 | # |
375 | # |
379 | # |
376 | # |
380 | } |
377 | } |
381 | |
378 | |
382 | $CACHEDIR ||= "$ENV{HOME}/.crossfire"; |
379 | sub init($) { |
|
|
380 | my ($cachedir) = @_; |
383 | |
381 | |
|
|
382 | return if %ARCH; |
|
|
383 | |
|
|
384 | mkdir $cachedir, 0777; |
|
|
385 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
|
|
386 | } |
|
|
387 | |
|
|
388 | $VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir; |
|
|
389 | |
384 | init $CACHEDIR; |
390 | init $VARDIR; |
385 | |
391 | |
386 | =head1 AUTHOR |
392 | =head1 AUTHOR |
387 | |
393 | |
388 | Marc Lehmann <schmorp@schmorp.de> |
394 | Marc Lehmann <schmorp@schmorp.de> |
389 | http://home.schmorp.de/ |
395 | http://home.schmorp.de/ |