# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit desktop xdg

DESCRIPTION="Advanced cross-platform rhythm game focused on keyboard play (binary package)"
HOMEPAGE="https://etternaonline.com"
SRC_URI="https://github.com/etternagame/etterna/releases/download/v${PV}/Etterna-${PV}-Linux.tar.gz -> ${P}.tar.gz"

S="${WORKDIR}/Etterna"
LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"

RDEPEND="
	!games-arcade/etterna
	dev-libs/openssl:=
	media-libs/libglvnd
	media-libs/libogg
	net-misc/curl
	x11-libs/libX11
	x11-libs/libXrandr
"
DEPEND="${RDEPEND}"

QA_PREBUILT="/opt/etterna/Etterna"

src_install() {
	exeinto /opt/etterna
	newexe "${S}/Etterna" Etterna

	insinto /opt/etterna
	for dir in \
		Announcers \
		Assets \
		BackgroundEffects \
		BackgroundTransitions \
		BGAnimations \
		Data \
		NoteSkins \
		Scripts \
		Songs \
		Themes; do
		if [[ -d "${S}/${dir}" ]]; then
			cp -a "${S}/${dir}" "${T}/Default_${dir}" || die
			doins -r "${T}/Default_${dir}"
		fi
	done

	dobin "${FILESDIR}/etterna"

	newicon \
		"${S}/Themes/_fallback/Graphics/Common window icon.png" \
		etterna.png

	make_desktop_entry \
		etterna \
		Etterna \
		etterna \
		"Game;ArcadeGame;"
}

pkg_postinst() {
	xdg_pkg_postinst
	elog "Etterna stores user data in ~/.etterna."
	elog "Default assets are copied from /opt/etterna"
	elog "to ~/.etterna the first time the launcher is started."
}

pkg_postrm() {
	xdg_pkg_postrm
}