… | |
… | |
14 | my $PNGNQ = "@PNGNQ@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
15 | |
15 | |
16 | use Getopt::Long; |
16 | use Getopt::Long; |
17 | use Coro::Event; |
17 | use Coro::Event; |
18 | use AnyEvent; |
18 | use AnyEvent; |
|
|
19 | use YAML::Syck (); |
|
|
20 | use JSON::XS (); |
19 | use IO::AIO (); |
21 | use IO::AIO (); |
20 | use File::Temp; |
22 | use File::Temp; |
21 | use Crossfire; |
23 | use Crossfire; |
22 | use Coro; |
24 | use Coro; |
23 | use Coro::AIO; |
25 | use Coro::AIO; |
… | |
… | |
497 | my ($dir, $file, $type) = @$job; |
499 | my ($dir, $file, $type) = @$job; |
498 | |
500 | |
499 | my $data; |
501 | my $data; |
500 | aio_load "$dir/$file", $data; |
502 | aio_load "$dir/$file", $data; |
501 | |
503 | |
502 | |
|
|
503 | my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
504 | my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
504 | |
505 | |
505 | utf8::decode $dir; |
506 | utf8::decode $dir; |
506 | utf8::decode $file; |
507 | utf8::decode $file; |
507 | |
508 | |
… | |
… | |
530 | $file =~ s/\.res$//; |
531 | $file =~ s/\.res$//; |
531 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
532 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
532 | |
533 | |
533 | substr $dir, 0, 1 + length $PATH, ""; |
534 | substr $dir, 0, 1 + length $PATH, ""; |
534 | |
535 | |
|
|
536 | if (my $filter = $meta->{cfutil_filter}) { |
|
|
537 | if ($filter eq "yaml2json") { |
|
|
538 | $data = JSON::XS::encode_json YAML::Syck::Load $data; |
|
|
539 | } else { |
|
|
540 | warn "$dir/$file: unknown filter $filter, skipping\n"; |
|
|
541 | } |
|
|
542 | } |
|
|
543 | |
535 | $RESOURCE{"$dir/$file"} = { |
544 | $RESOURCE{"$dir/$file"} = { |
536 | type => (delete $meta->{type}) || $type, |
545 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
537 | data => $data, |
546 | data => $data, |
538 | %$meta ? (meta => $meta) : (), |
547 | %$meta ? (meta => $meta) : (), |
539 | }; |
548 | }; |
540 | } |
549 | } |
541 | } |
550 | } |
… | |
… | |
562 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
571 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
563 | $c_res->put ([$path, $file, 5]) # FT_SOUND |
572 | $c_res->put ([$path, $file, 5]) # FT_SOUND |
564 | if $file =~ /\.(wav|ogg)$/; |
573 | if $file =~ /\.(wav|ogg)$/; |
565 | |
574 | |
566 | } elsif ($dir =~ /^res(?:\/|$)/) { |
575 | } elsif ($dir =~ /^res(?:\/|$)/) { |
|
|
576 | if ($file =~ /\.(jpg|png)$/) { |
567 | $c_res->put ([$path, $file, 0]) # FT_FACE |
577 | $c_res->put ([$path, $file, 0]) # FT_FACE |
568 | if $file =~ /\.(jpg|png)$/; |
578 | } elsif ($file =~ /\.(res)$/) { |
569 | $c_res->put ([$path, $file, 7]) # FT_RSRC |
579 | $c_res->put ([$path, $file, 7]) # FT_RSRC |
570 | if $file =~ /\.(res)$/; |
580 | } else { |
|
|
581 | $c_res->put ([$path, $file, undef]); |
|
|
582 | } |
571 | |
583 | |
572 | } elsif ($file =~ /\.png$/) { |
584 | } elsif ($file =~ /\.png$/) { |
573 | push @c_png, ["$path/$file", 0]; |
585 | push @c_png, ["$path/$file", 0]; |
574 | |
586 | |
575 | } elsif ($file =~ /\.trs$/) { |
587 | } elsif ($file =~ /\.trs$/) { |