#!/bin/sh
# SPDX-License-Identifier: ACSL
# SPDX-FileCopyrightText: © 2017 Antoine Le Gonidec <vv221@dotslashplay.it>
set -o errexit

###
# Pandora: First Contact
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260101.4

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='pandora-first-contact'
GAME_NAME='Pandora: First Contact'

ARCHIVE_BASE_0_NAME='pandora_first_contact_en_1_6_7_16815.sh'
ARCHIVE_BASE_0_MD5='0d9343d1693fc561823811a0cd3e279c'
ARCHIVE_BASE_0_SIZE='720000'
ARCHIVE_BASE_0_VERSION='1.6.7-gog16815'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/pandora'

## Optional icons pack
ARCHIVE_OPTIONAL_ICONS_NAME='pandora-first-contact_icons.tar.gz'
ARCHIVE_OPTIONAL_ICONS_MD5='66b1d99166b738b2130449a49b9cd58c'
ARCHIVE_OPTIONAL_ICONS_URL='http://downloads.dotslashplay.it/games/pandora-first-contact/'
CONTENT_ICONS_PATH='.'
CONTENT_ICONS_FILES='
256x256'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_LIBS_BIN_RELATIVE_PATH='Binaries'
CONTENT_LIBS_BIN_FILES='
libavcodec.so.53
libavformat.so.53
libavutil.so.51
libboost_date_time.so.1.58.0
libboost_filesystem.so.1.58.0
libboost_locale.so.1.58.0
libboost_regex.so.1.58.0
libboost_system.so.1.58.0
libboost_thread.so.1.58.0
libGLEW.so.1.6
libjpeg.so.8
libpng15.so.15
libswscale.so.2'
CONTENT_GAME_BIN_FILES='
Binaries/Pandora.bin
Binaries/PandoraServer.bin'
CONTENT_GAME_L10N_FR_FILES='
Data/Core/Languages/French
Data/Cinematics/Clips/Languages/French/Intro.mkv'
CONTENT_GAME_L10N_DE_FILES='
Data/Core/Languages/German
Data/Cinematics/Clips/Languages/German/Intro.mkv'
CONTENT_GAME_L10N_EN_FILES='
Data/Cinematics/Clips/Languages/English/Intro.mkv'
CONTENT_GAME_L10N_VOICES_DE_FILES='
Data/Audio/Sounds/Languages/German
Data/Cinematics/Clips/Languages/German/Intro.ogg'
CONTENT_GAME_L10N_VOICES_EN_FILES='
Data/Audio/Sounds/Languages/English
Data/Cinematics/Clips/Languages/English/Intro.ogg'
CONTENT_GAME_DATA_FILES='
Data/GUI
Data/Scene
Data/Video
Data/World
Data/Audio/Music
Data/Audio/Sounds/Ambient
Data/Audio/Sounds/Explosions
Data/Audio/Sounds/Interface
Data/Audio/Sounds/Operations
Data/Audio/Sounds/Units
Data/Audio/Sounds/Weapons
Data/Cinematics/Clips/Factions
Data/Cinematics/Clips/Invasion.mkv
Data/Cinematics/Clips/Invasion.ogg
Data/Cinematics/Clips/MenuScreenFirstContact.mkv
Data/Cinematics/Clips/MenuScreen.mkv'
## English texts must be included to prevent a crash on launch.
CONTENT_GAME0_DATA_FILES='
Data/Core/Languages/English'
CONTENT_DOC_DATA_RELATIVE_PATH='Documents'
CONTENT_DOC_DATA_FILES='
Licenses
PandoraWebsite.url'
CONTENT_DOC0_DATA_RELATIVE_PATH='Documents/English'
CONTENT_DOC0_DATA_FILES='
Manual.pdf
ManualPrinterFriendly.pdf
ChangeLog.txt'
CONTENT_DOC_L10N_FR_RELATIVE_PATH='Documents/French'
CONTENT_DOC_DATA_FILES='
Intro.txt
ReadMe.txt'
CONTENT_DOC_L10N_DE_RELATIVE_PATH='Documents/German'
CONTENT_DOC_DATA_FILES='
Intro.txt
ReadMe.txt'
CONTENT_DOC_L10N_EN_RELATIVE_PATH='Documents/English'
CONTENT_DOC_DATA_FILES='
Intro.txt
ReadMe.txt'

APP_MAIN_EXE='Binaries/Pandora.bin'
APP_MAIN_ICON='../support/icon.png'

PACKAGES_LIST='
PKG_BIN
PKG_L10N_FR
PKG_L10N_DE
PKG_L10N_EN
PKG_L10N_VOICES_DE
PKG_L10N_VOICES_EN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_L10N
PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libbz2.so.1
libc.so.6
libcurl.so.4
libfreetype.so.6
libgcc_s.so.1
libglfw.so.3
libGL.so.1
libGLU.so.1
libm.so.6
libopenal.so.1
libpthread.so.0
librt.so.1
libstdc++.so.6
libvorbisfile.so.3
libX11.so.6
libXi.so.6
libXrandr.so.2
libXxf86vm.so.1
libz.so.1'

PKG_L10N_ID="${GAME_ID}-l10n"
PKG_L10N_FR_ID="${PKG_L10N_ID}-fr"
PKG_L10N_DE_ID="${PKG_L10N_ID}-de"
PKG_L10N_EN_ID="${PKG_L10N_ID}-en"
PKG_L10N_PROVIDES="
$PKG_L10N_ID"
PKG_L10N_DESCRIPTION_FR='French localisation'
PKG_L10N_DESCRIPTION_DE='German localisation'
PKG_L10N_DESCRIPTION_EN='English localisation'
PKG_L10N_DEPENDENCIES_SIBLINGS='
PKG_L10N_VOICES'

PKG_L10N_VOICES_ID="${PKG_L10N_ID}-voices"
PKG_L10N_VOICES_DE_ID="${PKG_L10N_VOICES_ID}-de"
PKG_L10N_VOICES_EN_ID="${PKG_L10N_VOICES_ID}-en"
PKG_L10N_VOICES_PROVIDES="
$PKG_L10N_VOICES_ID"
PKG_L10N_VOICES_DE_PROVIDES="$PKG_L10N_VOICES_PROVIDES"
PKG_L10N_VOICES_EN_PROVIDES="$PKG_L10N_VOICES_PROVIDES"
PKG_L10N_VOICES_DESCRIPTION_DE='German voices'
PKG_L10N_VOICES_DESCRIPTION_EN='English voices'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'

# Load common functions.

## Scan library paths used by ./play.it ≥ 2.35.
if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${HOME}/.local/lib/play.it" \
		'/usr/local/lib/play.it' \
		'/usr/lib/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit.sh.2"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
## Scan library paths used by ./play.it < 2.35.
## This can go away when PLAYIT_COMPATIBILITY_LEVEL is bumped to 2.35 or higher.
if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${XDG_DATA_HOME:="${HOME}/.local/share"}/play.it" \
		'/usr/local/share/games/play.it' \
		'/usr/local/share/play.it' \
		'/usr/share/games/play.it' \
		'/usr/share/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit2.sh"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
## Error out if the library can not be found.
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit2.sh not found.\n'
	exit 1
fi
# shellcheck source=libplayit2.sh
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default
## Set the required execution permissions on the server binary.
chmod 755 "${PLAYIT_WORKDIR}/gamedata/$(content_path_default)/Binaries/PandoraServer.bin"

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

## Run the game binary from its parent directory.
game_exec_line() {
	cat <<- 'EOF'
	# Run the game binary from its parent directory.
	cd Binaries
	./Pandora.bin "$@"
	EOF
}

launchers_generation

# Build packages.

packages_generation
case "$(messages_language)" in
	('fr')
		lang_string='version %s :'
		lang_fr='française'
		lang_de='allemande'
		lang_en='anglaise'
	;;
	('en'|*)
		lang_string='%s version:'
		lang_fr='French'
		lang_de='German'
		lang_en='English'
	;;
esac
printf '\n'
printf "$lang_string" "$lang_fr"
print_instructions 'PKG_BIN' 'PKG_DATA' 'PKG_L10N_FR' 'PKG_L10N_VOICES_EN'
printf "$lang_string" "$lang_de"
print_instructions 'PKG_BIN' 'PKG_DATA' 'PKG_L10N_DE' 'PKG_L10N_VOICES_DE'
printf "$lang_string" "$lang_en"
print_instructions 'PKG_BIN' 'PKG_DATA' 'PKG_L10N_EN' 'PKG_L10N_VOICES_EN'

# Clean up.

working_directory_cleanup

exit 0
