… | |
… | |
20 | # <http://www.gnu.org/licenses/>. |
20 | # <http://www.gnu.org/licenses/>. |
21 | # |
21 | # |
22 | # The authors can be reached via e-mail to <support@deliantra.net> |
22 | # The authors can be reached via e-mail to <support@deliantra.net> |
23 | # |
23 | # |
24 | |
24 | |
25 | use strict; |
25 | use common::sense; |
26 | |
26 | |
27 | my $prefix = "@prefix@"; |
27 | my $prefix = "@prefix@"; |
28 | my $exec_prefix = "@exec_prefix@"; |
28 | my $exec_prefix = "@exec_prefix@"; |
29 | my $datarootdir = "@datarootdir@"; |
29 | my $datarootdir = "@datarootdir@"; |
30 | my $DATADIR = "@datadir@/@PACKAGE@"; |
30 | my $DATADIR = "@datadir@/@PACKAGE@"; |
… | |
… | |
74 | my $VERBOSE = 1; |
74 | my $VERBOSE = 1; |
75 | my $CACHE = 0; |
75 | my $CACHE = 0; |
76 | my $FORCE; |
76 | my $FORCE; |
77 | my $TMPDIR = "/tmp/cfutil$$~"; |
77 | my $TMPDIR = "/tmp/cfutil$$~"; |
78 | my $TMPFILE = "aaaa0"; |
78 | my $TMPFILE = "aaaa0"; |
|
|
79 | my @COMMIT; |
79 | |
80 | |
80 | our %COLOR = ( |
81 | our %COLOR = ( |
81 | black => 0, |
82 | black => 0, |
82 | white => 1, |
83 | white => 1, |
83 | navy => 2, |
84 | navy => 2, |
… | |
… | |
105 | my ($id, $dataref, $hashref, $clen) = @_; |
106 | my ($id, $dataref, $hashref, $clen) = @_; |
106 | |
107 | |
107 | my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; |
108 | my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; |
108 | |
109 | |
109 | if (exists $hash{$hash}) { |
110 | if (exists $hash{$hash}) { |
110 | # hahs collinion, but some files are simply identical |
111 | # hash collision, but some files are simply identical |
111 | if (${$hash{$hash}[1]} ne $$dataref) { |
112 | if (${$hash{$hash}[1]} ne $$dataref) { |
112 | warn "hash collision $hash{$hash}[0] vs. $id\n"; |
113 | warn "hash collision $hash{$hash}[0] vs. $id\n"; |
113 | exit 1; |
114 | exit 1; |
114 | } else { |
115 | } else { |
115 | print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; |
116 | print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; |
… | |
… | |
155 | and die "map installation failed.\n"; |
156 | and die "map installation failed.\n"; |
156 | |
157 | |
157 | print "maps installed successfully.\n"; |
158 | print "maps installed successfully.\n"; |
158 | } |
159 | } |
159 | |
160 | |
|
|
161 | our %WALL_SUFFIX = ( |
|
|
162 | "_0" => "⬤", |
|
|
163 | "_1_3" => "╸", |
|
|
164 | "_1_4" => "╺", |
|
|
165 | "_2_1_2" => "━", |
|
|
166 | |
|
|
167 | "_1_2" => "╹", |
|
|
168 | "_2_2_4" => "┛", |
|
|
169 | "_2_2_1" => "┗", |
|
|
170 | "_3_1" => "┻", |
|
|
171 | |
|
|
172 | "_1_1" => "╻", |
|
|
173 | "_2_2_3" => "┓", |
|
|
174 | "_2_2_2" => "┏", |
|
|
175 | "_3_3" => "┳", |
|
|
176 | |
|
|
177 | "_2_1_1" => "┃", |
|
|
178 | "_3_4" => "┫", |
|
|
179 | "_3_2" => "┣", |
|
|
180 | "_4" => "╋", |
|
|
181 | ); |
|
|
182 | |
|
|
183 | sub autoglyph { |
|
|
184 | my ($stem, $face) = @_; |
|
|
185 | |
|
|
186 | if ($stem =~ /^wall\/|Nimwall/) { |
|
|
187 | if ($stem =~ /((?:_[0-4])+).x11/) { |
|
|
188 | return $WALL_SUFFIX{$1} if exists $WALL_SUFFIX{$1}; |
|
|
189 | } |
|
|
190 | |
|
|
191 | "+" |
|
|
192 | |
|
|
193 | } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) { |
|
|
194 | "." |
|
|
195 | |
|
|
196 | } elsif ($stem =~ /^player\//) { |
|
|
197 | "\@" |
|
|
198 | |
|
|
199 | } else { |
|
|
200 | substr $stem, 0, 1 |
|
|
201 | } |
|
|
202 | } |
|
|
203 | |
160 | { |
204 | { |
161 | our %ANIMINFO; |
205 | our %ANIMINFO; |
162 | our %FACEINFO; |
206 | our %FACEINFO; |
163 | our %RESOURCE; |
207 | our %RESOURCE; |
164 | our @ARC; |
208 | our @ARC; |
… | |
… | |
173 | our $c_trs = new Coro::Channel; |
217 | our $c_trs = new Coro::Channel; |
174 | our $c_res = new Coro::Channel; |
218 | our $c_res = new Coro::Channel; |
175 | |
219 | |
176 | our @c_png; |
220 | our @c_png; |
177 | |
221 | |
178 | sub commit_png($$$) { |
222 | sub commit_png($$$$) { |
179 | my ($name, $data, $T) = @_; |
223 | my ($stem, $name, $data, $T) = @_; |
180 | |
224 | |
|
|
225 | $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH; |
181 | $FACEINFO{$name}{"data$T"} = $data; |
226 | $FACEINFO{$name}{"data$T"} = $data; |
182 | } |
227 | } |
183 | |
228 | |
184 | sub process_png { |
229 | sub process_png { |
185 | while (@c_png) { |
230 | while (@c_png) { |
… | |
… | |
403 | |
448 | |
404 | if (0 > aio_load $file, $tile) { |
449 | if (0 > aio_load $file, $tile) { |
405 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
450 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
406 | } |
451 | } |
407 | IO::AIO::aio_unlink $file unless $CACHE; |
452 | IO::AIO::aio_unlink $file unless $CACHE; |
408 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
453 | commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
409 | } |
454 | } |
410 | } else { |
455 | } else { |
411 | # use as-is (either small, use smooth) |
456 | # use as-is (either small, use smooth) |
412 | commit_png $face, $png, $T; |
457 | commit_png $stem, $face, $png, $T; |
413 | } |
458 | } |
414 | |
459 | |
415 | aio_unlink $path if $delete; |
460 | aio_unlink $path if $delete; |
416 | } |
461 | } |
417 | } |
462 | } |
… | |
… | |
432 | |
477 | |
433 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
478 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
434 | |
479 | |
435 | my $visibility = delete $o->{visibility}; |
480 | my $visibility = delete $o->{visibility}; |
436 | my $magicmap = delete $o->{magicmap}; |
481 | my $magicmap = delete $o->{magicmap}; |
|
|
482 | my $glyph = delete $o->{glyph}; |
437 | |
483 | |
438 | # find upper left corner :/ |
484 | # find upper left corner :/ |
439 | # omg, this is sooo broken |
485 | # omg, this is sooo broken |
440 | my ($dx, $dy); |
486 | my ($dx, $dy); |
441 | for (my $o = $o; $o; $o = $o->{more}) { |
487 | for (my $o = $o; $o; $o = $o->{more}) { |
… | |
… | |
451 | |
497 | |
452 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
498 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
453 | |
499 | |
454 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
500 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
455 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
501 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
|
|
502 | $glyph = delete $o->{glyph} if exists $o->{glyph}; |
456 | |
503 | |
457 | my $anim = delete $o->{anim}; |
504 | my $anim = delete $o->{anim}; |
458 | |
505 | |
459 | if ($anim) { |
506 | if ($anim) { |
460 | # possibly add $ext to the animation name to avoid |
507 | # possibly add $ext to the animation name to avoid |
… | |
… | |
491 | |
538 | |
492 | next if $face =~ /^blank.x11$|^empty.x11$/; |
539 | next if $face =~ /^blank.x11$|^empty.x11$/; |
493 | |
540 | |
494 | $info->{visibility} = $visibility if defined $visibility; |
541 | $info->{visibility} = $visibility if defined $visibility; |
495 | $info->{magicmap} = $magicmap if defined $magicmap; |
542 | $info->{magicmap} = $magicmap if defined $magicmap; |
|
|
543 | $info->{glyph} = $glyph if defined $glyph; |
496 | } |
544 | } |
497 | |
545 | |
498 | if (my $smooth = delete $o->{smoothface}) { |
546 | if (my $smooth = delete $o->{smoothface}) { |
499 | my %kv = split /\s+/, $smooth; |
547 | my %kv = split /\s+/, $smooth; |
500 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
548 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
… | |
… | |
569 | if ($meta->{license} =~ s/^#//) { |
617 | if ($meta->{license} =~ s/^#//) { |
570 | $meta->{license} = ({ |
618 | $meta->{license} = ({ |
571 | "pd" => "Public Domain", |
619 | "pd" => "Public Domain", |
572 | "gpl" => "GNU General Public License, version 3.0 or any later", |
620 | "gpl" => "GNU General Public License, version 3.0 or any later", |
573 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
621 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
|
|
622 | "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/", |
574 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
623 | "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
575 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
624 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
576 | })->{$meta->{license}} |
625 | })->{$meta->{license}} |
577 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
626 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
|
|
627 | } |
|
|
628 | |
|
|
629 | if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { |
|
|
630 | ($meta->{author} = $1) =~ s/_/ /g; |
578 | } |
631 | } |
579 | |
632 | |
580 | $file =~ s/\.res$//; |
633 | $file =~ s/\.res$//; |
581 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
634 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
582 | |
635 | |
… | |
… | |
733 | while () { |
786 | while () { |
734 | my $progress; |
787 | my $progress; |
735 | my $loop; |
788 | my $loop; |
736 | |
789 | |
737 | for my $o (values %ARC) { |
790 | for my $o (values %ARC) { |
738 | if (my $other = $o->{inherit}) { |
791 | for my $other (split /,/, $o->{inherit}) { |
739 | if (my $s = $ARC{$other}) { |
792 | if (my $s = $ARC{$other}) { |
740 | if ($s->{inherit}) { |
793 | if ($s->{inherit}) { |
741 | $loop = $s; |
794 | $loop = $s; |
742 | } else { |
795 | } else { |
743 | delete $o->{inherit}; |
796 | delete $o->{inherit}; |
… | |
… | |
795 | if (my $magicmap = $v->{magicmap}) { |
848 | if (my $magicmap = $v->{magicmap}) { |
796 | $magicmap =~ y/A-Z_\-/a-z/d; |
849 | $magicmap =~ y/A-Z_\-/a-z/d; |
797 | $v->{magicmap} = $COLOR{$magicmap}; |
850 | $v->{magicmap} = $COLOR{$magicmap}; |
798 | } |
851 | } |
799 | |
852 | |
|
|
853 | my $stem = delete $v->{stem}; |
|
|
854 | $v->{glyph} //= autoglyph $stem, $v; |
|
|
855 | utf8::encode $v->{glyph}; |
|
|
856 | $v->{glyph} = (chr $v->{magicmap}) . $v->{glyph}; |
|
|
857 | |
800 | delete $v->{arc}; |
858 | delete $v->{arc}; |
801 | } |
859 | } |
802 | |
860 | |
803 | print "processing resources...\n" if $VERBOSE; |
861 | print "processing resources...\n" if $VERBOSE; |
804 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
862 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
805 | while (my ($k, $v) = each %RESOURCE) { |
863 | while (my ($k, $v) = each %RESOURCE) { |
806 | |
864 | |
|
|
865 | if ($v->{meta} && $v->{meta}{datadir}) { |
|
|
866 | delete $RESOURCE{$k}; |
|
|
867 | |
|
|
868 | $k =~ s/^res\/// or die "$k: datadir files must be in res/"; |
|
|
869 | |
|
|
870 | printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE; |
|
|
871 | open my $fh, ">:raw", "$DATADIR/$k~" |
|
|
872 | or die "$DATADIR/$k~: $!"; |
|
|
873 | syswrite $fh, $v->{data}; |
|
|
874 | push @COMMIT, $k; |
|
|
875 | |
|
|
876 | } else { |
807 | if ($v->{type} & 1) { |
877 | if ($v->{type} & 1) { |
808 | # prepend meta info |
878 | # prepend meta info |
809 | |
879 | |
810 | my $meta = $enc->encode ({ |
880 | my $meta = $enc->encode ({ |
811 | name => $k, |
881 | name => $k, |
812 | %{ $v->{meta} || {} }, |
882 | %{ $v->{meta} || {} }, |
813 | }); |
883 | }); |
814 | |
884 | |
815 | $v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
885 | $v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
816 | } |
886 | } |
817 | |
887 | |
818 | make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
888 | make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
|
|
889 | } |
819 | } |
890 | } |
820 | |
891 | |
821 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
892 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
822 | scalar keys %FACEINFO, |
893 | scalar keys %FACEINFO, |
823 | scalar keys %ANIMINFO, |
894 | scalar keys %ANIMINFO, |
… | |
… | |
825 | if $VERBOSE; |
896 | if $VERBOSE; |
826 | |
897 | |
827 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
898 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
828 | or die "$DATADIR/facedata~: $!"; |
899 | or die "$DATADIR/facedata~: $!"; |
829 | |
900 | |
830 | print $fh freeze { |
901 | print $fh nfreeze { |
831 | version => 2, |
902 | version => 2, |
832 | faceinfo => \%FACEINFO, |
903 | faceinfo => \%FACEINFO, |
833 | animinfo => \%ANIMINFO, |
904 | animinfo => \%ANIMINFO, |
834 | resource => \%RESOURCE, |
905 | resource => \%RESOURCE, |
835 | }; |
906 | }; |
836 | |
907 | |
837 | } |
908 | } |
838 | |
909 | |
839 | print "committing files...\n" if $VERBOSE; |
910 | print "committing files...\n" if $VERBOSE; |
840 | |
911 | |
841 | for (qw(archetypes facedata treasures)) { |
912 | for (qw(archetypes facedata treasures), @COMMIT) { |
842 | chmod 0644, "$DATADIR/$_~"; |
913 | chmod 0644, "$DATADIR/$_~"; |
843 | rename "$DATADIR/$_~", "$DATADIR/$_" |
914 | rename "$DATADIR/$_~", "$DATADIR/$_" |
844 | or die "$DATADIR/$_: $!"; |
915 | or die "$DATADIR/$_: $!"; |
845 | } |
916 | } |
846 | |
917 | |