… | |
… | |
80 | |
80 | |
81 | { |
81 | { |
82 | our @PNG; |
82 | our @PNG; |
83 | our @ARC; |
83 | our @ARC; |
84 | our $NFILE; |
84 | our $NFILE; |
|
|
85 | our @FACE; |
|
|
86 | our $ANIM; |
85 | |
87 | |
86 | our (@png, @trs, @arc); # files we are interested in |
88 | our (@png, @trs, @arc); # files we are interested in |
87 | |
89 | |
88 | sub commit_png { |
90 | sub commit_png { |
89 | my ($name, $data) = @_; |
91 | my ($name, $data) = @_; |
90 | #warn "$name: commited\n"; |
92 | |
|
|
93 | push @PNG, [$name => $data]; |
91 | } |
94 | } |
92 | |
95 | |
93 | sub process_png { |
96 | sub process_png { |
94 | while (@png) { |
97 | while (@png) { |
95 | my $path = pop @png; |
98 | my $path = pop @png; |
… | |
… | |
98 | aio_lstat $path; |
101 | aio_lstat $path; |
99 | my ($size, $mtime) = (stat _)[7,9]; |
102 | my ($size, $mtime) = (stat _)[7,9]; |
100 | |
103 | |
101 | if (0 > aio_load $path, $png) { |
104 | if (0 > aio_load $path, $png) { |
102 | warn "$path: $!, skipping.\n"; |
105 | warn "$path: $!, skipping.\n"; |
103 | return; |
106 | next; |
104 | } |
107 | } |
105 | |
108 | |
106 | # quickly extratc width and height of the (necessarily PNG) image |
109 | # quickly extratc width and height of the (necessarily PNG) image |
107 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
110 | unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
108 | warn "$path: not a recongized png file, skipping.\n"; |
111 | warn "$path: not a recongized png file, skipping.\n"; |
109 | return; |
112 | next; |
110 | } |
113 | } |
111 | |
114 | |
112 | my ($w, $h) = unpack "NN", $1; |
115 | my ($w, $h) = unpack "NN", $1; |
113 | |
116 | |
114 | (my $face = $path) =~ s/^.*\///; |
117 | (my $face = $path) =~ s/^.*\///; |
115 | my $T = 32; |
118 | my $T = 32; |
116 | |
119 | |
117 | unless ($face =~ s/\.base\.(...)\.png$/.$1/) { |
120 | unless ($face =~ s/\.base\.(...)\.png$/.$1/) { |
118 | warn "$path: weird filename, skipping.\n"; |
121 | warn "$path: weird filename, skipping.\n"; |
119 | return; |
122 | next; |
120 | } |
123 | } |
121 | |
124 | |
122 | if ($w < $T || $h < $T) { |
125 | if ($w < $T || $h < $T) { |
123 | warn "$path: too small ($w $h), skipping.\n"; |
126 | warn "$path: too small ($w $h), skipping.\n"; |
124 | return; |
127 | next; |
125 | } |
128 | } |
126 | |
129 | |
127 | if ($w % $T || $h % $T) { |
130 | if ($w % $T || $h % $T) { |
128 | warn "$path: weird png size ($w $h), skipping.\n"; |
131 | warn "$path: weird png size ($w $h), skipping.\n"; |
129 | return; |
132 | next; |
130 | } |
133 | } |
131 | |
134 | |
132 | if (($w > $T || $h > $T) && $face !~ /_S\./) { |
135 | if (($w > $T || $h > $T) && $face !~ /_S\./) { |
133 | # split |
136 | # split |
134 | my @tile; |
137 | my @tile; |
… | |
… | |
144 | my @todo = grep { $_->[3] <= $mtime } @tile; |
147 | my @todo = grep { $_->[3] <= $mtime } @tile; |
145 | if (@todo) { |
148 | if (@todo) { |
146 | fork_sub { |
149 | fork_sub { |
147 | open my $convert, "|-", $CONVERT, |
150 | open my $convert, "|-", $CONVERT, |
148 | "png:-", |
151 | "png:-", |
|
|
152 | -negate,#d# |
149 | (map { |
153 | (map { |
150 | ( |
154 | ( |
151 | "(", |
155 | "(", |
152 | "+clone", |
156 | "+clone", |
153 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
157 | -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
… | |
… | |
191 | while (@arc) { |
195 | while (@arc) { |
192 | my ($dir, $file) = @{pop @arc}; |
196 | my ($dir, $file) = @{pop @arc}; |
193 | |
197 | |
194 | my $arc; |
198 | my $arc; |
195 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
199 | aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
|
|
200 | |
196 | my $arc = read_arch "$dir/$file"; |
201 | my $arc = read_arch "$dir/$file"; |
|
|
202 | for my $o (values %$arc) { |
|
|
203 | push @ARC, $o; |
|
|
204 | my ($dx, $dy); |
|
|
205 | # omg, this is sooo broken |
|
|
206 | for (my $o = $o; $o; $o = $o->{more}) { |
|
|
207 | $dx = $o->{x} if $o->{x} < $dx; |
|
|
208 | $dy = $o->{y} if $o->{y} < $dy; |
|
|
209 | } |
|
|
210 | for (my $o = $o; $o; $o = $o->{more}) { |
|
|
211 | my $x = $o->{x} - $dx; |
|
|
212 | my $y = $o->{y} - $dy; |
|
|
213 | if ($x|$y) { |
|
|
214 | $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; |
|
|
215 | } |
|
|
216 | } |
|
|
217 | if (my $anim = delete $o->{anim}) { |
|
|
218 | $o->{animation} = $o->{_name}; |
|
|
219 | $ANIM .= join "", map "$_\n", |
|
|
220 | "anim $o->{_name}", |
|
|
221 | @$anim, |
|
|
222 | "mina"; |
|
|
223 | } |
|
|
224 | } |
197 | } |
225 | } |
198 | } |
226 | } |
199 | |
227 | |
200 | sub process_trs { |
228 | sub process_trs { |
201 | while (@trs) { |
229 | while (@trs) { |
… | |
… | |
245 | (async \&process_png), (async \&process_png), |
273 | (async \&process_png), (async \&process_png), |
246 | (async \&process_trs), (async \&process_trs), |
274 | (async \&process_trs), (async \&process_trs), |
247 | (async \&process_arc), (async \&process_arc), |
275 | (async \&process_arc), (async \&process_arc), |
248 | ); |
276 | ); |
249 | |
277 | |
|
|
278 | { |
|
|
279 | open my $fh, ">:utf8", "$DATADIR/animations~" |
|
|
280 | or die "$DATADIR/animations~: $!"; |
|
|
281 | print $fh $ANIM; |
|
|
282 | } |
|
|
283 | |
|
|
284 | { |
|
|
285 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
|
|
286 | or die "$DATADIR/archetypes~: $!"; |
|
|
287 | print $fh Crossfire::archlist_to_string \@ARC; |
|
|
288 | } |
|
|
289 | |
|
|
290 | @PNG = sort { $a->[0] cmp $b->[0] } @PNG; |
|
|
291 | |
|
|
292 | { |
|
|
293 | open my $fh, ">:perlio", "$DATADIR/crossfire.0~" |
|
|
294 | or die "$DATADIR/crossfire.0~: $!"; |
|
|
295 | printf $fh "IMAGE %d %d %s\x0a%s", $_, (length $PNG[$_][1]), $PNG[$_][0], $PNG[$_][1] |
|
|
296 | for 0.. $#PNG; |
|
|
297 | } |
|
|
298 | |
|
|
299 | rename "$DATADIR/archetypes~" , "$DATADIR/archetypes"; |
|
|
300 | rename "$DATADIR/crossfire.0~", "$DATADIR/crossfire.0"; |
|
|
301 | rename "$DATADIR/animations~" , "$DATADIR/animations"; |
|
|
302 | |
250 | die "--install-arch not yet implemented\n"; |
303 | die "--install-arch not fully implemented\n"; |
251 | } |
304 | } |
252 | } |
305 | } |
253 | |
306 | |
254 | Getopt::Long::Configure ("bundling", "no_ignore_case"); |
307 | Getopt::Long::Configure ("bundling", "no_ignore_case"); |
255 | GetOptions ( |
308 | GetOptions ( |