| 1 | |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use File::Basename; |
|---|
| 6 | use File::Spec; |
|---|
| 7 | use File::Temp qw/tempfile/; |
|---|
| 8 | use YAML; |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | my (undef, $path) = fileparse( File::Spec->rel2abs($0) ); |
|---|
| 13 | my $basepath = File::Spec->rel2abs( $path . '/..' ); |
|---|
| 14 | chdir $basepath; |
|---|
| 15 | |
|---|
| 16 | my ($fh, $tempfile) = tempfile; |
|---|
| 17 | |
|---|
| 18 | sub montage; |
|---|
| 19 | sub tarball; |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | montage "green/%03d.png", "montage-green.png", 60, 151; |
|---|
| 23 | montage "redblue/%03d.png", "montage-redblue.png", 60, 151; |
|---|
| 24 | montage "yellow/%03d.png", "montage-yellow.png", 60, 151; |
|---|
| 25 | montage "oldback/%03d.png", "montage-rby-back.png", 60, 151; |
|---|
| 26 | |
|---|
| 27 | montage "gold/%03d.png", "montage-gold.png", 60, 251; |
|---|
| 28 | montage "silver/%03d.png", "montage-silver.png", 60, 251; |
|---|
| 29 | montage "gold/shiny/%03d.png", "montage-gold-shiny.png", 60, 251; |
|---|
| 30 | montage "silver/shiny/%03d.png","montage-silver-shiny.png", 60, 251; |
|---|
| 31 | montage "newback/%03d.png", "montage-gsc-back.png", 60, 251; |
|---|
| 32 | |
|---|
| 33 | montage "frlg/%03d.png", "montage-frlg.png", 64, 151; |
|---|
| 34 | montage "rusa/%03d.png", "montage-rusa.png", 64, 386; |
|---|
| 35 | montage "rusa/shiny/%03d.png", "montage-rusa-shiny.png", 64, 386; |
|---|
| 36 | montage "rusaback/%03d.png", "montage-rusa-back.png", 64, 386; |
|---|
| 37 | |
|---|
| 38 | montage "dp/%03d.png", "montage-dp.png", 80, 493; |
|---|
| 39 | montage "dp/frame2/%03d.png", "montage-dp-frame2.png", 80, 493; |
|---|
| 40 | montage "dp/shiny/%03d.png", "montage-dp-shiny.png", 80, 493; |
|---|
| 41 | montage "dp/back/%03d.png", "montage-dp-back.png", 80, 493; |
|---|
| 42 | montage "dp/%03df.png", "montage-dp-female.png", 80, 493; |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | if (-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 | |
|---|
| 71 | if (-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 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | tarball items => 'root/dex-images/items', qw/ *.png rsefl /; |
|---|
| 99 | tarball rby => 'root/dex-images', qw/ redblue yellow oldback /; |
|---|
| 100 | tarball gsc => 'root/dex-images', qw/ gold silver crystal newback /; |
|---|
| 101 | tarball rse => 'root/dex-images', qw/ rusa rusaback emerald frlg /; |
|---|
| 102 | tarball dp => 'root/dex-images', qw/ dp /; |
|---|
| 103 | tarball pawprints => 'root/dex-images/footpaws', '*.png'; |
|---|
| 104 | tarball berries => 'root/dex-images/items/big', '*-berry.png'; |
|---|
| 105 | |
|---|
| 106 | tarball cries => 'root/files/cries', '*.mp3'; |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | sub 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 | |
|---|
| 128 | my $cols = int(sqrt($max) / 5 + 1) * 5; |
|---|
| 129 | system montage => |
|---|
| 130 | '-geometry' => "${size}x${size}+0+0", |
|---|
| 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 | |
|---|
| 143 | sub dp_montage { |
|---|
| 144 | my ($pattern, $outfile) = @_; |
|---|
| 145 | montage("dp/$pattern", $outfile, 80, 493); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | sub tarball { |
|---|
| 149 | my ($outfile, $path, @files) = @_; |
|---|
| 150 | my $subfolder = 'sprites'; |
|---|
| 151 | if ($outfile eq 'cries') { |
|---|
| 152 | |
|---|
| 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 | |
|---|
| 165 | |
|---|
| 166 | chdir $path; |
|---|
| 167 | @files = map { glob $_ } @files; |
|---|
| 168 | system tar => '--force-local', '--exclude=.svn', '-czf', $outpath, @files; |
|---|
| 169 | chdir $basepath; |
|---|
| 170 | |
|---|
| 171 | print "Done.\n"; |
|---|
| 172 | } |
|---|
| 173 | |
|---|