#!/bin/bash

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

for x in $svgdir/*.svg
do
    filename=`basename $x`
    rsvg-convert $x -w $tilesize -h $tilesize -o $common/${filename/svg/png}
done

for tiledir in $common
do
    for hv in $tiledir/*-v.png
    do
        echo "convert -rotate 90 $hv ${hv/-v.png/-h.png}"
        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
