… | |
… | |
388 | |
388 | |
389 | $TRS .= $trs; |
389 | $TRS .= $trs; |
390 | } |
390 | } |
391 | } |
391 | } |
392 | |
392 | |
|
|
393 | my %FILECACHE; |
|
|
394 | |
|
|
395 | sub load_cached($;$) { |
|
|
396 | unless (exists $FILECACHE{$_[0]}) { |
|
|
397 | my $data; |
|
|
398 | if (0 < aio_load $_[0], $data) { |
|
|
399 | if ($_[1]) { |
|
|
400 | $data = eval { $_[1]->($data) }; |
|
|
401 | warn "$_[0]: $@" if $@; |
|
|
402 | } |
|
|
403 | } |
|
|
404 | |
|
|
405 | $FILECACHE{$_[0]} = $data; |
|
|
406 | } |
|
|
407 | |
|
|
408 | $FILECACHE{$_[0]} |
|
|
409 | } |
|
|
410 | |
393 | sub process_res { |
411 | sub process_res { |
394 | while (@res) { |
412 | while (@res) { |
395 | my ($dir, $file, $type) = @{pop @res}; |
413 | my ($dir, $file, $type) = @{pop @res}; |
396 | |
414 | |
397 | my $data; |
415 | my $data; |
398 | aio_load "$dir/$file", $data; |
416 | aio_load "$dir/$file", $data; |
399 | |
417 | |
400 | my $copyright; |
418 | my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; |
401 | aio_load "$dir/copyright", $copyright; |
419 | |
|
|
420 | return if $meta && !exists $meta->{$file}; |
|
|
421 | |
|
|
422 | $meta = { |
|
|
423 | %{ $meta->{"" } || {} }, |
|
|
424 | %{ $meta->{$file} || {} }, |
|
|
425 | }; |
|
|
426 | |
|
|
427 | if ($meta->{license} =~ s/^#//) { |
|
|
428 | $meta->{license} = ({ |
|
|
429 | "pd" => "Public Domain", |
|
|
430 | "gpl" => "GNU General Public License, version 3.0 or any later", |
|
|
431 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
|
|
432 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.5/", |
|
|
433 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
|
|
434 | })->{$meta->{license}} |
|
|
435 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
|
|
436 | } |
402 | |
437 | |
403 | $file =~ s/\.res$//; |
438 | $file =~ s/\.res$//; |
404 | $file =~ /\.([^.]+)$/ |
439 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
405 | or next; |
|
|
406 | |
440 | |
407 | substr $dir, 0, 1 + length $PATH, ""; |
441 | substr $dir, 0, 1 + length $PATH, ""; |
408 | |
442 | |
409 | $RESOURCE{"$dir/$file"} = { |
443 | $RESOURCE{"$dir/$file"} = { |
410 | type => $type, |
444 | type => (delete $meta->{type}) || $type, |
411 | copyright => $copyright, |
|
|
412 | data => $data, |
445 | data => $data, |
413 | chksum => Digest::MD5::md5 $data, |
446 | chksum => (Digest::MD5::md5 $data), |
|
|
447 | %$meta ? (meta => $meta) : (), |
414 | }; |
448 | }; |
415 | } |
449 | } |
416 | } |
450 | } |
417 | |
451 | |
418 | sub find_files; |
452 | sub find_files; |
… | |
… | |
432 | for my $file (@$nondirs) { |
466 | for my $file (@$nondirs) { |
433 | if ($dir =~ /^music(?:\/|$)/) { |
467 | if ($dir =~ /^music(?:\/|$)/) { |
434 | push @res, [$path, $file, 3] # FT_MUSIC |
468 | push @res, [$path, $file, 3] # FT_MUSIC |
435 | if $file =~ /\.(ogg)$/; |
469 | if $file =~ /\.(ogg)$/; |
436 | |
470 | |
437 | } elsif ($dir =~ /^sounds(?:\/|$)/) { |
471 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
438 | push @res, [$path, $file, 5] # FT_SOUND |
472 | push @res, [$path, $file, 5] # FT_SOUND |
439 | if $file =~ /\.(wav|ogg)$/; |
473 | if $file =~ /\.(wav|ogg)$/; |
440 | |
474 | |
441 | } elsif ($dir =~ /^res(?:\/|$)/) { |
475 | } elsif ($dir =~ /^res(?:\/|$)/) { |
442 | push @res, [$path, $file, 0] # FT_FACE |
476 | push @res, [$path, $file, 0] # FT_FACE |