# SliTaz package receipt.

PACKAGE="chess3d"
VERSION="1.0"
CATEGORY="games"
SHORT_DESC="3D Chess game in javascript"
TARBALL="$PACKAGE-$VERSION.tar.lzma"
MAINTAINER="pascal.bellard@slitaz.org"
WEB_SITE="http://chessforeva.appspot.com/"

# Rules to configure and make the package.
compile_rules()
{
	mkdir $src
	cd $src
	if [ ! -s C0_Toledo.htm ] &&
		wget http://mirror.slitaz.org/sources/packages/c/$TARBALL; then
		unlzma -c $TARBALL | tar xf -
		mv $PACKAGE-$VERSION/* .
	fi
	mkdir arts d_img img
	for i in C0_Toledo.htm c0_pgn.js c0_chess.js ; do
		[ -s $i ] && continue
		wget ${WEB_SITE}$i || return 1
		dos2unix $i
	done
	for i in arts/a_arrow ; do
		[ -s $i.gif ] && continue
		wget -P arts ${WEB_SITE}$i.gif || return 1
	done
	for i in b_plus1 b_minus1 b_topview oie_arrow_white ; do
		[ -s img/$i.gif ] && continue
		wget -P img ${WEB_SITE}img/$i.gif || return 1
	done
	for i in t oie ; do
		for j in board letters letters2 ; do
			f=${i}_$j.gif
			[ -s img/$f ] && continue
			wget -P img ${WEB_SITE}img/$f || return 1
		done
		for j in w b ; do
			for k in pawn rook knight1 knight2 bishop qeen king ; do
				f=${i}_${j}$k.gif
				[ -s img/$f ] && continue
				wget -P img ${WEB_SITE}img/$f || return 1
			done
		done
	done
	sed -i	-e 's/var THide=.*/var THide=1;/' \
		-e 's/var Tnoback=.*/var Tnoback=1;/' \
		-e 's/c0_topview=true;/&\nc0_ch_topview();/' \
		-e 's|http://chess.*com/||' \
		-e 's|http://www.ltn.lv/~gv/to.*gif|img/b_minus1.gif|' \
		-e "s|${WEB_SITE}||" \
			C0_Toledo.htm
	sed -i	-e "s|${WEB_SITE}||" *.js
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
        mkdir -p $fs/var/www/chess3d $fs/usr/share/applications
	cp -a $src/* $fs/var/www/chess3d
	mv $fs/var/www/chess3d/C0_Toledo.htm $fs/var/www/chess3d/index.html
	chown -R 80.80 $fs/var/www/chess3d
	cat > $fs/usr/share/applications/chess3d.desktop <<EOT
[Desktop Entry]
Type=Application
Name=Chess3d
Exec=browser file:///var/www/chess3d/index.html
Icon=chess3d
Terminal=false
Categories=Game;
Comment=3d chess game
EOT
}