root/veekun/trunk/script/create_downloads.pl @ 248

Revision 248, 5.0 KB (checked in by eevee, 2 years ago)

Created a script to generate tarballs and montages of sprites. Huzzah. (#17)

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
106
107# functions ahoy
108
109sub montage {
110    my ($pattern, $outfile, $size, $max) = @_;
111    $pattern = "root/dex-images/$pattern";
112    my $outpath = "root/files/sprites/$outfile";
113
114    if (-e $outpath) {
115        print "$outfile exists; skipping.\n";
116        return;
117    }
118
119    print "Generating $outfile...\n";
120
121    my @files =
122        map { -e $_ ? $_ : 'null:' }
123        map { sprintf $pattern, $_ }
124        1 .. $max;
125
126    # this will make the grid roughly square, width divisible by 5 and longer than height
127    my $cols = int(sqrt($max) / 5 + 1) * 5;
128    system montage =>
129        '-geometry' => "${size}x${size}+0+0",  # since some females might be null
130        '-tile'     => $cols . 'x',
131        @files,
132        "png:$tempfile";
133
134    print "Crushing...\n";
135
136    system pngcrush => '-q',
137        $tempfile => $outpath;
138
139    print "Done.\n";
140}
141
142sub dp_montage {
143    my ($pattern, $outfile) = @_;
144    montage("dp/$pattern", $outfile, 80, 493);
145}
146
147sub tarball {
148    my ($outfile, $path, @files) = @_;
149    my $outpath = File::Spec->rel2abs("$basepath/root/files/sprites/$outfile.tgz");
150
151    if (-e $outpath) {
152        print "$outfile.tgz exists; skipping.\n";
153        return;
154    }
155
156    print "Generating $outfile.tgz...\n";
157
158    # --force-local is required for absolute win32 path names; tar assumes
159    # paths with colons are addresses on other machines
160    chdir $path;
161    system tar => '--force-local', '--exclude=.svn', '-czf', $outpath, @files;
162    chdir $basepath;
163
164    print "Done.\n";
165}
166
167
Note: See TracBrowser for help on using the browser.