… | |
… | |
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 = qw(⬤ ╹ ╺ ┗ ╻ ┃ ┏ ┣ ╸ ┛ ━ ┻ ┓ ┫ ┳ ╋); |
|
|
162 | |
|
|
163 | # used to create crude text glyphs for text-based clients |
|
|
164 | sub autoglyph { |
|
|
165 | my ($stem, $face) = @_; |
|
|
166 | |
|
|
167 | if ($stem =~ /^wall\/|Nimwall/) { |
|
|
168 | return $WALL_SUFFIX[hex $1] |
|
|
169 | if $stem =~ /(_[0-9A-F]).x11/; |
|
|
170 | |
|
|
171 | "█" |
|
|
172 | |
|
|
173 | } elsif ($stem =~ /^traps\//) { |
|
|
174 | "☠" |
|
|
175 | |
|
|
176 | } elsif ($stem =~ /^armour\/shield/) { |
|
|
177 | "Ø" |
|
|
178 | |
|
|
179 | } elsif ($stem =~ /^armour\//) { |
|
|
180 | "A" |
|
|
181 | |
|
|
182 | } elsif ($stem =~ /^weapon\//) { |
|
|
183 | "†" |
|
|
184 | |
|
|
185 | } elsif ($stem =~ /^readable\//) { |
|
|
186 | "✉" |
|
|
187 | |
|
|
188 | } elsif ($stem =~ /^river\//) { |
|
|
189 | "~" |
|
|
190 | |
|
|
191 | } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) { |
|
|
192 | "·" |
|
|
193 | |
|
|
194 | } elsif ($stem =~ /^spells\//) { |
|
|
195 | "!" |
|
|
196 | |
|
|
197 | } elsif ($stem =~ /^exit\//) { |
|
|
198 | "⎆" |
|
|
199 | |
|
|
200 | } elsif ($stem =~ /^construct\//) { |
|
|
201 | "⌂" |
|
|
202 | |
|
|
203 | } elsif ($stem =~ /^player\//) { |
|
|
204 | "\@" |
|
|
205 | |
|
|
206 | } elsif ($stem =~ /^(?:monster|misc|class|connect|gods|indoor|inorganic|mining|music|skills).*\/(.)/) { |
|
|
207 | $1 |
|
|
208 | |
|
|
209 | } else { |
|
|
210 | substr $stem, 0, 1 |
|
|
211 | } |
|
|
212 | } |
|
|
213 | |
160 | { |
214 | { |
161 | our %ANIMINFO; |
215 | our %ANIMINFO; |
162 | our %FACEINFO; |
216 | our %FACEINFO; |
163 | our %RESOURCE; |
217 | our %RESOURCE; |
164 | our @ARC; |
218 | our @ARC; |
… | |
… | |
173 | our $c_trs = new Coro::Channel; |
227 | our $c_trs = new Coro::Channel; |
174 | our $c_res = new Coro::Channel; |
228 | our $c_res = new Coro::Channel; |
175 | |
229 | |
176 | our @c_png; |
230 | our @c_png; |
177 | |
231 | |
178 | sub commit_png($$$) { |
232 | sub commit_png($$$$) { |
179 | my ($name, $data, $T) = @_; |
233 | my ($stem, $name, $data, $T) = @_; |
180 | |
234 | |
|
|
235 | $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH; |
181 | $FACEINFO{$name}{"data$T"} = $data; |
236 | $FACEINFO{$name}{"data$T"} = $data; |
182 | } |
237 | } |
183 | |
238 | |
184 | sub process_png { |
239 | sub process_png { |
185 | while (@c_png) { |
240 | while (@c_png) { |
… | |
… | |
403 | |
458 | |
404 | if (0 > aio_load $file, $tile) { |
459 | if (0 > aio_load $file, $tile) { |
405 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
460 | die "$path: unable to read tile +$x+$y, aborting.\n"; |
406 | } |
461 | } |
407 | IO::AIO::aio_unlink $file unless $CACHE; |
462 | IO::AIO::aio_unlink $file unless $CACHE; |
408 | commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
463 | commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
409 | } |
464 | } |
410 | } else { |
465 | } else { |
411 | # use as-is (either small, use smooth) |
466 | # use as-is (either small, use smooth) |
412 | commit_png $face, $png, $T; |
467 | commit_png $stem, $face, $png, $T; |
413 | } |
468 | } |
414 | |
469 | |
415 | aio_unlink $path if $delete; |
470 | aio_unlink $path if $delete; |
416 | } |
471 | } |
417 | } |
472 | } |
… | |
… | |
432 | |
487 | |
433 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
488 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
434 | |
489 | |
435 | my $visibility = delete $o->{visibility}; |
490 | my $visibility = delete $o->{visibility}; |
436 | my $magicmap = delete $o->{magicmap}; |
491 | my $magicmap = delete $o->{magicmap}; |
|
|
492 | my $glyph = delete $o->{glyph}; |
437 | |
493 | |
438 | # find upper left corner :/ |
494 | # find upper left corner :/ |
439 | # omg, this is sooo broken |
495 | # omg, this is sooo broken |
440 | my ($dx, $dy); |
496 | my ($dx, $dy); |
441 | for (my $o = $o; $o; $o = $o->{more}) { |
497 | for (my $o = $o; $o; $o = $o->{more}) { |
… | |
… | |
451 | |
507 | |
452 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
508 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
453 | |
509 | |
454 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
510 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
455 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
511 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
|
|
512 | $glyph = delete $o->{glyph} if exists $o->{glyph}; |
456 | |
513 | |
457 | my $anim = delete $o->{anim}; |
514 | my $anim = delete $o->{anim}; |
458 | |
515 | |
459 | if ($anim) { |
516 | if ($anim) { |
460 | # possibly add $ext to the animation name to avoid |
517 | # possibly add $ext to the animation name to avoid |
… | |
… | |
491 | |
548 | |
492 | next if $face =~ /^blank.x11$|^empty.x11$/; |
549 | next if $face =~ /^blank.x11$|^empty.x11$/; |
493 | |
550 | |
494 | $info->{visibility} = $visibility if defined $visibility; |
551 | $info->{visibility} = $visibility if defined $visibility; |
495 | $info->{magicmap} = $magicmap if defined $magicmap; |
552 | $info->{magicmap} = $magicmap if defined $magicmap; |
|
|
553 | $info->{glyph} = $glyph if defined $glyph; |
496 | } |
554 | } |
497 | |
555 | |
498 | if (my $smooth = delete $o->{smoothface}) { |
556 | if (my $smooth = delete $o->{smoothface}) { |
499 | my %kv = split /\s+/, $smooth; |
557 | my %kv = split /\s+/, $smooth; |
500 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
558 | my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
… | |
… | |
569 | if ($meta->{license} =~ s/^#//) { |
627 | if ($meta->{license} =~ s/^#//) { |
570 | $meta->{license} = ({ |
628 | $meta->{license} = ({ |
571 | "pd" => "Public Domain", |
629 | "pd" => "Public Domain", |
572 | "gpl" => "GNU General Public License, version 3.0 or any later", |
630 | "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/", |
631 | "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
|
|
632 | "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/", |
633 | "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/", |
634 | "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
576 | })->{$meta->{license}} |
635 | })->{$meta->{license}} |
577 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
636 | || warn "$dir/$file: license tag '$meta->{license}' not found."; |
|
|
637 | } |
|
|
638 | |
|
|
639 | if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { |
|
|
640 | ($meta->{author} = $1) =~ s/_/ /g; |
578 | } |
641 | } |
579 | |
642 | |
580 | $file =~ s/\.res$//; |
643 | $file =~ s/\.res$//; |
581 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
644 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
582 | |
645 | |
… | |
… | |
795 | if (my $magicmap = $v->{magicmap}) { |
858 | if (my $magicmap = $v->{magicmap}) { |
796 | $magicmap =~ y/A-Z_\-/a-z/d; |
859 | $magicmap =~ y/A-Z_\-/a-z/d; |
797 | $v->{magicmap} = $COLOR{$magicmap}; |
860 | $v->{magicmap} = $COLOR{$magicmap}; |
798 | } |
861 | } |
799 | |
862 | |
|
|
863 | my $stem = delete $v->{stem}; |
|
|
864 | $v->{glyph} //= autoglyph $stem, $v; |
|
|
865 | utf8::encode $v->{glyph}; |
|
|
866 | $v->{glyph} = (chr $v->{magicmap}) . $v->{glyph}; |
|
|
867 | |
800 | delete $v->{arc}; |
868 | delete $v->{arc}; |
801 | } |
869 | } |
802 | |
870 | |
803 | print "processing resources...\n" if $VERBOSE; |
871 | print "processing resources...\n" if $VERBOSE; |
804 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
872 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
805 | while (my ($k, $v) = each %RESOURCE) { |
873 | while (my ($k, $v) = each %RESOURCE) { |
806 | |
874 | |
|
|
875 | if ($v->{meta} && $v->{meta}{datadir}) { |
|
|
876 | delete $RESOURCE{$k}; |
|
|
877 | |
|
|
878 | $k =~ s/^res\/// or die "$k: datadir files must be in res/"; |
|
|
879 | |
|
|
880 | printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE; |
|
|
881 | open my $fh, ">:raw", "$DATADIR/$k~" |
|
|
882 | or die "$DATADIR/$k~: $!"; |
|
|
883 | syswrite $fh, $v->{data}; |
|
|
884 | push @COMMIT, $k; |
|
|
885 | |
|
|
886 | } else { |
807 | if ($v->{type} & 1) { |
887 | if ($v->{type} & 1) { |
808 | # prepend meta info |
888 | # prepend meta info |
809 | |
889 | |
810 | my $meta = $enc->encode ({ |
890 | my $meta = $enc->encode ({ |
811 | name => $k, |
891 | name => $k, |
812 | %{ $v->{meta} || {} }, |
892 | %{ $v->{meta} || {} }, |
813 | }); |
893 | }); |
814 | |
894 | |
815 | $v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
895 | $v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
816 | } |
896 | } |
817 | |
897 | |
818 | make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
898 | make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
|
|
899 | } |
819 | } |
900 | } |
820 | |
901 | |
821 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
902 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
822 | scalar keys %FACEINFO, |
903 | scalar keys %FACEINFO, |
823 | scalar keys %ANIMINFO, |
904 | scalar keys %ANIMINFO, |
… | |
… | |
825 | if $VERBOSE; |
906 | if $VERBOSE; |
826 | |
907 | |
827 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
908 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
828 | or die "$DATADIR/facedata~: $!"; |
909 | or die "$DATADIR/facedata~: $!"; |
829 | |
910 | |
830 | print $fh freeze { |
911 | print $fh nfreeze { |
831 | version => 2, |
912 | version => 2, |
832 | faceinfo => \%FACEINFO, |
913 | faceinfo => \%FACEINFO, |
833 | animinfo => \%ANIMINFO, |
914 | animinfo => \%ANIMINFO, |
834 | resource => \%RESOURCE, |
915 | resource => \%RESOURCE, |
835 | }; |
916 | }; |
836 | |
917 | |
837 | } |
918 | } |
838 | |
919 | |
839 | print "committing files...\n" if $VERBOSE; |
920 | print "committing files...\n" if $VERBOSE; |
840 | |
921 | |
841 | for (qw(archetypes facedata treasures)) { |
922 | for (qw(archetypes facedata treasures), @COMMIT) { |
842 | chmod 0644, "$DATADIR/$_~"; |
923 | chmod 0644, "$DATADIR/$_~"; |
843 | rename "$DATADIR/$_~", "$DATADIR/$_" |
924 | rename "$DATADIR/$_~", "$DATADIR/$_" |
844 | or die "$DATADIR/$_: $!"; |
925 | or die "$DATADIR/$_: $!"; |
845 | } |
926 | } |
846 | |
927 | |