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

###
# Alan Wake's American Nightmare
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260417.5

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='alan-wakes-american-nightmare'
GAME_NAME='Alan Wake’s American Nightmare'

ARCHIVE_BASE_0_NAME='setup_alan_wake_american_nightmare_2.1.0.24.exe'
ARCHIVE_BASE_0_MD5='dc500730b639a48897c00f5791e5b2f3'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='2500000'
ARCHIVE_BASE_0_VERSION='1.0-gog2.1.0.24'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/alan_wakes_american_nightmare'

CONTENT_PATH_DEFAULT='app'
CONTENT_GAME_BIN_FILES='
alan_wakes_american_nightmare.exe'
# alan_wakes_american_nightmare.exe requirements
# TODO: Install libraries in a standard path.
CONTENT_GAME0_BIN_FILES='
binkw32.dll
ai_w32_f.dll
app_w32_f.dll
d3d_w32_f.dll
dm_w32_f.dll
loc_w32_f.dll
physics_w32_f.dll
renderer_w32_f.dll
rl_w32_f.dll
snd_w32_f.dll'
# snd_w32_f.dll requirements
CONTENT_GAME1_BIN_FILES='
fmodex.dll'
# TODO: Build dedicated localisation packages.
CONTENT_GAME2_BIN_FILES='
Language Setup.exe'
CONTENT_GAME_DATA_FILES='
data
shaders'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/Documents/Remedy/AmericanNightmare_GOG_Version'

APP_MAIN_EXE='alan_wakes_american_nightmare.exe'

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.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
