#!/usr/bin/env fish

set sizes 16 24 32 48 64 128 256 512 1024
set hidpi 32 48 64 96 128 256 512 1024 2048
set numsize 9

mkdir -p resources/icons
rm -f resources/icons/* resources/icons.qrc

echo "<RCC>" > resources/icons.qrc
echo '<qresource prefix="/tycho">' >> resources/icons.qrc

function conv_icon -a out sz inf
	rsvg-convert -w "$sz" -h "$sz" -f svg -o "$out" "$inf" &
end

function compress -a out
	pigz --best -fm -S z "$out"
end

function comp_icon -a f i
	set sz $sizes[$i]
	set hz $hidpi[$i]
	set out icons/(basename -s .svg "$f")_$sz
	set out_s $out.svg
	set out_h $out@2x.svg
	echo \t"<file>$out_s""z</file>" >> resources/icons.qrc
	echo \t"<file>$out_h""z</file>" >> resources/icons.qrc
	set out_s resources/$out_s
	set out_h resources/$out_h
	conv_icon "$out_s" "$sz" "$f"
	conv_icon "$out_h" "$hz" "$f"
	wait rsvg-convert
	compress "$out_s"
	compress "$out_h"
end

for f in resources/mini/*.svg
	for i in (seq 1 "$numsize")
		comp_icon "$f" "$i"
	end
end

echo "</qresource>" >> resources/icons.qrc
echo "</RCC>" >> resources/icons.qrc

echo "done"

## EOF
