# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=3

inherit eutils games

MY_PN="Hammerfight"
DESCRIPTION="A game about 2D battles of flying machines equipped with various slashing, piercing and blunt weaponry"
HOMEPAGE="http://www.koshutin.com/"

HIBPAGE="http://www.humblebundle.com"
SRC_URI="${PN}_${PV}_all.tar.gz"

RESTRICT="fetch"
LICENSE="as-is"

SLOT="0"
KEYWORDS="amd64 x86"
IUSE=""

RDEPEND="media-libs/libsdl[audio,joystick,video]
	 media-libs/openal"

S="${WORKDIR}/${PN}"

GAMEDIR="${GAMES_PREFIX_OPT}/${PN}"

pkg_nofetch() {
	einfo ""
	einfo "Please buy and download \"${SRC_URI}\" from:"
	einfo "   ${HIBPAGE}"
	einfo "and move/link it to \"${DISTDIR}\""
	einfo ""
}

src_install() {
	insinto "${GAMEDIR}" || die "insinto \"${GAMEDIR}\" failed"
	# Dirs:
	find . -maxdepth 1 -mindepth 1 -type d ! -iname amd64 ! -iname x86 -exec doins -r '{}' \+ || die "doins data failed"
	# Configs:
	doins *.ini *.script strings.txt || die "doins config failed"

	exeinto "${GAMEDIR}" || die "exeinto \"${GAMEDIR}\" failed"
	if use amd64
	then
	  newexe "${MY_PN}-amd64" "${PN}" || die "newexe \"${MY_PN}\" failed"
	fi
	if use x86
	then
	  newexe "${MY_PN}-x86" "${PN}" || die "newexe \"${MY_PN}\" failed"
	fi

	# Make game wrapper
	games_make_wrapper "${PN}" "./${PN}" "${GAMEDIR}" || die "games_make_wrapper \"./${PN}\" failed"

	# Install icon and desktop file
	local icon="${PN}.png"
	doicon "${icon}" || die "doicon \"${icon}\" failed"
	make_desktop_entry "${PN}" "${MY_PN}" "/usr/share/pixmaps/${icon}" || die "make_desktop_entry failed"

	# Install documentation
	find . -maxdepth 1 -iname "readme*" -exec dodoc '{}' \+ || die "dodoc failed"

	# Setting permissions
	prepgamesdirs
}

pkg_postinst() {
	echo ""
	games_pkg_postinst

	einfo "Please report any bugs here:"
	einfo "   http://bugzilla.icculus.org/"
	einfo "An email list for discussion (not bug reports!) is available here:"
	einfo "   http://icculus.org/mailman/listinfo/${PN}"
	echo ""
	einfo "${MY_PN} savegames and configurations are stored in:"
	einfo "   \${HOME}/.local/share/${MY_PN}"
	echo ""
}