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

###
# Return of the Incredible Machine: Contraptions
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260420.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='the-incredible-machine-contraptions'
GAME_NAME='Return of the Incredible Machine: Contraptions'

ARCHIVE_BASE_0_NAME='setup_return_of_tim_contraptions_2.1.0.21.exe'
ARCHIVE_BASE_0_MD5='827015fe4244d09f5f5aee17db6f65cc'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='260000'
ARCHIVE_BASE_0_VERSION='1.0-gog2.1.0.21'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/the_incredible_machine_mega_pack'

CONTENT_PATH_DEFAULT='app'
CONTENT_GAME_BIN_FILES='
Contraptions.cnt
Contraptions.exe
Contraptions.hlp
CONTRAPTIONS.INI
SIGSPat.exe
setup.GID
setup.hlp
Sierra.inf
Saved Games'
# TODO: Install libraries in a standard path.
# TODO: Drop unused libraries.
CONTENT_GAME0_BIN_FILES='
refresh.dll
Roboex32.dll'
CONTENT_GAME_DATA_FILES='
sx_10??.mid
Interfaces.tbv
Intro.tbv
Levels.tbv
Music.tbv
Parts.tbv
Sounds.tbv
System.tbv
Voice.tbv'
CONTENT_DOC_DATA_FILES='
readme.txt'

USER_PERSISTENT_DIRECTORIES='
Homemade
Saved Games'

# Mouse inputs do not register unless the game is run in a virtual desktop.
# TODO: Check if this is still a problem with current WINE.
WINE_VIRTUAL_DESKTOP='auto'

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