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

###
# Hidden Through Time series:
# - Hidden Through Time
# - Hidden Through Time 2
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260422.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID_EPISODE1='hidden-through-time-1'
GAME_ID_EPISODE2='hidden-through-time-2'

GAME_NAME_EPISODE1='Hidden Through Time'
GAME_NAME_EPISODE2='Hidden Through Time 2: Myths & Magic'

ARCHIVE_BASE_EPISODE1_1_NAME='setup_hidden_through_time_1.0.9b_(56935).exe'
ARCHIVE_BASE_EPISODE1_1_MD5='fafb6b639f687a13c2c6c293550a0ec6'
ARCHIVE_BASE_EPISODE1_1_TYPE='innosetup'
ARCHIVE_BASE_EPISODE1_1_SIZE='632768'
ARCHIVE_BASE_EPISODE1_1_VERSION='1.0.9b-gog56935'
ARCHIVE_BASE_EPISODE1_1_URL='https://www.gog.com/game/hidden_through_time'

ARCHIVE_BASE_EPISODE1_0_NAME='setup_hidden_through_time_1.0.7_(46929).exe'
ARCHIVE_BASE_EPISODE1_0_MD5='f64269fa2f3627fe5ad74cae5ff11869'
ARCHIVE_BASE_EPISODE1_0_TYPE='innosetup'
ARCHIVE_BASE_EPISODE1_0_SIZE='520000'
ARCHIVE_BASE_EPISODE1_0_VERSION='1.0.7-gog46929'

ARCHIVE_BASE_EPISODE2_0_NAME='setup_hidden_through_time_2_myths__magic_1.0.30a_(64bit)_(68025).exe'
ARCHIVE_BASE_EPISODE2_0_MD5='20b5488ad9f819ea3e008f8df2a28ab1'
ARCHIVE_BASE_EPISODE2_0_TYPE='innosetup'
ARCHIVE_BASE_EPISODE2_0_SIZE='682606'
ARCHIVE_BASE_EPISODE2_0_VERSION='1.0.30a-gog68025'
ARCHIVE_BASE_EPISODE2_0_URL='https://www.gog.com/game/hidden_through_time_2_myths_magic'

UNITY3D_NAME_EPISODE1='Hidden'
UNITY3D_NAME_EPISODE2='HTT2'
# TODO: Include an explicit list of Unity3D plugins.

CONTENT_PATH_DEFAULT='.'

USER_PERSISTENT_DIRECTORIES_EPISODE2="
${UNITY3D_NAME_EPISODE2}_Data/Saves"

WINE_PERSISTENT_DIRECTORIES_EPISODE1='
users/${USER}/AppData/LocalLow/Crazy Monkey Studios/Hidden Through Time'
WINE_PERSISTENT_DIRECTORIES_EPISODE2='
users/${USER}/AppData/LocalLow/Rogueside/HTT2'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
# Easier upgrades from pre-20240220.1 packages
PKG_BIN_PROVIDES_EPISODE1='
hidden-through-time'

PKG_DATA_ID_EPISODE1="${GAME_ID_EPISODE1}-data"
PKG_DATA_ID_EPISODE2="${GAME_ID_EPISODE2}-data"
PKG_DATA_DESCRIPTION='data'
# Easier upgrades from pre-20240220.1 packages
PKG_DATA_PROVIDES_EPISODE1='
hidden-through-time-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
