root / veekun / trunk / script / create_downloads.pl

Revision 367, 5.3 kB (checked in by eevee, 10 months ago)

Added a cries tarball to the resources page. (#164)

Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use File::Basename;
6use File::Spec;
7use File::Temp qw/tempfile/;
8use YAML;
9
10# usage: create_downloads.pl
11
12my (undef, $path) = fileparse( File::Spec->rel2abs($0) );
13my $basepath = File::Spec->rel2abs( $path . '/..' );
14chdir $basepath;
15
16my ($fh, $tempfile) = tempfile;
17
18sub montage;
19sub tarball;
20
21# THAT'S CALLED A MONTAGE...  MONTAAAGE~
22montage "green/%03d.png",       "montage-green.png",        60, 151;
23montage "redblue/%03d.png",     "montage-redblue.png",      60, 151;
24montage "yellow/%03d.png",      "montage-yellow.png",       60, 151;
25montage "oldback/%03d.png",     "montage-rby-back.png",     60, 151;
26
27montage "gold/%03d.png",        "montage-gold.png",         60, 251;
28montage "silver/%03d.png",      "montage-silver.png",       60, 251;
29montage "gold/shiny/%03d.png""montage-gold-shiny.png",   60, 251;
30montage "silver/shiny/%03d.png","montage-silver-shiny.png", 60, 251;
31montage "newback/%03d.png",     "montage-gsc-back.png",     60, 251;
32
33montage "frlg/%03d.png",        "montage-frlg.png",         64, 151;
34montage "rusa/%03d.png",        "montage-rusa.png",         64, 386;
35montage "rusa/shiny/%03d.png""montage-rusa-shiny.png",   64, 386;
36montage "rusaback/%03d.png",    "montage-rusa-back.png",    64, 386;
37
38montage "dp/%03d.png",          "montage-dp.png",           80, 493;
39montage "dp/frame2/%03d.png",   "montage-dp-frame2.png",    80, 493;
40montage "dp/shiny/%03d.png",    "montage-dp-shiny.png",     80, 493;
41montage "dp/back/%03d.png",     "montage-dp-back.png",      80, 493;
42montage "dp/%03df.png",         "montage-dp-female.png",    80, 493;
43
44# TODO: undupe this code.  like, next time you touch this.  yeah.  then.
45if (-e "root/files/sprites/montage-berries.png") {
46    print "montage-berries.png exists; skipping.\n";
47} else {
48    print "Generating montage-berries.png...\n";
49
50    chdir 'root/dex-images/items/big';
51    my @berries = glob('*-berry.png');
52    my @berry_params;
53    for my $file (@berries) {
54        (my $berry = $file) =~ s/-berry\.png$//;
55        push @berry_params, '-label', ucfirst $berry, $file;
56    }
57    system montage =>
58        '-geometry', '+4+4',
59        @berry_params,
60        "png:$tempfile";
61    chdir $basepath;
62
63    print "Crushing...\n";
64
65    system pngcrush => '-q',
66        $tempfile => 'root/files/sprites/montage-berries.png';
67
68    print "Done.\n";
69}
70
71if (-e "root/files/sprites/montage-items.png") {
72    print "montage-items.png exists; skipping.\n";
73} else {
74    print "Generating montage-items.png...\n";
75
76    my @files = glob('root/dex-images/items/*.png');
77    my $cols = int(sqrt(scalar @files) / 5 + 1) * 5;
78
79    system montage =>
80        '-geometry' => '+0+0',
81        '-tile' => $cols . 'x',
82        'root/dex-images/items/*.png',
83        "png:$tempfile";
84    chdir $basepath;
85
86    print "Crushing...\n";
87
88    system pngcrush => '-q',
89        $tempfile => 'root/files/sprites/montage-items.png';
90
91    print "Done.\n";
92}
93# even Rocky had a montage...
94
95
96# I don't have a funny movie quote for tarballs.
97# Teehee.  Balls.
98tarball items => 'root/dex-images/items', qw/ *.png rsefl /;
99tarball rby => 'root/dex-images', qw/ redblue yellow oldback /;
100tarball gsc => 'root/dex-images', qw/ gold silver crystal newback /;
101tarball rse => 'root/dex-images', qw/ rusa rusaback emerald frlg /;
102tarball dp  => 'root/dex-images', qw/ dp /;
103tarball pawprints => 'root/dex-images/footpaws', '*.png';
104tarball berries => 'root/dex-images/items/big', '*-berry.png';
105
106tarball cries => 'root/files/cries', '*.mp3';
107
108# functions ahoy
109
110sub montage {
111    my ($pattern, $outfile, $size, $max) = @_;
112    $pattern = "root/dex-images/$pattern";
113    my $outpath = "root/files/sprites/$outfile";
114
115    if (-e $outpath) {
116        print "$outfile exists; skipping.\n";
117        return;
118    }
119
120    print "Generating $outfile...\n";
121
122    my @files =
123        map { -e $_ ? $_ : 'null:' }
124        map { sprintf $pattern, $_ }
125        1 .. $max;
126
127    # this will make the grid roughly square, width divisible by 5 and longer than height
128    my $cols = int(sqrt($max) / 5 + 1) * 5;
129    system montage =>
130        '-geometry' => "${size}x${size}+0+0"# since some females might be null
131        '-tile'     => $cols . 'x',
132        @files,
133        "png:$tempfile";
134
135    print "Crushing...\n";
136
137    system pngcrush => '-q',
138        $tempfile => $outpath;
139
140    print "Done.\n";
141}
142
143sub dp_montage {
144    my ($pattern, $outfile) = @_;
145    montage("dp/$pattern", $outfile, 80, 493);
146}
147
148sub tarball {
149    my ($outfile, $path, @files) = @_;
150    my $subfolder = 'sprites';
151    if ($outfile eq 'cries') {
152        # Hack
153        $subfolder = 'cries';
154    }
155    my $outpath = File::Spec->rel2abs("$basepath/root/files/$subfolder/$outfile.tgz");
156
157    if (-e $outpath) {
158        print "$outfile.tgz exists; skipping.\n";
159        return;
160    }
161
162    print "Generating $outfile.tgz...\n";
163
164    # --force-local is required for absolute win32 path names; tar assumes
165    # paths with colons are addresses on other machines
166    chdir $path;
167    @files = map { glob $_ } @files;  # on Linux expansion is done by the shell
168    system tar => '--force-local', '--exclude=.svn', '-czf', $outpath, @files;
169    chdir $basepath;
170
171    print "Done.\n";
172}
173
Note: See TracBrowser for help on using the browser.