… | |
… | |
394 | |
394 | |
395 | sub load_cached($;$) { |
395 | sub load_cached($;$) { |
396 | unless (exists $FILECACHE{$_[0]}) { |
396 | unless (exists $FILECACHE{$_[0]}) { |
397 | my $data; |
397 | my $data; |
398 | if (0 < aio_load $_[0], $data) { |
398 | if (0 < aio_load $_[0], $data) { |
|
|
399 | if ($_[1]) { |
399 | $data = $_[1]->($data) |
400 | $data = eval { $_[1]->($data) }; |
400 | if $_[1]; |
401 | warn "$_[0]: $@" if $@; |
|
|
402 | } |
401 | } |
403 | } |
402 | |
404 | |
403 | $FILECACHE{$_[0]} = $data; |
405 | $FILECACHE{$_[0]} = $data; |
404 | } |
406 | } |
405 | |
407 | |
… | |
… | |
413 | my $data; |
415 | my $data; |
414 | aio_load "$dir/$file", $data; |
416 | aio_load "$dir/$file", $data; |
415 | |
417 | |
416 | my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; |
418 | my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; |
417 | |
419 | |
418 | $file =~ s/\.res$//; |
420 | return if $meta && !exists $meta->{$file}; |
419 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
|
|
420 | |
|
|
421 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
422 | |
421 | |
423 | $meta = { |
422 | $meta = { |
424 | %{ $meta->{"" } || {} }, |
423 | %{ $meta->{"" } || {} }, |
425 | %{ $meta->{$file} || {} }, |
424 | %{ $meta->{$file} || {} }, |
426 | }; |
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 | } |
|
|
437 | |
|
|
438 | $file =~ s/\.res$//; |
|
|
439 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
|
|
440 | |
|
|
441 | substr $dir, 0, 1 + length $PATH, ""; |
427 | |
442 | |
428 | $RESOURCE{"$dir/$file"} = { |
443 | $RESOURCE{"$dir/$file"} = { |
429 | type => (delete $meta->{type}) || $type, |
444 | type => (delete $meta->{type}) || $type, |
430 | data => $data, |
445 | data => $data, |
431 | chksum => (Digest::MD5::md5 $data), |
446 | chksum => (Digest::MD5::md5 $data), |
… | |
… | |
451 | for my $file (@$nondirs) { |
466 | for my $file (@$nondirs) { |
452 | if ($dir =~ /^music(?:\/|$)/) { |
467 | if ($dir =~ /^music(?:\/|$)/) { |
453 | push @res, [$path, $file, 3] # FT_MUSIC |
468 | push @res, [$path, $file, 3] # FT_MUSIC |
454 | if $file =~ /\.(ogg)$/; |
469 | if $file =~ /\.(ogg)$/; |
455 | |
470 | |
456 | } elsif ($dir =~ /^sounds(?:\/|$)/) { |
471 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
457 | push @res, [$path, $file, 5] # FT_SOUND |
472 | push @res, [$path, $file, 5] # FT_SOUND |
458 | if $file =~ /\.(wav|ogg)$/; |
473 | if $file =~ /\.(wav|ogg)$/; |
459 | |
474 | |
460 | } elsif ($dir =~ /^res(?:\/|$)/) { |
475 | } elsif ($dir =~ /^res(?:\/|$)/) { |
461 | push @res, [$path, $file, 0] # FT_FACE |
476 | push @res, [$path, $file, 0] # FT_FACE |