1 |
root |
1.1 |
#!@PERL@ |
2 |
|
|
|
3 |
root |
1.77 |
# |
4 |
|
|
# This file is part of Deliantra, the Roguelike Realtime MMORPG. |
5 |
|
|
# |
6 |
|
|
# Copyright (©) 2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
7 |
|
|
# |
8 |
|
|
# Deliantra is free software: you can redistribute it and/or modify it under |
9 |
|
|
# the terms of the Affero GNU General Public License as published by the |
10 |
|
|
# Free Software Foundation, either version 3 of the License, or (at your |
11 |
|
|
# option) any later version. |
12 |
|
|
# |
13 |
|
|
# This program is distributed in the hope that it will be useful, |
14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
# GNU General Public License for more details. |
17 |
|
|
# |
18 |
|
|
# You should have received a copy of the Affero GNU General Public License |
19 |
|
|
# and the GNU General Public License along with this program. If not, see |
20 |
|
|
# <http://www.gnu.org/licenses/>. |
21 |
|
|
# |
22 |
|
|
# The authors can be reached via e-mail to <support@deliantra.net> |
23 |
|
|
# |
24 |
|
|
|
25 |
root |
1.84 |
use common::sense; |
26 |
root |
1.2 |
|
27 |
|
|
my $prefix = "@prefix@"; |
28 |
|
|
my $exec_prefix = "@exec_prefix@"; |
29 |
|
|
my $datarootdir = "@datarootdir@"; |
30 |
|
|
my $DATADIR = "@datadir@/@PACKAGE@"; |
31 |
|
|
|
32 |
|
|
my $CONVERT = "@CONVERT@"; |
33 |
root |
1.36 |
#my $IDENTIFY = "@IDENTIFY@"; |
34 |
root |
1.3 |
my $OPTIPNG = "@OPTIPNG@"; |
35 |
root |
1.2 |
my $RSYNC = "@RSYNC@"; |
36 |
root |
1.31 |
my $PNGNQ = "@PNGNQ@"; |
37 |
root |
1.2 |
|
38 |
|
|
use Getopt::Long; |
39 |
root |
1.73 |
use File::Temp; |
40 |
|
|
use POSIX (); |
41 |
|
|
use Carp; |
42 |
|
|
|
43 |
root |
1.69 |
use Coro::EV; |
44 |
root |
1.3 |
use AnyEvent; |
45 |
root |
1.72 |
use YAML::XS (); |
46 |
root |
1.63 |
use JSON::XS (); |
47 |
root |
1.3 |
use IO::AIO (); |
48 |
root |
1.79 |
use Digest::MD5 (); |
49 |
root |
1.73 |
|
50 |
root |
1.70 |
use Coro 5.12; |
51 |
root |
1.3 |
use Coro::AIO; |
52 |
root |
1.51 |
use Coro::Util; |
53 |
root |
1.53 |
use Coro::Channel; |
54 |
root |
1.25 |
use Coro::Storable; $Storable::canonical = 1; |
55 |
root |
1.2 |
|
56 |
root |
1.73 |
use Deliantra; |
57 |
|
|
|
58 |
root |
1.42 |
$SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
59 |
|
|
|
60 |
root |
1.103 |
sub WRITE_FACEINFO() { 0 } |
61 |
|
|
|
62 |
root |
1.2 |
sub usage { |
63 |
|
|
warn <<EOF; |
64 |
root |
1.3 |
Usage: cfutil [-v] [-q] [--force] [--cache] |
65 |
root |
1.2 |
[--install-arch path] |
66 |
|
|
[--install-maps maps] |
67 |
|
|
[--print-statedir] |
68 |
|
|
[--print-confdir] |
69 |
|
|
[--print-datadir] |
70 |
|
|
[--print-libdir] |
71 |
|
|
[--print-bindir] |
72 |
|
|
EOF |
73 |
|
|
exit 1; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
my $VERBOSE = 1; |
77 |
root |
1.3 |
my $CACHE = 0; |
78 |
root |
1.2 |
my $FORCE; |
79 |
root |
1.3 |
my $TMPDIR = "/tmp/cfutil$$~"; |
80 |
|
|
my $TMPFILE = "aaaa0"; |
81 |
root |
1.83 |
my @COMMIT; |
82 |
root |
1.2 |
|
83 |
root |
1.35 |
our %COLOR = ( |
84 |
root |
1.103 |
# original cf colours |
85 |
root |
1.35 |
black => 0, |
86 |
|
|
white => 1, |
87 |
root |
1.103 |
navy => 2, # "dark blue" |
88 |
root |
1.35 |
red => 3, |
89 |
|
|
orange => 4, |
90 |
root |
1.103 |
blue => 5, # "light blue" |
91 |
root |
1.35 |
darkorange => 6, |
92 |
|
|
green => 7, |
93 |
|
|
lightgreen => 8, |
94 |
|
|
grey => 9, |
95 |
root |
1.103 |
brown => 10, # "yellow" |
96 |
|
|
gold => 11, # "light yellow" |
97 |
|
|
tan => 12, # yellowish gray |
98 |
|
|
|
99 |
|
|
# new for deliantra |
100 |
|
|
none => 13, |
101 |
|
|
|
102 |
|
|
# compatibility to existing archetypes |
103 |
|
|
lightblue => 5, |
104 |
|
|
gray => 9, |
105 |
|
|
yellow => 11, |
106 |
|
|
khaki => 12, |
107 |
root |
1.35 |
); |
108 |
|
|
|
109 |
root |
1.2 |
END { system "rm", "-rf", $TMPDIR } |
110 |
|
|
|
111 |
root |
1.69 |
my $s_INT = EV::signal INT => sub { exit 1 }; |
112 |
|
|
my $s_TERM = EV::signal TERM => sub { exit 1 }; |
113 |
root |
1.3 |
|
114 |
root |
1.79 |
our %hash; |
115 |
|
|
|
116 |
|
|
# here we could try to avoid collisions and reduce chksum size further |
117 |
|
|
sub make_hash($\$\$;$) { |
118 |
|
|
my ($id, $dataref, $hashref, $clen) = @_; |
119 |
|
|
|
120 |
|
|
my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; |
121 |
|
|
|
122 |
|
|
if (exists $hash{$hash}) { |
123 |
root |
1.92 |
# hash collision, but some files are simply identical |
124 |
root |
1.79 |
if (${$hash{$hash}[1]} ne $$dataref) { |
125 |
|
|
warn "hash collision $hash{$hash}[0] vs. $id\n"; |
126 |
|
|
exit 1; |
127 |
|
|
} else { |
128 |
|
|
print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; |
129 |
|
|
} |
130 |
|
|
} |
131 |
|
|
$hash{$hash} = [$id, $dataref, $hashref]; |
132 |
|
|
|
133 |
|
|
$$hashref = $hash; |
134 |
|
|
} |
135 |
|
|
|
136 |
root |
1.2 |
mkdir $TMPDIR, 0700 |
137 |
|
|
or die "$TMPDIR: $!"; |
138 |
|
|
|
139 |
root |
1.3 |
sub fork_sub(&) { |
140 |
|
|
my ($cb) = @_; |
141 |
|
|
|
142 |
|
|
if (my $pid = fork) { |
143 |
|
|
my $current = $Coro::current; |
144 |
|
|
my $w = AnyEvent->child (pid => $pid, cb => sub { $current->ready }); |
145 |
|
|
Coro::schedule; |
146 |
|
|
} else { |
147 |
|
|
eval { $cb->() }; |
148 |
|
|
POSIX::_exit 0 unless $@; |
149 |
|
|
warn $@; |
150 |
|
|
POSIX::_exit 1; |
151 |
|
|
} |
152 |
|
|
} |
153 |
|
|
|
154 |
root |
1.2 |
sub inst_maps($) { |
155 |
|
|
my (undef, $path) = @_; |
156 |
|
|
|
157 |
root |
1.29 |
print "\nInstalling '$path' to '$DATADIR/maps'\n\n"; |
158 |
root |
1.2 |
|
159 |
|
|
if (!-f "$path/regions") { |
160 |
|
|
warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
161 |
|
|
exit 1 unless $FORCE; |
162 |
|
|
} |
163 |
|
|
|
164 |
root |
1.62 |
system $RSYNC, "-av", "--chmod=u=rwX,go=rX", |
165 |
|
|
"$path/.", "$DATADIR/maps/.", |
166 |
|
|
"--exclude", "CVS", "--exclude", "/world-precomposed", |
167 |
|
|
"--delete", "--delete-excluded" |
168 |
root |
1.16 |
and die "map installation failed.\n"; |
169 |
root |
1.13 |
|
170 |
|
|
print "maps installed successfully.\n"; |
171 |
root |
1.2 |
} |
172 |
|
|
|
173 |
root |
1.103 |
{ |
174 |
|
|
no utf8; # == values are utf-8 encoded |
175 |
|
|
|
176 |
|
|
our @WALL_SUFFIX = qw(⬤ ╹ ╺ ┗ ╻ ┃ ┏ ┣ ╸ ┛ ━ ┻ ┓ ┫ ┳ ╋); |
177 |
root |
1.90 |
|
178 |
root |
1.103 |
# used to create crude text glyphs for text-based clients |
179 |
|
|
sub autoglyph { |
180 |
|
|
my ($stem, $face) = @_; |
181 |
root |
1.87 |
|
182 |
root |
1.103 |
if ($stem =~ /^wall\/|Nimwall/) { |
183 |
|
|
return $WALL_SUFFIX[hex $1] |
184 |
|
|
if $stem =~ /(_[0-9A-F]).x11/; |
185 |
root |
1.90 |
|
186 |
root |
1.103 |
"█" |
187 |
root |
1.90 |
|
188 |
root |
1.103 |
} elsif ($stem =~ /^traps\//) { |
189 |
|
|
"☠" |
190 |
root |
1.98 |
|
191 |
root |
1.103 |
} elsif ($stem =~ /^armour\/shield/) { |
192 |
|
|
"Ø" |
193 |
root |
1.100 |
|
194 |
root |
1.103 |
} elsif ($stem =~ /^armour\//) { |
195 |
|
|
"A" |
196 |
root |
1.98 |
|
197 |
root |
1.103 |
} elsif ($stem =~ /^weapon\//) { |
198 |
|
|
"†" |
199 |
root |
1.98 |
|
200 |
root |
1.103 |
} elsif ($stem =~ /^readable\//) { |
201 |
|
|
"✉" |
202 |
root |
1.98 |
|
203 |
root |
1.103 |
} elsif ($stem =~ /^river\//) { |
204 |
|
|
"~" |
205 |
root |
1.96 |
|
206 |
root |
1.103 |
} elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) { |
207 |
|
|
"·" |
208 |
root |
1.100 |
|
209 |
root |
1.103 |
} elsif ($stem =~ /^spells\//) { |
210 |
|
|
"!" |
211 |
root |
1.90 |
|
212 |
root |
1.103 |
} elsif ($stem =~ /^exit\//) { |
213 |
|
|
"⎆" |
214 |
root |
1.90 |
|
215 |
root |
1.103 |
} elsif ($stem =~ /^construct\//) { |
216 |
|
|
"⌂" |
217 |
root |
1.101 |
|
218 |
root |
1.103 |
} elsif ($stem =~ /^player\//) { |
219 |
|
|
"\@" |
220 |
root |
1.102 |
|
221 |
root |
1.103 |
} elsif ($stem =~ /^(?:monster|misc|class|connect|gods|indoor|inorganic|mining|music|skills).*\/(.)/) { |
222 |
|
|
$1 |
223 |
root |
1.98 |
|
224 |
root |
1.103 |
} else { |
225 |
|
|
substr $stem, 0, 1 |
226 |
|
|
} |
227 |
root |
1.87 |
} |
228 |
|
|
} |
229 |
|
|
|
230 |
root |
1.2 |
{ |
231 |
root |
1.24 |
our %ANIMINFO; |
232 |
root |
1.6 |
our %FACEINFO; |
233 |
root |
1.37 |
our %RESOURCE; |
234 |
root |
1.30 |
our @ARC; |
235 |
root |
1.27 |
our %ARC; |
236 |
root |
1.12 |
our $TRS; |
237 |
root |
1.3 |
our $NFILE; |
238 |
root |
1.37 |
our $PATH; |
239 |
root |
1.3 |
|
240 |
root |
1.19 |
our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
241 |
|
|
|
242 |
root |
1.53 |
our $c_arc = new Coro::Channel; |
243 |
root |
1.103 |
our $c_any = new Coro::Channel; |
244 |
root |
1.53 |
|
245 |
|
|
our @c_png; |
246 |
root |
1.2 |
|
247 |
root |
1.86 |
sub commit_png($$$$) { |
248 |
|
|
my ($stem, $name, $data, $T) = @_; |
249 |
root |
1.5 |
|
250 |
root |
1.86 |
$FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH; |
251 |
root |
1.19 |
$FACEINFO{$name}{"data$T"} = $data; |
252 |
root |
1.2 |
} |
253 |
|
|
|
254 |
root |
1.3 |
sub process_png { |
255 |
root |
1.53 |
while (@c_png) { |
256 |
|
|
my ($path, $delete) = @{pop @c_png}; |
257 |
root |
1.2 |
|
258 |
root |
1.3 |
my $png; |
259 |
|
|
aio_lstat $path; |
260 |
root |
1.2 |
my ($size, $mtime) = (stat _)[7,9]; |
261 |
|
|
|
262 |
root |
1.3 |
if (0 > aio_load $path, $png) { |
263 |
|
|
warn "$path: $!, skipping.\n"; |
264 |
root |
1.5 |
next; |
265 |
root |
1.3 |
} |
266 |
|
|
|
267 |
root |
1.19 |
my $stem = $path; |
268 |
|
|
my $T; |
269 |
|
|
|
270 |
|
|
if ($stem =~ s/\.32x32\.png~?$//) { |
271 |
|
|
$T = 32; |
272 |
|
|
} elsif ($stem =~ s/\.64x64\.png~?$//) { |
273 |
|
|
$T = 64; |
274 |
|
|
} else { |
275 |
|
|
warn "$path: weird filename, skipping.\n"; |
276 |
|
|
next; |
277 |
|
|
} |
278 |
|
|
|
279 |
root |
1.6 |
# quickly extract width and height of the (necessarily PNG) image |
280 |
root |
1.3 |
unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { |
281 |
root |
1.19 |
warn "$path: not a recognized png file, skipping.\n"; |
282 |
root |
1.5 |
next; |
283 |
root |
1.3 |
} |
284 |
root |
1.2 |
|
285 |
root |
1.3 |
my ($w, $h) = unpack "NN", $1; |
286 |
root |
1.2 |
|
287 |
root |
1.3 |
if ($w < $T || $h < $T) { |
288 |
|
|
warn "$path: too small ($w $h), skipping.\n"; |
289 |
root |
1.5 |
next; |
290 |
root |
1.3 |
} |
291 |
|
|
|
292 |
|
|
if ($w % $T || $h % $T) { |
293 |
|
|
warn "$path: weird png size ($w $h), skipping.\n"; |
294 |
root |
1.5 |
next; |
295 |
root |
1.3 |
} |
296 |
root |
1.2 |
|
297 |
root |
1.54 |
(my $base = $stem) =~ s/^.*\///; |
298 |
|
|
|
299 |
|
|
my $fi = $FACEINFO{$base}; |
300 |
|
|
unless ($fi) { |
301 |
root |
1.59 |
#warn "$path: <$base> not referenced by any archetype, skipping.\n"; |
302 |
|
|
#next; |
303 |
root |
1.54 |
} |
304 |
|
|
|
305 |
root |
1.59 |
my $arc = $fi->{arc} || { }; |
306 |
root |
1.54 |
|
307 |
root |
1.19 |
unless ($path =~ /~$/) { |
308 |
|
|
# possibly enlarge |
309 |
|
|
if (0 > aio_stat "$stem.64x64.png") { |
310 |
|
|
my $other = "$stem.64x64.png~"; |
311 |
|
|
|
312 |
|
|
if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
313 |
|
|
fork_sub { |
314 |
root |
1.52 |
my $CROP; |
315 |
|
|
my $SRC = "png:\Q$path\E"; |
316 |
|
|
|
317 |
root |
1.54 |
my $is_floor = $arc->{is_floor}; |
318 |
|
|
my $is_wall = 0; |
319 |
|
|
|
320 |
|
|
my ($wall_pfx, $wall_dir, $wall_sfx); |
321 |
|
|
|
322 |
|
|
if ( |
323 |
|
|
!$is_floor |
324 |
|
|
&& !$arc->{alive} |
325 |
root |
1.55 |
&& $arc->{move_block} eq "all" |
326 |
root |
1.54 |
&& $path =~ /^(.*_)([0-9A-F])(\.x11.*\.png)$/ |
327 |
|
|
) { |
328 |
|
|
($wall_pfx, $wall_dir, $wall_sfx) = ($1, hex $2, $3); |
329 |
|
|
|
330 |
|
|
unless (grep { !-e sprintf "%s%X%s", $wall_pfx, $_, $wall_sfx } 0..15) { |
331 |
|
|
$is_wall = 1; |
332 |
|
|
} |
333 |
|
|
} |
334 |
|
|
|
335 |
|
|
if ($is_wall || $is_floor) { |
336 |
|
|
# add a 4px border and add other images around it |
337 |
|
|
$CROP = "-shave 8x8 +repage"; |
338 |
|
|
|
339 |
|
|
$w += 8; |
340 |
|
|
$h += 8; |
341 |
|
|
|
342 |
|
|
$SRC = "-size ${w}x${h} xc:transparent"; |
343 |
|
|
$SRC .= " png:\Q$path\E -geometry +4+4 -composite"; |
344 |
|
|
|
345 |
|
|
# 8 surrounding images |
346 |
|
|
for ( |
347 |
|
|
# x y b r0 r1 |
348 |
|
|
[-1, -1, 0, 6], |
349 |
|
|
[ 0, -1, 1, 10, 14], |
350 |
|
|
[+1, -1, 0, 12], |
351 |
|
|
|
352 |
|
|
[-1, 0, 8, 5, 7], |
353 |
|
|
# |
354 |
|
|
[+1, 0, 2, 5, 13], |
355 |
|
|
|
356 |
|
|
[-1, +1, 0, 3], |
357 |
|
|
[ 0, +1, 4, 10, 11], |
358 |
|
|
[+1, +1, 0, 9], |
359 |
|
|
) { |
360 |
|
|
my ($x, $y, $d, $r0, $r1) = @$_; |
361 |
|
|
|
362 |
|
|
my $tile = $is_floor ? $path |
363 |
|
|
: $is_wall ? sprintf "%s%X%s", $wall_pfx, ($wall_dir & $d) ? $r1 : $r0, $wall_sfx |
364 |
|
|
: die; |
365 |
|
|
|
366 |
|
|
$SRC .= sprintf " png:%s -geometry %+d%+d -composite", |
367 |
|
|
"\Q$tile", |
368 |
|
|
$x * ($w - 8) + 4, |
369 |
|
|
$y * ($h - 8) + 4; |
370 |
root |
1.52 |
} |
371 |
|
|
} |
372 |
|
|
|
373 |
|
|
system "convert -depth 8 $SRC rgba:-" |
374 |
root |
1.51 |
. "| $exec_prefix/bin/cfhq2xa $w $h 0" |
375 |
root |
1.52 |
. "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $CROP $QUANTIZE -quality 00 png32:\Q$other\E~" |
376 |
|
|
and die "convert/cfhq2xa pipeline error: status $? ($!)"; |
377 |
root |
1.31 |
system $OPTIPNG, "-i0", "-q", "$other~"; |
378 |
root |
1.19 |
die "$other~ has zero size, aborting." unless -s "$other~"; |
379 |
|
|
rename "$other~", $other; |
380 |
|
|
}; |
381 |
|
|
} |
382 |
|
|
|
383 |
root |
1.53 |
push @c_png, [$other, !$CACHE]; |
384 |
root |
1.19 |
} |
385 |
|
|
|
386 |
|
|
# possibly scale down |
387 |
|
|
if (0 > aio_stat "$stem.32x32.png") { |
388 |
|
|
my $other = "$stem.32x32.png~"; |
389 |
|
|
|
390 |
|
|
if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
391 |
|
|
fork_sub { |
392 |
|
|
system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
393 |
root |
1.31 |
system $OPTIPNG, "-i0", "-q", "$other~"; |
394 |
|
|
|
395 |
|
|
# reduce smoothfaces >10000 bytes |
396 |
root |
1.71 |
# obsolete, no longer required |
397 |
|
|
if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) { |
398 |
root |
1.31 |
my $ncolor = 256; |
399 |
|
|
while () { |
400 |
root |
1.33 |
system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
401 |
root |
1.31 |
system $OPTIPNG, "-i0", "-q", "$other~~"; |
402 |
|
|
last if 10000 > -s "$other~~"; |
403 |
|
|
$ncolor = int $ncolor * 0.9; |
404 |
|
|
$ncolor > 8 or die "cannot reduce filesize to < 10000 bytes"; |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
printf "reduced %s from %d to %d bytes using %d colours.\n", |
408 |
|
|
$other, -s "$other~", -s "$other~~", $ncolor |
409 |
root |
1.32 |
if $VERBOSE >= 2; |
410 |
root |
1.31 |
rename "$other~~", "$other~"; |
411 |
|
|
} |
412 |
|
|
|
413 |
root |
1.19 |
die "$other~ has zero size, aborting." unless -s "$other~"; |
414 |
|
|
rename "$other~", $other; |
415 |
|
|
}; |
416 |
|
|
} |
417 |
|
|
|
418 |
root |
1.21 |
#warn "scaled down $path to $other\n";#d# |
419 |
root |
1.53 |
push @c_png, [$other, !$CACHE]; |
420 |
root |
1.19 |
} |
421 |
|
|
} |
422 |
|
|
|
423 |
|
|
(my $face = $stem) =~ s/^.*\///; |
424 |
|
|
|
425 |
root |
1.23 |
# split all bigfaces, but avoid smoothfaces (*_S) |
426 |
root |
1.3 |
if (($w > $T || $h > $T) && $face !~ /_S\./) { |
427 |
|
|
# split |
428 |
|
|
my @tile; |
429 |
|
|
for my $x (0 .. (int $w / $T) - 1) { |
430 |
|
|
for my $y (0 .. (int $h / $T) - 1) { |
431 |
|
|
my $file = "$path+$x+$y~"; |
432 |
|
|
aio_lstat $file; |
433 |
|
|
push @tile, [$x, $y, $file, (stat _)[9]]; |
434 |
|
|
} |
435 |
root |
1.2 |
} |
436 |
|
|
|
437 |
root |
1.3 |
my $mtime = (lstat $path)[9]; |
438 |
|
|
my @todo = grep { $_->[3] <= $mtime } @tile; |
439 |
|
|
if (@todo) { |
440 |
|
|
fork_sub { |
441 |
|
|
open my $convert, "|-", $CONVERT, |
442 |
|
|
"png:-", |
443 |
|
|
(map { |
444 |
|
|
( |
445 |
|
|
"(", |
446 |
|
|
"+clone", |
447 |
|
|
-crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), |
448 |
root |
1.7 |
"+repage", |
449 |
root |
1.19 |
-quality => "00", |
450 |
|
|
-write => "png32:$_->[2]~", |
451 |
root |
1.3 |
"+delete", |
452 |
|
|
")", |
453 |
|
|
) |
454 |
|
|
} @todo), |
455 |
|
|
"null:"; |
456 |
|
|
|
457 |
|
|
binmode $convert; |
458 |
|
|
print $convert $png; |
459 |
|
|
close $convert; |
460 |
|
|
|
461 |
|
|
# pass 2, optimise, and rename |
462 |
|
|
for (@todo) { |
463 |
|
|
system $OPTIPNG, "-o5", "-i0", "-q", "$_->[2]~"; |
464 |
root |
1.19 |
die "$_->[2]~ has zero size, aborting." unless -s "$_->[2]~"; |
465 |
root |
1.3 |
rename "$_->[2]~", $_->[2]; |
466 |
|
|
} |
467 |
|
|
}; |
468 |
root |
1.2 |
} |
469 |
|
|
|
470 |
root |
1.3 |
for (@tile) { |
471 |
|
|
my ($x, $y, $file) = @$_; |
472 |
|
|
my $tile; |
473 |
|
|
|
474 |
|
|
if (0 > aio_load $file, $tile) { |
475 |
|
|
die "$path: unable to read tile +$x+$y, aborting.\n"; |
476 |
|
|
} |
477 |
|
|
IO::AIO::aio_unlink $file unless $CACHE; |
478 |
root |
1.86 |
commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T; |
479 |
root |
1.2 |
} |
480 |
root |
1.3 |
} else { |
481 |
|
|
# use as-is (either small, use smooth) |
482 |
root |
1.86 |
commit_png $stem, $face, $png, $T; |
483 |
root |
1.3 |
} |
484 |
root |
1.19 |
|
485 |
|
|
aio_unlink $path if $delete; |
486 |
root |
1.3 |
} |
487 |
root |
1.2 |
} |
488 |
|
|
|
489 |
root |
1.103 |
sub process_faceinfo { |
490 |
|
|
my ($dir, $file) = @_; |
491 |
|
|
my $path = "$dir/$file"; |
492 |
|
|
|
493 |
|
|
my $data; |
494 |
|
|
if (0 > aio_load $path, $data) { |
495 |
|
|
warn "$path: $!, skipping.\n"; |
496 |
|
|
return; |
497 |
|
|
} |
498 |
|
|
|
499 |
|
|
for (split /\n/, $data) { |
500 |
|
|
my ($face, $visibility, $fg, $bg, $glyph) = split /\s+/; |
501 |
|
|
|
502 |
|
|
$glyph =~ s/^?(?=.)//; # remove "autoglyph" flag |
503 |
|
|
|
504 |
|
|
(my $fgi = $COLOR{$fg}) |
505 |
|
|
// warn "WARNING: $path: $face specifies unknown foreground colour '$fg'.\n"; |
506 |
|
|
(my $bgi = $COLOR{$bg}) |
507 |
|
|
// warn "WARNING: $path: $face specifies unknown background colour '$bg'.\n"; |
508 |
|
|
|
509 |
|
|
my $fi = $FACEINFO{$face} ||= { }; |
510 |
|
|
$fi->{visibility} = $visibility * 1; |
511 |
|
|
$fi->{magicmap} = $fgi; # foreground colour becomes magicmap |
512 |
|
|
$fi->{glyph} = (chr $fgi) . (chr $bgi) . $glyph; |
513 |
|
|
# bg not used except for text clients |
514 |
|
|
} |
515 |
|
|
} |
516 |
|
|
|
517 |
root |
1.3 |
sub process_arc { |
518 |
root |
1.103 |
while (my ($dir, $file) = @{ $c_arc->get }) { |
519 |
root |
1.3 |
my $arc; |
520 |
|
|
aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ |
521 |
root |
1.4 |
|
522 |
root |
1.2 |
my $arc = read_arch "$dir/$file"; |
523 |
root |
1.4 |
for my $o (values %$arc) { |
524 |
root |
1.30 |
push @ARC, $o; |
525 |
|
|
for (my $m = $o; $m; $m = $m->{more}) { |
526 |
|
|
$ARC{$m->{_name}} = $m; |
527 |
|
|
} |
528 |
root |
1.6 |
|
529 |
root |
1.76 |
$o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
530 |
root |
1.10 |
|
531 |
root |
1.6 |
# find upper left corner :/ |
532 |
|
|
# omg, this is sooo broken |
533 |
root |
1.4 |
my ($dx, $dy); |
534 |
|
|
for (my $o = $o; $o; $o = $o->{more}) { |
535 |
|
|
$dx = $o->{x} if $o->{x} < $dx; |
536 |
|
|
$dy = $o->{y} if $o->{y} < $dy; |
537 |
|
|
} |
538 |
root |
1.6 |
|
539 |
root |
1.4 |
for (my $o = $o; $o; $o = $o->{more}) { |
540 |
|
|
my $x = $o->{x} - $dx; |
541 |
|
|
my $y = $o->{y} - $dy; |
542 |
root |
1.6 |
|
543 |
|
|
my $ext = $x|$y ? "+$x+$y" : ""; |
544 |
|
|
|
545 |
root |
1.26 |
$o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
546 |
root |
1.6 |
|
547 |
|
|
my $anim = delete $o->{anim}; |
548 |
|
|
|
549 |
|
|
if ($anim) { |
550 |
root |
1.24 |
# possibly add $ext to the animation name to avoid |
551 |
|
|
# the need to specify archnames for all parts |
552 |
|
|
# of a multipart archetype. |
553 |
root |
1.8 |
$o->{animation} = "$o->{_name}"; |
554 |
root |
1.24 |
my $facings = 1; |
555 |
|
|
my @frames; |
556 |
root |
1.6 |
|
557 |
|
|
for (@$anim) { |
558 |
root |
1.24 |
if (/^facings\s+(\d+)/) { |
559 |
|
|
$facings = $1*1; |
560 |
|
|
} elsif (/^blank.x11$|^empty.x11$/) { |
561 |
|
|
push @frames, $_; |
562 |
|
|
} else { |
563 |
|
|
push @frames, "$_$ext"; |
564 |
|
|
} |
565 |
root |
1.6 |
} |
566 |
|
|
|
567 |
root |
1.24 |
$ANIMINFO{$o->{animation}} = { |
568 |
|
|
facings => $facings, |
569 |
|
|
frames => \@frames, |
570 |
|
|
}; |
571 |
root |
1.6 |
} |
572 |
|
|
|
573 |
root |
1.58 |
for ($o->{face} || (), @{$anim || []}) { |
574 |
|
|
next if /^facings\s/; |
575 |
|
|
|
576 |
|
|
my $face = $_; |
577 |
|
|
$face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates |
578 |
root |
1.6 |
|
579 |
root |
1.56 |
my $info = $FACEINFO{$face} ||= { }; |
580 |
|
|
$info->{arc} = $o; |
581 |
|
|
|
582 |
|
|
next if $face =~ /^blank.x11$|^empty.x11$/; |
583 |
root |
1.4 |
} |
584 |
root |
1.12 |
|
585 |
|
|
if (my $smooth = delete $o->{smoothface}) { |
586 |
root |
1.54 |
my %kv = split /\s+/, $smooth; |
587 |
root |
1.23 |
my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support |
588 |
|
|
while (my ($face, $smooth) = each %kv) { |
589 |
root |
1.54 |
$FACEINFO{$smooth}{arc} = $o; |
590 |
|
|
|
591 |
root |
1.23 |
$FACEINFO{$face}{smooth} = $smooth; |
592 |
|
|
$FACEINFO{$face}{smoothlevel} = $level; |
593 |
root |
1.14 |
} |
594 |
root |
1.12 |
} |
595 |
root |
1.4 |
} |
596 |
|
|
} |
597 |
root |
1.3 |
} |
598 |
root |
1.2 |
} |
599 |
|
|
|
600 |
root |
1.3 |
sub process_trs { |
601 |
root |
1.103 |
my ($dir, $file) = @_; |
602 |
|
|
my $path = "$dir/$file"; |
603 |
root |
1.12 |
|
604 |
root |
1.103 |
my $trs; |
605 |
|
|
if (0 > aio_load $path, $trs) { |
606 |
|
|
warn "$path: $!, skipping.\n"; |
607 |
|
|
return; |
608 |
|
|
} |
609 |
root |
1.12 |
|
610 |
root |
1.103 |
$TRS .= $trs; |
611 |
root |
1.2 |
} |
612 |
|
|
|
613 |
root |
1.45 |
my %FILECACHE; |
614 |
|
|
|
615 |
|
|
sub load_cached($;$) { |
616 |
|
|
unless (exists $FILECACHE{$_[0]}) { |
617 |
|
|
my $data; |
618 |
|
|
if (0 < aio_load $_[0], $data) { |
619 |
root |
1.49 |
if ($_[1]) { |
620 |
|
|
$data = eval { $_[1]->($data) }; |
621 |
|
|
warn "$_[0]: $@" if $@; |
622 |
|
|
} |
623 |
root |
1.45 |
} |
624 |
|
|
|
625 |
|
|
$FILECACHE{$_[0]} = $data; |
626 |
|
|
} |
627 |
|
|
|
628 |
|
|
$FILECACHE{$_[0]} |
629 |
|
|
} |
630 |
|
|
|
631 |
root |
1.37 |
sub process_res { |
632 |
root |
1.103 |
my ($dir, $file, $type) = @_; |
633 |
root |
1.37 |
|
634 |
root |
1.103 |
my $data; |
635 |
|
|
aio_load "$dir/$file", $data; |
636 |
root |
1.37 |
|
637 |
root |
1.103 |
my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; |
638 |
root |
1.38 |
|
639 |
root |
1.103 |
utf8::decode $dir; |
640 |
|
|
utf8::decode $file; |
641 |
root |
1.61 |
|
642 |
root |
1.103 |
# a meta file for resources is now mandatory |
643 |
|
|
unless (exists $meta->{$file}) { |
644 |
|
|
warn "skipping $dir/$file\n" if $VERBOSE >= 3; |
645 |
|
|
return; |
646 |
|
|
} |
647 |
root |
1.49 |
|
648 |
root |
1.103 |
$meta = { |
649 |
|
|
%{ $meta->{"" } || {} }, |
650 |
|
|
%{ $meta->{$file} || {} }, |
651 |
|
|
}; |
652 |
root |
1.48 |
|
653 |
root |
1.103 |
if ($meta->{license} =~ s/^#//) { |
654 |
|
|
$meta->{license} = ({ |
655 |
|
|
"pd" => "Public Domain", |
656 |
|
|
"gpl" => "GNU General Public License, version 3.0 or any later", |
657 |
|
|
"cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", |
658 |
|
|
"cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/", |
659 |
|
|
"cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", |
660 |
|
|
"cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", |
661 |
|
|
})->{$meta->{license}} |
662 |
|
|
|| warn "$dir/$file: license tag '$meta->{license}' not found."; |
663 |
|
|
} |
664 |
|
|
|
665 |
|
|
if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { |
666 |
|
|
($meta->{author} = $1) =~ s/_/ /g; |
667 |
|
|
} |
668 |
|
|
|
669 |
|
|
$file =~ s/\.res$//; |
670 |
|
|
$file =~ s/\.(ogg|wav|jpg|png)$//; |
671 |
|
|
|
672 |
|
|
substr $dir, 0, 1 + length $PATH, ""; |
673 |
|
|
|
674 |
|
|
if (my $filter = $meta->{cfutil_filter}) { |
675 |
|
|
if ($filter eq "yaml2json") { |
676 |
|
|
$data = JSON::XS::encode_json YAML::XS::Load $data; |
677 |
|
|
} elsif ($filter eq "json2json") { |
678 |
|
|
$data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); |
679 |
|
|
} elsif ($filter eq "perl2json") { |
680 |
|
|
$data = eval $data; die if $@; |
681 |
|
|
$data = JSON::XS::encode_json $data; |
682 |
|
|
} else { |
683 |
|
|
warn "$dir/$file: unknown filter $filter, skipping\n"; |
684 |
root |
1.63 |
} |
685 |
root |
1.103 |
} |
686 |
|
|
|
687 |
|
|
$RESOURCE{"$dir/$file"} = { |
688 |
|
|
type => (exists $meta->{type} ? delete $meta->{type} : $type), |
689 |
|
|
data => $data, |
690 |
|
|
%$meta ? (meta => $meta) : (), |
691 |
|
|
}; |
692 |
|
|
} |
693 |
root |
1.63 |
|
694 |
root |
1.103 |
sub process_any { |
695 |
|
|
while (my ($func, @args) = @{ $c_any->get }) { |
696 |
|
|
$func->(@args); |
697 |
root |
1.37 |
} |
698 |
|
|
} |
699 |
|
|
|
700 |
root |
1.3 |
sub find_files; |
701 |
|
|
sub find_files { |
702 |
root |
1.2 |
my ($path) = @_; |
703 |
|
|
|
704 |
root |
1.103 |
my $grp = IO::AIO::aio_group; |
705 |
|
|
|
706 |
|
|
my $scandir; $scandir = sub { |
707 |
|
|
my ($path) = @_; |
708 |
|
|
|
709 |
|
|
IO::AIO::aioreq_pri 4; |
710 |
|
|
add $grp IO::AIO::aio_scandir $path, 4, sub { |
711 |
|
|
my ($dirs, $nondirs) = @_; |
712 |
|
|
|
713 |
|
|
$scandir->("$path/$_") |
714 |
|
|
for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs; |
715 |
|
|
|
716 |
|
|
my $dir = $path; |
717 |
|
|
substr $dir, 0, 1 + length $PATH, ""; |
718 |
|
|
|
719 |
|
|
for my $file (@$nondirs) { |
720 |
|
|
if ($dir =~ /^music(?:\/|$)/) { |
721 |
|
|
$c_any->put ([\&process_res, $path, $file, 3]) # FT_MUSIC |
722 |
|
|
if $file =~ /\.(ogg)$/; |
723 |
|
|
|
724 |
|
|
} elsif ($dir =~ /^sound(?:\/|$)/) { |
725 |
|
|
$c_any->put ([\&process_res, $path, $file, 5]) # FT_SOUND |
726 |
|
|
if $file =~ /\.(wav|ogg)$/; |
727 |
|
|
|
728 |
|
|
} elsif ($dir =~ /^res(?:\/|$)/) { |
729 |
|
|
if ($file =~ /\.(jpg|png)$/) { |
730 |
|
|
$c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE |
731 |
|
|
} elsif ($file =~ /\.(res)$/) { |
732 |
|
|
$c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC |
733 |
|
|
} else { |
734 |
|
|
$c_any->put ([\&process_res, $path, $file, undef]); |
735 |
|
|
} |
736 |
|
|
|
737 |
|
|
} elsif ($file =~ /\.png$/) { |
738 |
|
|
push @c_png, ["$path/$file", 0]; |
739 |
root |
1.44 |
|
740 |
root |
1.103 |
} elsif ($file =~ /\.faceinfo$/) { |
741 |
|
|
$c_any->put ([\&process_faceinfo, $path, $file]); |
742 |
root |
1.44 |
|
743 |
root |
1.103 |
} elsif ($file =~ /\.trs$/) { |
744 |
|
|
$c_any->put ([\&process_trs, $path, $file]); |
745 |
root |
1.44 |
|
746 |
root |
1.103 |
} elsif ($file =~ /\.arc$/) { |
747 |
|
|
$c_arc->put ([$path, $file]); |
748 |
root |
1.44 |
|
749 |
root |
1.103 |
} else { |
750 |
|
|
warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
751 |
|
|
} |
752 |
root |
1.2 |
} |
753 |
root |
1.103 |
}; |
754 |
root |
1.2 |
}; |
755 |
root |
1.103 |
|
756 |
|
|
$scandir->($path); |
757 |
|
|
aio_wait $grp; |
758 |
root |
1.2 |
} |
759 |
|
|
|
760 |
root |
1.73 |
sub generate_plurals { |
761 |
|
|
# use Lingua::EN::Inflect (); |
762 |
|
|
# Lingua::EN::Inflect::classical; |
763 |
root |
1.74 |
# Lingua::EN::Inflect::def_noun '(.*)staff' => '$1staves'; # policy |
764 |
root |
1.73 |
# Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack |
765 |
|
|
# |
766 |
|
|
# for my $a (@ARC) { |
767 |
|
|
# my $name = $a->{name} || $a->{_name}; |
768 |
|
|
# |
769 |
|
|
# next unless $a->{name_pl}; |
770 |
root |
1.74 |
# next if $a->{invisible}; |
771 |
|
|
# next if $a->{is_floor}; |
772 |
|
|
# next if $a->{no_pick}; |
773 |
root |
1.73 |
# |
774 |
|
|
# my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name; |
775 |
|
|
# my $pl = $test =~ /^(?:eq|p:.)$/ |
776 |
|
|
# ? $name |
777 |
|
|
# : Lingua::EN::Inflect::PL $name; |
778 |
|
|
# |
779 |
|
|
# if ($pl ne $a->{name_pl}) { |
780 |
|
|
# warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n"; |
781 |
|
|
# } |
782 |
|
|
# } |
783 |
|
|
} |
784 |
|
|
|
785 |
root |
1.2 |
sub inst_arch($) { |
786 |
|
|
my (undef, $path) = @_; |
787 |
|
|
|
788 |
root |
1.37 |
$PATH = $path; |
789 |
|
|
|
790 |
root |
1.29 |
print "\n", |
791 |
|
|
"Installing '$path' to '$DATADIR'\n", |
792 |
root |
1.28 |
"\n", |
793 |
root |
1.27 |
"This can take a long time if you run this\n", |
794 |
|
|
"for the first time or do not use --cache.\n", |
795 |
|
|
"\n", |
796 |
|
|
"Unless you run verbosely, all following warning\n", |
797 |
|
|
"or error messages indicate serious problems.\n", |
798 |
|
|
"\n"; |
799 |
root |
1.2 |
|
800 |
|
|
if (!-d "$path/treasures") { |
801 |
|
|
warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; |
802 |
|
|
exit 1 unless $FORCE; |
803 |
|
|
} |
804 |
|
|
|
805 |
root |
1.103 |
print "start file scan, arc, any processing...\n" if $VERBOSE; |
806 |
root |
1.53 |
|
807 |
|
|
my @a_arc = map +(async \&process_arc), 1..2; |
808 |
root |
1.103 |
my @a_any = map +(async \&process_any), 1..4; |
809 |
root |
1.53 |
|
810 |
root |
1.103 |
find_files $path; |
811 |
root |
1.2 |
|
812 |
root |
1.70 |
$c_arc->shutdown; |
813 |
root |
1.103 |
$c_any->shutdown; |
814 |
root |
1.53 |
|
815 |
|
|
$_->join for @a_arc; # need to parse all archetypes before png processing |
816 |
root |
1.3 |
|
817 |
root |
1.53 |
print "end arc, start png processing...\n" if $VERBOSE; |
818 |
|
|
|
819 |
root |
1.69 |
# eight png crunchers work fine for my 4x smp machine |
820 |
|
|
my @a_png = map +(async \&process_png), 1..8; |
821 |
root |
1.53 |
|
822 |
root |
1.103 |
print "end any processing...\n" if $VERBOSE; |
823 |
|
|
$_->join for @a_any; |
824 |
|
|
|
825 |
|
|
print "end png processing...\n" if $VERBOSE; |
826 |
|
|
$_->join for @a_png; |
827 |
root |
1.53 |
|
828 |
|
|
print "scanning done, processing results...\n" if $VERBOSE; |
829 |
root |
1.5 |
{ |
830 |
root |
1.27 |
# remove path prefix from editor_folder |
831 |
root |
1.76 |
$_->{editor_folder} =~ /^\x00/ |
832 |
|
|
and substr $_->{editor_folder}, 0, 2 + length $path, "" |
833 |
|
|
for values %ARC; |
834 |
root |
1.27 |
|
835 |
root |
1.53 |
print "resolving inheritance tree...\n" if $VERBOSE; |
836 |
root |
1.27 |
# resolve inherit |
837 |
|
|
while () { |
838 |
|
|
my $progress; |
839 |
|
|
my $loop; |
840 |
|
|
|
841 |
|
|
for my $o (values %ARC) { |
842 |
root |
1.81 |
for my $other (split /,/, $o->{inherit}) { |
843 |
root |
1.27 |
if (my $s = $ARC{$other}) { |
844 |
|
|
if ($s->{inherit}) { |
845 |
|
|
$loop = $s; |
846 |
|
|
} else { |
847 |
|
|
delete $o->{inherit}; |
848 |
root |
1.30 |
my %s = %$s; |
849 |
|
|
delete @s{qw(_name more name name_pl)}; |
850 |
|
|
%$o = ( %s, %$o ); |
851 |
root |
1.27 |
++$progress; |
852 |
|
|
} |
853 |
|
|
} else { |
854 |
root |
1.103 |
warn "WARNING: archetype '$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; |
855 |
root |
1.27 |
delete $ARC{$o->{_name}}; |
856 |
|
|
} |
857 |
|
|
} |
858 |
|
|
} |
859 |
|
|
|
860 |
|
|
unless ($progress) { |
861 |
|
|
die "inheritance loop detected starting at archetype '$loop->{_name}', aborting.\n" |
862 |
|
|
if $loop; |
863 |
|
|
|
864 |
|
|
last; |
865 |
|
|
} |
866 |
|
|
} |
867 |
|
|
|
868 |
root |
1.34 |
# remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
869 |
|
|
@ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
870 |
|
|
|
871 |
root |
1.73 |
print "generating plurals...\n" if $VERBOSE; |
872 |
|
|
generate_plurals; |
873 |
|
|
|
874 |
root |
1.78 |
printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
875 |
root |
1.5 |
open my $fh, ">:utf8", "$DATADIR/archetypes~" |
876 |
|
|
or die "$DATADIR/archetypes~: $!"; |
877 |
root |
1.65 |
print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
878 |
root |
1.5 |
} |
879 |
|
|
|
880 |
root |
1.103 |
if (WRITE_FACEINFO) { |
881 |
|
|
my @table; |
882 |
|
|
for my $face (sort keys %FACEINFO) { |
883 |
|
|
my $v = $FACEINFO{$face}; |
884 |
|
|
(my $xf = $face) =~ s/\+\d+\+\d+$//; |
885 |
|
|
|
886 |
|
|
$v->{magicmap} //= $FACEINFO{$xf}{magicmap}; |
887 |
|
|
$v->{glyph} //= $FACEINFO{$xf}{glyph}; |
888 |
|
|
|
889 |
|
|
$v->{magicmap} =~ y/A-Z_\-/a-z/d; |
890 |
|
|
|
891 |
|
|
delete $v->{glyph} if $v->{glyph} =~ /^\?./; |
892 |
|
|
|
893 |
|
|
my $stem = $v->{stem}; |
894 |
|
|
$v->{glyph} = $v->{glyph} // ("?" . (autoglyph $stem, $v)); |
895 |
|
|
|
896 |
|
|
push @table, [$face, $v->{visibility} || 0, $v->{magicmap} || "none", "none ", $v->{glyph}]; |
897 |
|
|
} |
898 |
|
|
use Text::Table; |
899 |
|
|
my $tb = new Text::Table undef, { align => "num" }, undef, undef, undef; |
900 |
|
|
$tb->load (@table); |
901 |
|
|
open my $fh, ">:raw", "default.faceinfo"or die; |
902 |
|
|
print $fh $tb; |
903 |
|
|
print "default.faceinfo written, exiting.\n"; |
904 |
|
|
exit 77; |
905 |
|
|
} |
906 |
|
|
|
907 |
root |
1.6 |
{ |
908 |
root |
1.78 |
printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
909 |
root |
1.12 |
open my $fh, ">:utf8", "$DATADIR/treasures~" |
910 |
|
|
or die "$DATADIR/treasures~: $!"; |
911 |
|
|
print $fh $TRS; |
912 |
|
|
} |
913 |
|
|
|
914 |
|
|
{ |
915 |
root |
1.53 |
print "processing facedata...\n" if $VERBOSE; |
916 |
root |
1.6 |
while (my ($k, $v) = each %FACEINFO) { |
917 |
root |
1.103 |
length $v->{data32} or warn "WARNING: face '$k' has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
918 |
|
|
length $v->{data64} or warn "WARNING: face '$k' has no png64. this will not work very well.\n"; |
919 |
root |
1.5 |
|
920 |
root |
1.79 |
make_hash $k, $v->{data32}, $v->{hash32}; |
921 |
|
|
make_hash $k, $v->{data64}, $v->{hash64}; |
922 |
|
|
|
923 |
root |
1.103 |
#length $v->{data32} <= 10000 or warn "WARNING: face '$k' has face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
924 |
|
|
#length $v->{data64} <= 10000 or warn "WARNING: face '$k' has face64 larger than 10000 bytes.\n"; |
925 |
root |
1.20 |
|
926 |
root |
1.103 |
exists $v->{visibility} |
927 |
|
|
or warn "WARNING: face '$k' has no visibility info, missing faceinfo entry?\n"; |
928 |
root |
1.53 |
|
929 |
root |
1.91 |
my $stem = delete $v->{stem}; |
930 |
root |
1.103 |
$v->{glyph} // warn "WARNING: face '$k' has glyph, cannot autoglyph at the moment."; |
931 |
|
|
#$v->{glyph} //= autoglyph $stem, $v; |
932 |
root |
1.91 |
|
933 |
root |
1.53 |
delete $v->{arc}; |
934 |
root |
1.6 |
} |
935 |
|
|
|
936 |
root |
1.79 |
print "processing resources...\n" if $VERBOSE; |
937 |
|
|
my $enc = JSON::XS->new->utf8->canonical->relaxed; |
938 |
|
|
while (my ($k, $v) = each %RESOURCE) { |
939 |
|
|
|
940 |
root |
1.83 |
if ($v->{meta} && $v->{meta}{datadir}) { |
941 |
|
|
delete $RESOURCE{$k}; |
942 |
root |
1.79 |
|
943 |
root |
1.83 |
$k =~ s/^res\/// or die "$k: datadir files must be in res/"; |
944 |
root |
1.79 |
|
945 |
root |
1.83 |
printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE; |
946 |
|
|
open my $fh, ">:raw", "$DATADIR/$k~" |
947 |
|
|
or die "$DATADIR/$k~: $!"; |
948 |
|
|
syswrite $fh, $v->{data}; |
949 |
|
|
push @COMMIT, $k; |
950 |
|
|
|
951 |
|
|
} else { |
952 |
|
|
if ($v->{type} & 1) { |
953 |
|
|
# prepend meta info |
954 |
|
|
|
955 |
|
|
my $meta = $enc->encode ({ |
956 |
|
|
name => $k, |
957 |
|
|
%{ $v->{meta} || {} }, |
958 |
|
|
}); |
959 |
|
|
|
960 |
|
|
$v->{data} = pack "(w/a*)*", $meta, $v->{data}; |
961 |
|
|
} |
962 |
|
|
|
963 |
|
|
make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients |
964 |
root |
1.79 |
} |
965 |
|
|
} |
966 |
|
|
|
967 |
root |
1.78 |
printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
968 |
|
|
scalar keys %FACEINFO, |
969 |
|
|
scalar keys %ANIMINFO, |
970 |
|
|
scalar keys %RESOURCE |
971 |
|
|
if $VERBOSE; |
972 |
|
|
|
973 |
root |
1.19 |
open my $fh, ">:perlio", "$DATADIR/facedata~" |
974 |
|
|
or die "$DATADIR/facedata~: $!"; |
975 |
root |
1.6 |
|
976 |
root |
1.82 |
print $fh nfreeze { |
977 |
root |
1.24 |
version => 2, |
978 |
|
|
faceinfo => \%FACEINFO, |
979 |
|
|
animinfo => \%ANIMINFO, |
980 |
root |
1.37 |
resource => \%RESOURCE, |
981 |
root |
1.24 |
}; |
982 |
root |
1.78 |
|
983 |
root |
1.5 |
} |
984 |
|
|
|
985 |
root |
1.53 |
print "committing files...\n" if $VERBOSE; |
986 |
|
|
|
987 |
root |
1.83 |
for (qw(archetypes facedata treasures), @COMMIT) { |
988 |
root |
1.6 |
chmod 0644, "$DATADIR/$_~"; |
989 |
root |
1.13 |
rename "$DATADIR/$_~", "$DATADIR/$_" |
990 |
|
|
or die "$DATADIR/$_: $!"; |
991 |
root |
1.6 |
} |
992 |
root |
1.13 |
|
993 |
|
|
print "archetype data installed successfully.\n"; |
994 |
root |
1.2 |
} |
995 |
|
|
} |
996 |
|
|
|
997 |
|
|
Getopt::Long::Configure ("bundling", "no_ignore_case"); |
998 |
|
|
GetOptions ( |
999 |
|
|
"verbose|v:+" => \$VERBOSE, |
1000 |
root |
1.3 |
"cache" => \$CACHE, |
1001 |
root |
1.2 |
"quiet|q" => sub { $VERBOSE = 0 }, |
1002 |
|
|
"force" => sub { $FORCE = 1 }, |
1003 |
|
|
"install-arch=s" => \&inst_arch, |
1004 |
|
|
"install-maps=s" => \&inst_maps, |
1005 |
|
|
"print-statedir" => sub { print "@pkgstatedir@\n" }, |
1006 |
|
|
"print-datadir" => sub { print "$DATADIR\n" }, |
1007 |
|
|
"print-confdir" => sub { print "@pkgconfdir@\n" }, |
1008 |
|
|
"print-libdir" => sub { print "@libdir@/@PACKAGE@\n" }, |
1009 |
|
|
"print-bindir" => sub { print "@bindir@/@PACKAGE@\n" }, |
1010 |
|
|
) or usage; |
1011 |
|
|
|