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

inherit eutils games

DESCRIPTION="Postal 2: Apocalypse Weekend expansion"
HOMEPAGE="http://www.gopostal.com/"
SRC_URI=""

LICENSE="postal2"
SLOT="0"
KEYWORDS="~x86"
IUSE=""
RESTRICT="nostrip"

DEPEND="app-arch/unrar
	>=postal2-1409.1"
RDEPEND="amd64? (
		app-emulation/emul-linux-x86-baselibs
		app-emulation/emul-linux-x86-xlibs
		>=media-video/nvidia-glx-1.0.6629-r3
	)
	|| ( 
		x11-libs/libXext
		 virtual/x11 )"

dir=${GAMES_PREFIX_OPT}/postal2
Ddir=${D}/${dir}
awdir=${dir}/ApocalypseWeekend
awDdir=${D}/${awdir}

pkg_setup() {
	check_license postal2
	games_pkg_setup
}

src_install() {
	cdrom_get_cds
	dodir "${awdir}"

	unpack_makeself "${CDROM_ROOT}"/postal2aw-linux-installer.sh || die "Unpacking files"

	cp -r System "${awDdir}"

	echo "Copying files from the CD . . . "

	cp -r "${CDROM_ROOT}"/{Animations,KarmaData,Maps,Movies,Music,Sounds,StaticMeshes,System,"AW Manual (US).pdf"} "${awDdir}"
	
	# Extract textures from the rar archive
	unrar e -o+ "${CDROM_ROOT}"/Textures/Textures.exe

	mkdir "${awDdir}"/Textures
	cp *.utx "${awDdir}"/Textures/

	rm -r "${awDdir}"/System/{EditorRes,*.dll,*.DLL,*.exe,*.ico,*.lib,DefaultAW.ini,DefUserAW.ini,DefUnrealEd.ini,EdSplash.bmp}

	games_make_wrapper ${PN} './postal2-bin "-INI=ApocalypseWeekend.ini" "-USERINI=ApocalypseWeekendUser.ini" "-SAVEDGAMEINI=ApocalypseWeekendSavedGameInfo.ini" "-BASEDIR=../ApocalypseWeekend/System"' "${dir}/System/"

	doicon ${PN}.xpm

	prepgamesdirs

	make_desktop_entry ${PN} "Postal 2: Apocalypse Weekend" ${PN}.xpm
	
}

pkg_postinst() {
	games_pkg_postinst
	echo
	einfo "Postal 2: Apocalypse Weekend"
	einfo "has been successfully installed."
	echo
	einfo "To play, type: ${PN}"
	echo
}