#!/bin/sh
# SPDX-License-Identifier: BSD-2-Clause
# SPDX-FileCopyrightText: © 2019 Jacek Szafarkiewicz
# SPDX-FileCopyrightText: © 2023 Antoine Le Gonidec <vv221@dotslashplay.it>
set -o errexit

###
# Commandos 3: Destination Berlin
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260404.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='commandos-3'
GAME_NAME='Commandos 3: Destination Berlin'

ARCHIVE_BASE_0_NAME='setup_commandos_3_-_destination_berlin_1.42_hotfix2_(25143).exe'
ARCHIVE_BASE_0_MD5='2fa1ad6e7c7e918bdaa1adee5bb3a0ec'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='2100000'
ARCHIVE_BASE_0_VERSION='1.42-gog25143'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/commandos_2_3'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_BIN_FILES='
Commandos3.exe'
# TODO: Install libraries in a standard path.
# TODO: Drop unused libraries.
CONTENT_GAME0_BIN_FILES='
binkw32.dll
d3d8.dll
ogg.dll
vorbis.dll'
CONTENT_GAME_DATA_FILES='
Data
Output
DATA.PCK
Data2.PCK
Data3.pck'
# TODO: Check if DirectPlay script is required.
CONTENT_GAME0_DATA_FILES='
directplay.cmd'
CONTENT_DOC_DATA_FILES='
Readme.rtf
support.txt
manual.pdf'

USER_PERSISTENT_DIRECTORIES='
Output'

# Without a virtual desktop mouse inputs trigger a sound feedback
# but no actual action, preventing to even start a game.
# (WINE 11.5)
WINE_VIRTUAL_DESKTOP='800x600'

APP_MAIN_EXE='Commandos3.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
