#!/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 (Masterpiece Edition)
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260104.3

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='myst-1'
GAME_NAME='Myst'

ARCHIVE_BASE_4_NAME='setup_myst_masterpiece_edition_2.0.5_(64bit)_(83079).exe'
ARCHIVE_BASE_4_MD5='3da8caf76c12e66fac4cedd945127c2e'
ARCHIVE_BASE_4_TYPE='innosetup'
ARCHIVE_BASE_4_SIZE='1885140'
ARCHIVE_BASE_4_VERSION='2.0.5-gog83079'
ARCHIVE_BASE_4_URL='https://www.gog.com/game/myst_masterpiece_edition'

ARCHIVE_BASE_3_NAME='setup_myst_masterpiece_edition_2.0.3_(64bit)_(82361).exe'
ARCHIVE_BASE_3_MD5='1c72d6dd734478aba521c8764449c94e'
ARCHIVE_BASE_3_TYPE='innosetup'
ARCHIVE_BASE_3_SIZE='1885314'
ARCHIVE_BASE_3_VERSION='2.0.3-gog82361'

ARCHIVE_BASE_2_NAME='setup_myst_masterpiece_edition_1.0_svm_update_4_(22597).exe'
ARCHIVE_BASE_2_MD5='cee43afef96ec781a18c578a1cc8bdcc'
ARCHIVE_BASE_2_TYPE='innosetup'
ARCHIVE_BASE_2_PART1_NAME='setup_myst_masterpiece_edition_1.0_svm_update_4_(22597)-1.bin'
ARCHIVE_BASE_2_PART1_MD5='1417de6ceaaaac67064529c3afab6792'
ARCHIVE_BASE_2_SIZE='1409531'
ARCHIVE_BASE_2_VERSION='1.0.4-gog22597'

ARCHIVE_BASE_1_NAME='setup_myst_masterpiece_edition_1.0_svm_update_4_(22598).exe'
ARCHIVE_BASE_1_MD5='e3c62eeb19abd2c9a947aee8300e995d'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_PART1_NAME='setup_myst_masterpiece_edition_1.0_svm_update_4_(22598)-1.bin'
ARCHIVE_BASE_1_PART1_MD5='4b84a68ec57e55bcc9b522c6333c669c'
ARCHIVE_BASE_1_SIZE='1500000'
ARCHIVE_BASE_1_VERSION='1.0.4-gog22598'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_L10N_FILES='
qtw/channel/holoalgh.mov
qtw/channel/holoamth.mov
qtw/channel/holoasir.mov
qtw/channel/holosmsg.mov
qtw/channel/monalgh.mov
qtw/channel/monamth.mov
qtw/channel/monasirs.mov
qtw/channel/monsmsg.mov
qtw/dunny/atr1nopg.mov
qtw/dunny/atr1page.mov
qtw/dunny/atrmidc2.mov
qtw/dunny/atrus2.mov
qtw/intro/broder.mov
qtw/intro/intro.mov
qtw/mech/holoon.mov
qtw/myst/aextra.mov
qtw/myst/alose.mov
qtw/myst/apage1.mov
qtw/myst/apage2.mov
qtw/myst/apage3.mov
qtw/myst/apage4.mov
qtw/myst/apage5.mov
qtw/myst/atrusbk1.mov
qtw/myst/atrusbk2.mov
qtw/myst/sextra.mov
qtw/myst/slose.mov
qtw/myst/spage1.mov
qtw/myst/spage2.mov
qtw/myst/spage3.mov
qtw/myst/spage4.mov
qtw/myst/spage5.mov
qtw/myst/vltatrus.mov'
CONTENT_GAME_L10N_FR_PATH='french'
CONTENT_GAME_L10N_FR_FILES="$CONTENT_GAME_L10N_FILES"
CONTENT_GAME_L10N_EN_FILES="$CONTENT_GAME_L10N_FILES"
CONTENT_GAME0_L10N_FR_FILES='
channel_french.dat
credits_french.dat
help_french.dat
mechan_french.dat
myst_french.dat
selen_french.dat
stone_french.dat'
CONTENT_GAME_MAIN_FILES='
channel.dat
credits.dat
dunny.dat
help.dat
intro.dat
mechan.dat
menu.dat
myst.dat
selen.dat
stone.dat
qtw'
CONTENT_DOC_MAIN_FILES='
manual.pdf
readme.txt'

APP_MAIN_SCUMMID='mohawk:myst'
APP_MAIN_ICON='app/goggame-1207658818.ico'

PACKAGES_LIST='
PKG_L10N_FR
PKG_L10N_EN
PKG_MAIN'

PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_L10N'
## Easier upgrades from pre-20260104.3 packages
PKG_MAIN_PROVIDES="${PKG_MAIN_PROVIDES:-}
myst-1-common"

PKG_L10N_ID="${GAME_ID}-l10n"
PKG_L10N_FR_ID="${PKG_L10N_ID}-fr"
PKG_L10N_EN_ID="${PKG_L10N_ID}-en"
PKG_L10N_PROVIDES="
$PKG_L10N_ID"
PKG_L10N_FR_DESCRIPTION='French localisation'
PKG_L10N_EN_DESCRIPTION='English localisation'
## Easier upgrades from pre-20260104.3 packages
PKG_L10N_PROVIDES="${PKG_L10N_PROVIDES:-}
myst-1-fr
myst-1-en"

# 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 "$@"
set_default_package 'PKG_MAIN'

# Extract game data.

archive_extraction_default

# Include game data.

content_inclusion_icons
content_inclusion_default

# Write launchers.

## Set game language.
game_exec_line() {
	cat <<- 'EOF'
	# Set game language
	if [ -e "${PATH_GAME_DATA}/myst_french.dat" ]; then
	    language=fr
	else
	    language=en
	fi
	scummvm --language="$language" --path="$PATH_GAME_DATA" "$@" mohawk:myst
	EOF
}

launchers_generation

# Build packages.

packages_generation
case "$(messages_language)" in
	('fr')
		lang_string='version %s :'
		lang_fr='française'
		lang_en='anglaise'
	;;
	('en'|*)
		lang_string='%s version:'
		lang_fr='French'
		lang_en='English'
	;;
esac
printf '\n'
printf "$lang_string" "$lang_fr"
print_instructions 'PKG_MAIN' 'PKG_L10N_FR'
printf "$lang_string" "$lang_en"
print_instructions 'PKG_MAIN' 'PKG_L10N_EN'

# Clean up.

working_directory_cleanup

exit 0
