#!/bin/ash
BASEDIR="/usr/share/pixmaps"
BACKGROUND="/usr/share/backgrounds/default.jpg"

draw_svg(){
i=0
SVG='<svg width="640" height="480">
<image x="1" y="1" width="640" height="480" xlink:href="'$BACKGROUND'" />
'
while ([ $i -lt ${#1} ]) do
#replace with eval echo \${GRID:$i:1}
[ "${1:$i:1}" != " " ] && SVG=$SVG'	<image x="'$(($i % 13 * 48))'" y="'$(($i / 13 * 48))'" width="48" height="48" xlink:href="'`eval echo \$"${1:$i:1}"`'" />
'
i=$(($i+1))
done
echo "$SVG</svg>" >svgame.svg
}



#faking a 12x9 2d array for bourne shells using a string and mod/div ops.
#each letter represents a 48x48 pixel square on a 640x480 grid
GRID=""
GRID="${GRID}             "
GRID="${GRID}             "
GRID="${GRID}             "
GRID="${GRID}             "
GRID="${GRID}      p      "
GRID="${GRID}          q  "
GRID="${GRID}             "
GRID="${GRID}             "
GRID="${GRID}             "
GRID="${GRID}             "
#Sprites and Tilesets
p="$BASEDIR/cd.png"
q="$BASEDIR/deb.png"
draw_svg "${GRID}"
