#!/bin/sh
# SPDX-License-Identifier: ACSL
# SPDX-FileCopyrightText: © 2016 Antoine Le Gonidec <vv221@dotslashplay.it>
# SPDX-FileCopyrightText: © 2018 Mopi
# SPDX-FileCopyrightText: © 2020 Fabien Givors <captnfab@debian-facile.org>
set -o errexit

###
# Myst 3: Exile
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260104.1

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='myst-3-exile'
GAME_NAME='Myst III: Exile'

ARCHIVE_BASE_2_NAME='setup_myst_iii_exile_2.0.5_(64bit)_(83079).exe'
ARCHIVE_BASE_2_MD5='596d1683253f8c2111b20d23e8c320ed'
ARCHIVE_BASE_2_TYPE='innosetup'
ARCHIVE_BASE_2_PART1_NAME='setup_myst_iii_exile_2.0.5_(64bit)_(83079)-1.bin'
ARCHIVE_BASE_2_PART1_MD5='d0e247e34be60a4040653193a586b394'
ARCHIVE_BASE_2_SIZE='2946948'
ARCHIVE_BASE_2_VERSION='2.0.5-gog83079'
ARCHIVE_BASE_2_URL='https://www.gog.com/game/myst_3_exile'

ARCHIVE_BASE_1_NAME='setup_myst_iii_exile_2.0.3_(64bit)_(82361).exe'
ARCHIVE_BASE_1_MD5='fed3b0b13eee6fa6969c5235bdab122f'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_PART1_NAME='setup_myst_iii_exile_2.0.3_(64bit)_(82361)-1.bin'
ARCHIVE_BASE_1_PART1_MD5='d3c1bd80c58b50345fd9ab84e98374e5'
ARCHIVE_BASE_1_SIZE='2947141'
ARCHIVE_BASE_1_VERSION='2.0.3-gog82361'

ARCHIVE_BASE_0_NAME='setup_myst_3_exile_1.27_rvm_(21807).exe'
ARCHIVE_BASE_0_MD5='e2b8e962326b8802009d3e30b9e4c8ff'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_PART1_NAME='setup_myst_3_exile_1.27_rvm_(21807)-1.bin'
ARCHIVE_BASE_0_PART1_MD5='c69e2780274f2830ab210d230889e5bb'
ARCHIVE_BASE_0_SIZE='2422163'
ARCHIVE_BASE_0_VERSION='1.27-gog21807'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_MAIN_FILES='
data
m3data'
CONTENT_DOC_MAIN_FILES='
manual.pdf'
CONTENT_DOC_L10N_FILES='
manual.pdf
readme.txt'
CONTENT_DOC_L10N_EN_RELATIVE_PATH='myst iii english'
CONTENT_DOC_L10N_EN_FILES="$CONTENT_DOC_L10N_FILES"
CONTENT_DOC_L10N_FR_RELATIVE_PATH='myst iii french'
CONTENT_DOC_L10N_FR_FILES="$CONTENT_DOC_L10N_FILES"

APP_MAIN_SCUMMID='myst3:myst3'
APP_MAIN_ICON='myst iii english/m3.exe'
APP_MAIN_ICON_0='app/goggame-1766899243.ico'

# Load common functions.

## Scan library paths used by ./play.it ≥ 2.35.
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
## Scan library paths used by ./play.it < 2.35.
## This can go away when PLAYIT_COMPATIBILITY_LEVEL is bumped to 2.35 or higher.
if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${XDG_DATA_HOME:="${HOME}/.local/share"}/play.it" \
		'/usr/local/share/games/play.it' \
		'/usr/local/share/play.it' \
		'/usr/share/games/play.it' \
		'/usr/share/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit2.sh"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
## Error out if the library can not be found.
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit2.sh not found.\n'
	exit 1
fi
# shellcheck source=libplayit2.sh
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Include game data.

content_inclusion_icons
content_inclusion 'DOC_L10N_EN' 'PKG_MAIN' "$(path_documentation)/en"
content_inclusion 'DOC_L10N_FR' 'PKG_MAIN' "$(path_documentation)/fr"
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
