#!/bin/bash

tilesize=20
svgdir=source/svg
pngdir=data/tiles

for subdir in common/snake lab
do
    for x in $svgdir/$subdir/*.svg
    do
        filename=`basename $x`
        filepath=$pngdir/$subdir/${filename/svg/png}
        rsvg-convert $x -w $tilesize -h $tilesize -o $filepath
        pngcrush -q $filepath tmp && mv tmp $filepath
    done
done

shopt -s nullglob

for tiledir in $pngdir/common/snake $pngdir/lab
do
    for hv in $tiledir/*-v.png
    do
        convert -rotate 90 $hv ${hv/-v.png/-h.png}
    done

    for lrud in $tiledir/*-r.png
    do
        convert -rotate 90 $lrud ${lrud/-r.png/-d.png}
        convert -rotate 180 $lrud ${lrud/-r.png/-l.png}
        convert -rotate 270 $lrud ${lrud/-r.png/-u.png}
    done

    for tblr in $tiledir/*-tl.png
    do
        convert -rotate 90 $tblr ${tblr/-tl.png/-tr.png}
        convert -rotate 180 $tblr ${tblr/-tl.png/-br.png}
        convert -rotate 270 $tblr ${tblr/-tl.png/-bl.png}
    done
done
