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

###
# Total Overdose
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260321.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='total-overdose'
GAME_NAME='Total Overdose'

ARCHIVE_BASE_0_NAME='setup_total_overdose_1.00_(18925).exe'
ARCHIVE_BASE_0_MD5='df9f6750e5f12fd83ee775365dfd9637'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='1700000'
ARCHIVE_BASE_0_VERSION='1.00-gog18925'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/total_overdose_a_gunslingers_tale_in_mexico'

CONTENT_PATH_DEFAULT='app'
# TODO: Check is all libraries are required.
CONTENT_LIBS_BIN_FILES='
binkw32.dll
DieselPowerImplementation.dll'
CONTENT_GAME_BIN_FILES='
TOD.exe'
CONTENT_GAME_DATA_FILES='
dpconfig.dpc
blocks.naz
sounds.naz
videos00.naz
videos01.naz'
# TODO: Move localisation to a dedicated package.
CONTENT_GAME0_DATA_FILES='
uk_sounds.naz'
CONTENT_DOC_DATA_FILES='
Total Overdose EULA French.doc
Total Overdose EULA German.docx
Total Overdose EULA Italian.docx
Total Overdose EULA Spanish.docx
Total Overdose - Manual.pdf'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/Documents/Total Overdose'

APP_MAIN_EXE='TOD.exe'
APP_MAIN_ICON_WRESTOOL_OPTIONS='--type=14 --name=101'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='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.

# Install shipped libraries.
wineprefix_init_custom() {
	cat <<- EOF
	# Install shipped libraries.
	ln --force --symbolic $(path_libraries)/* "\${PATH_PREFIX}"
	EOF
}

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
