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

###
# The Witness
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260421.6

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='the-witness'
GAME_NAME='The Witness'

ARCHIVE_BASE_0_NAME='setup_the_witness_21-12-2017_(19091).exe'
ARCHIVE_BASE_0_MD5='5bfb0d687fb80cdd64cdee7b6b567400'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_PART1_NAME='setup_the_witness_21-12-2017_(19091)-1.bin'
ARCHIVE_BASE_0_PART1_MD5='90a24fed5d8e2e52ab1bf2de84349984'
ARCHIVE_BASE_0_SIZE='4300000'
ARCHIVE_BASE_0_VERSION='2017.12.21-gog19091'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/the_witness'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_BIN_FILES='
witness64_d3d11.exe'
# TODO: Drop unused libraries.
# TODO: Install libraries in a standard path.
CONTENT_GAME0_BIN_FILES='
amd_ags_x64.dll
AnselSDK64.dll
bink2w64.dll
openvr_api.dll'
# TODO: Check if the Steam library is required.
CONTENT_GAME1_BIN_FILES='
steam_api64.dll'
CONTENT_GAME_DATA_FILES='
data
data-pc
controller.vdf
data-pc.zip'
CONTENT_GAME0_DATA_PATH='__support/app'
CONTENT_GAME0_DATA_FILES='
language.ini'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/AppData/Roaming/The Witness'

USER_PERSISTENT_FILES='
language.ini'

APP_MAIN_EXE='witness64_d3d11.exe'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
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.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
