# Copyright 2023 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit cmake

DESCRIPTION="Amnesia: The Dark Descent"
HOMEPAGE="https://frictionalgames.com/ https://github.com/shamazmazum/AmnesiaTheDarkDescent"

SRC_URI="https://github.com/shamazmazum/AmnesiaTheDarkDescent/archive/refs/tags/v${PV}.tar.gz -> AmnesiaTheDarkDescent-${PV}.tar.gz"
S="${WORKDIR}/AmnesiaTheDarkDescent-${PV}"

# GPL-3+: amnesia-tdd
# zlib: AngelScript, Newton Dynamics and OALWrapper
LICENSE="GPL-3+ ZLIB"
SLOT="0"
KEYWORDS="~amd64"

DEPEND="
	media-libs/devil
	media-libs/glew:=
	media-libs/glu
	media-libs/libogg
	media-libs/libsdl2
	media-libs/libtheora:=
	media-libs/libvorbis
	media-libs/openal
	sys-libs/zlib:=
	virtual/opengl
"
RDEPEND="${DEPEND}"

CMAKE_USE_DIR="${S}/amnesia/src"

PATCHES=(
	"${FILESDIR}/0.3.3-0001-Use-Modern-OpenGL.patch"
	"${FILESDIR}/0.3.3-0002-Remove-obsoleted-gfx-code.patch"
	"${FILESDIR}/0.3.3-0003-Set-standard-to-C-14.patch"
	"${FILESDIR}/0.3.3-0004-Newton-core-dgTypes.h-include-cstdint-for-int32_t.patch"
)

src_prepare() {
	default
	rm amnesia/src/launcher/glut32.lib || die
}

src_configure() {
	local mycmakeargs=(
		-DSYSTEMWIDE_RESOURCES=ON
		-DSYSTEMWIDE_RESOURCES_LOCATION="${EPREFIX}/usr/share/amnesia-tdd"
		-DOpenGL_GL_PREFERENCE=GLVND
	)

	cmake_src_configure
}