# Copyright 2019 Julian Ospald <hasufell@posteo.de>
# Distributed under the terms of the GNU General Public License v2

require gog [ installer="stardew_valley_1_4_5_433754439_36068.sh" ]
require desktop-utils

SUMMARY="Stardew Valley is a farming simulation role-playing video game"
HOMEPAGE="https://www.gog.com/game/stardew_valley"

SLOT="0"
PLATFORMS="-* ~amd64 ~x86"
MYOPTIONS="
    ( platform: amd64 x86 )
"

DEPENDENCIES="
    run:
        media-libs/fontconfig
        media-libs/freetype
        x11-apps/xterm
        x11-dri/mesa
"

src_install() {
    local arch=$(option platform:amd64 "x86_64" "x86")
    local noarch=$(option platform:amd64 "x86" "x86_64")
    local nolib=$(option platform:amd64 "lib" "lib64")

    herebin ${PN} <<EOF
#!/bin/sh
cd "${GOG_INSTALL_DIR}/game"
export TERM=xterm
exec "./StardewValley.bin.${arch}" "\$@"
EOF

    install_desktop_entry "Name=Stardew Valley"

    edo rm "${WORK}/game/StardewValley.bin.${noarch}"
    edo rm -r "${WORK}/game/${nolib}"

    insinto "${GOG_INSTALL_DIR}"
    doins -r "${WORK}/game"
    edo chmod +x "${IMAGE%/}${GOG_INSTALL_DIR}/game/StardewValley.bin.${arch}"
    edo ln -sf mcs.bin.${arch} "${IMAGE%/}${GOG_INSTALL_DIR}"/game/mcs
}