… | |
… | |
6 | my $exec_prefix = "@exec_prefix@"; |
6 | my $exec_prefix = "@exec_prefix@"; |
7 | my $datarootdir = "@datarootdir@"; |
7 | my $datarootdir = "@datarootdir@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
9 | |
9 | |
10 | my $CONVERT = "@CONVERT@"; |
10 | my $CONVERT = "@CONVERT@"; |
11 | my $IDENTIFY = "@IDENTIFY@"; |
11 | #my $IDENTIFY = "@IDENTIFY@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
13 | my $RSYNC = "@RSYNC@"; |
13 | my $RSYNC = "@RSYNC@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
15 | |
15 | |
16 | use Getopt::Long; |
16 | use Getopt::Long; |
… | |
… | |
43 | my $CACHE = 0; |
43 | my $CACHE = 0; |
44 | my $FORCE; |
44 | my $FORCE; |
45 | my $TMPDIR = "/tmp/cfutil$$~"; |
45 | my $TMPDIR = "/tmp/cfutil$$~"; |
46 | my $TMPFILE = "aaaa0"; |
46 | my $TMPFILE = "aaaa0"; |
47 | |
47 | |
|
|
48 | our %COLOR = ( |
|
|
49 | black => 0, |
|
|
50 | white => 1, |
|
|
51 | navy => 2, |
|
|
52 | red => 3, |
|
|
53 | orange => 4, |
|
|
54 | blue => 5, |
|
|
55 | darkorange => 6, |
|
|
56 | green => 7, |
|
|
57 | lightgreen => 8, |
|
|
58 | grey => 9, |
|
|
59 | brown => 10, |
|
|
60 | gold => 11, |
|
|
61 | tan => 12, |
|
|
62 | ); |
|
|
63 | |
48 | END { system "rm", "-rf", $TMPDIR } |
64 | END { system "rm", "-rf", $TMPDIR } |
49 | |
65 | |
50 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
66 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
51 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
67 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
52 | |
68 | |
… | |
… | |
85 | } |
101 | } |
86 | |
102 | |
87 | { |
103 | { |
88 | our %ANIMINFO; |
104 | our %ANIMINFO; |
89 | our %FACEINFO; |
105 | our %FACEINFO; |
|
|
106 | our %RESOURCE; |
90 | our @ARC; |
107 | our @ARC; |
91 | our %ARC; |
108 | our %ARC; |
92 | our $TRS; |
109 | our $TRS; |
93 | our $NFILE; |
110 | our $NFILE; |
|
|
111 | our $PATH; |
94 | |
112 | |
95 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
113 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
96 | |
114 | |
97 | our (@png, @trs, @arc); # files we are interested in |
115 | our (@png, @trs, @arc, @res); # files we are interested in |
98 | |
116 | |
99 | sub commit_png($$$) { |
117 | sub commit_png($$$) { |
100 | my ($name, $data, $T) = @_; |
118 | my ($name, $data, $T) = @_; |
101 | |
119 | |
102 | $FACEINFO{$name}{"data$T"} = $data; |
120 | $FACEINFO{$name}{"data$T"} = $data; |
… | |
… | |
301 | |
319 | |
302 | my $ext = $x|$y ? "+$x+$y" : ""; |
320 | my $ext = $x|$y ? "+$x+$y" : ""; |
303 | |
321 | |
304 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
322 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
305 | |
323 | |
306 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
324 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
307 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
325 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
308 | |
326 | |
309 | my $anim = delete $o->{anim}; |
327 | my $anim = delete $o->{anim}; |
310 | |
328 | |
311 | if ($anim) { |
329 | if ($anim) { |
312 | # possibly add $ext to the animation name to avoid |
330 | # possibly add $ext to the animation name to avoid |
… | |
… | |
367 | |
385 | |
368 | $TRS .= $trs; |
386 | $TRS .= $trs; |
369 | } |
387 | } |
370 | } |
388 | } |
371 | |
389 | |
|
|
390 | sub process_res { |
|
|
391 | while (@res) { |
|
|
392 | my ($dir, $file) = @{pop @res}; |
|
|
393 | |
|
|
394 | my $data; |
|
|
395 | aio_load "$dir/$file", $data; |
|
|
396 | |
|
|
397 | $file =~ s/\.res$//; |
|
|
398 | $file =~ /\.([^.]+)$/ |
|
|
399 | or next; |
|
|
400 | |
|
|
401 | my $type = $1; |
|
|
402 | |
|
|
403 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
404 | |
|
|
405 | $RESOURCE{"$dir/$file"} = { |
|
|
406 | type => $1, |
|
|
407 | copyright => "", # TODO |
|
|
408 | data => $data, |
|
|
409 | chksum => Digest::MD5::md5 $data, |
|
|
410 | }; |
|
|
411 | } |
|
|
412 | } |
|
|
413 | |
372 | sub find_files; |
414 | sub find_files; |
373 | sub find_files { |
415 | sub find_files { |
374 | my ($path) = @_; |
416 | my ($path) = @_; |
375 | |
417 | |
376 | IO::AIO::aioreq_pri 4; |
418 | IO::AIO::aioreq_pri 4; |
… | |
… | |
385 | push @png, ["$path/$file", 0]; |
427 | push @png, ["$path/$file", 0]; |
386 | } elsif ($file =~ /\.trs$/) { |
428 | } elsif ($file =~ /\.trs$/) { |
387 | push @trs, [$path, $file]; |
429 | push @trs, [$path, $file]; |
388 | } elsif ($file =~ /\.arc$/) { |
430 | } elsif ($file =~ /\.arc$/) { |
389 | push @arc, [$path, $file]; |
431 | push @arc, [$path, $file]; |
|
|
432 | } elsif ($file =~ /\.(ogg|res)$/) { |
|
|
433 | push @res, [$path, $file]; |
390 | } else { |
434 | } else { |
391 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
435 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
392 | } |
436 | } |
393 | } |
437 | } |
394 | }; |
438 | }; |
395 | } |
439 | } |
396 | |
440 | |
397 | sub inst_arch($) { |
441 | sub inst_arch($) { |
398 | my (undef, $path) = @_; |
442 | my (undef, $path) = @_; |
|
|
443 | |
|
|
444 | $PATH = $path; |
399 | |
445 | |
400 | print "\n", |
446 | print "\n", |
401 | "Installing '$path' to '$DATADIR'\n", |
447 | "Installing '$path' to '$DATADIR'\n", |
402 | "\n", |
448 | "\n", |
403 | "This can take a long time if you run this\n", |
449 | "This can take a long time if you run this\n", |
… | |
… | |
418 | $_->join for ( |
464 | $_->join for ( |
419 | # four png crunchers work fine for my 2x smp machine |
465 | # four png crunchers work fine for my 2x smp machine |
420 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
466 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
421 | (async \&process_trs), (async \&process_trs), |
467 | (async \&process_trs), (async \&process_trs), |
422 | (async \&process_arc), (async \&process_arc), |
468 | (async \&process_arc), (async \&process_arc), |
|
|
469 | (async \&process_res), (async \&process_res), |
423 | ); |
470 | ); |
424 | |
471 | |
425 | { |
472 | { |
426 | # remove path prefix from editor_folder |
473 | # remove path prefix from editor_folder |
427 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
474 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
… | |
… | |
457 | |
504 | |
458 | last; |
505 | last; |
459 | } |
506 | } |
460 | } |
507 | } |
461 | |
508 | |
|
|
509 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
|
|
510 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
|
|
511 | |
462 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
512 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
463 | or die "$DATADIR/archetypes~: $!"; |
513 | or die "$DATADIR/archetypes~: $!"; |
464 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
514 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
465 | } |
515 | } |
466 | |
516 | |
… | |
… | |
478 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
528 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
479 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
529 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
480 | |
530 | |
481 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
531 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
482 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
532 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
|
|
533 | |
|
|
534 | if (my $magicmap = $v->{magicmap}) { |
|
|
535 | $magicmap =~ y/A-Z_\-/a-z/d; |
|
|
536 | $v->{magicmap} = $COLOR{$magicmap}; |
|
|
537 | } |
483 | } |
538 | } |
484 | |
539 | |
485 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
540 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
486 | or die "$DATADIR/facedata~: $!"; |
541 | or die "$DATADIR/facedata~: $!"; |
487 | |
542 | |
488 | print $fh freeze { |
543 | print $fh freeze { |
489 | version => 2, |
544 | version => 2, |
490 | faceinfo => \%FACEINFO, |
545 | faceinfo => \%FACEINFO, |
491 | animinfo => \%ANIMINFO, |
546 | animinfo => \%ANIMINFO, |
|
|
547 | resource => \%RESOURCE, |
492 | }; |
548 | }; |
493 | } |
549 | } |
494 | |
550 | |
495 | for (qw(archetypes facedata treasures)) { |
551 | for (qw(archetypes facedata treasures)) { |
496 | chmod 0644, "$DATADIR/$_~"; |
552 | chmod 0644, "$DATADIR/$_~"; |