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

###
# True Fear: Forsaken Souls
# send your bug reports to bugs@dotslashplay.it
###

script_version=20250418.5

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID_EPISODE1='true-fear-forsaken-souls-1'
GAME_NAME_EPISODE1='True Fear: Forsaken Souls - Part 1'

GAME_ID_EPISODE2='true-fear-forsaken-souls-2'
GAME_NAME_EPISODE2='True Fear: Forsaken Souls - Part 2'

ARCHIVE_BASE_EPISODE1_1_NAME='setup_true_fear_forsaken_souls_part_1_2.0.10_(64bit)_(86246).exe'
ARCHIVE_BASE_EPISODE1_1_MD5='f3ff475c3cfe99b559eda57c14d3029b'
ARCHIVE_BASE_EPISODE1_1_TYPE='innosetup'
ARCHIVE_BASE_EPISODE1_1_SIZE='932520'
ARCHIVE_BASE_EPISODE1_1_VERSION='2.0.10-gog86246'
ARCHIVE_BASE_EPISODE1_1_URL='https://www.gog.com/game/true_fear_forsaken_souls'

ARCHIVE_BASE_EPISODE1_0_NAME='setup_true_fear_forsaken_souls_part_1_2.0.26_(43095).exe'
ARCHIVE_BASE_EPISODE1_0_MD5='12c98dc222047ba571e7c1ce3e6689c8'
ARCHIVE_BASE_EPISODE1_0_TYPE='innosetup'
ARCHIVE_BASE_EPISODE1_0_SIZE='660000'
ARCHIVE_BASE_EPISODE1_0_VERSION='2.0.2-gog43095'

ARCHIVE_BASE_EPISODE2_1_NAME='setup_true_fear_forsaken_souls_part_2_2.0.12_(64bit)_(86051).exe'
ARCHIVE_BASE_EPISODE2_1_MD5='dabf1b7292071d5145809c66ad26f4cc'
ARCHIVE_BASE_EPISODE2_1_TYPE='innosetup'
ARCHIVE_BASE_EPISODE2_1_SIZE='973169'
ARCHIVE_BASE_EPISODE2_1_VERSION='2.0.10-gog86051'
ARCHIVE_BASE_EPISODE2_1_URL='https://www.gog.com/game/true_fear_forsaken_souls_part_2'

ARCHIVE_BASE_EPISODE2_0_NAME='setup_true_fear_forsaken_souls_part_2_2.0.8_(49144).exe'
ARCHIVE_BASE_EPISODE2_0_MD5='e464cb8eedd9728249efde7593c75f79'
ARCHIVE_BASE_EPISODE2_0_TYPE='innosetup'
ARCHIVE_BASE_EPISODE2_0_SIZE='900000'
ARCHIVE_BASE_EPISODE2_0_VERSION='2.0.8-gog49144'

UNITY3D_NAME_EPISODE1='TrueFear1'
UNITY3D_NAME_EPISODE1_0='True Fear'
UNITY3D_NAME_EPISODE2='TrueFear2'
UNITY3D_NAME_EPISODE2_0='True Fear 2'
# TODO: Include an explicit list of Unity3D plugins.

CONTENT_PATH_DEFAULT='.'

WINE_PERSISTENT_DIRECTORIES_EPISODE1='
users/${USER}/AppData/Local/Goblinz/TrueFear_ForsakenSouls'
WINE_PERSISTENT_DIRECTORIES_EPISODE2='
users/${USER}/AppData/Local/Goblinz/True Fear 2'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN_DEPENDENCIES_GSTREAMER_PLUGINS='
video/quicktime, variant=(string)iso'
# Easier updates from pre-20250418.1 packages
PKG_BIN_PROVIDES_EPISODE1='
true-fear-1'
PKG_BIN_PROVIDES_EPISODE2='
true-fear-2'

PKG_DATA_ID_EPISODE1="${GAME_ID_EPISODE1}-data"
PKG_DATA_ID_EPISODE2="${GAME_ID_EPISODE2}-data"
PKG_DATA_DESCRIPTION='data'
# Easier updates from pre-20250418.1 packages
PKG_DATA_PROVIDES_EPISODE1='
true-fear-1-data'
PKG_DATA_PROVIDES_EPISODE2='
true-fear-2-data'

# Load common functions.

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
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit.sh.2 not found.\n'
	exit 1
fi
# shellcheck source=libplayit.sh.2
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
