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

###
# Shadow Gambit expansions:
# - Yuki's Wish
# - Zagan's Ritual
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260128.1

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='shadow-gambit'
GAME_NAME='Shadow Gambit: The Cursed Crew'

EXPANSION_ID_YUKI='yukis-wish'
EXPANSION_NAME_YUKI='Yuki’s Wish'

EXPANSION_ID_ZAGAN='zagans-ritual'
EXPANSION_NAME_ZAGAN='Zagan’s Ritual'

# Yuki's Wish

ARCHIVE_BASE_YUKI_2_NAME='setup_shadow_gambit_yukis_wish_1.2.133.f.r40893v3_(87352).exe'
ARCHIVE_BASE_YUKI_2_MD5='24d6e120b615ed64daa7eb6d0dc74c9f'
ARCHIVE_BASE_YUKI_2_TYPE='innosetup'
ARCHIVE_BASE_YUKI_2_SIZE='7491'
ARCHIVE_BASE_YUKI_2_VERSION='1.2.133.f.r40893v3-gog87352'
ARCHIVE_BASE_YUKI_2_URL='https://www.gog.com/game/shadow_gambit_yukis_wish'

ARCHIVE_BASE_YUKI_1_NAME='setup_shadow_gambit_yukis_wish_1.2.133.f.r40893v2_(86438).exe'
ARCHIVE_BASE_YUKI_1_MD5='0b507bc3dccb5788a991440c396fb178'
ARCHIVE_BASE_YUKI_1_TYPE='innosetup'
ARCHIVE_BASE_YUKI_1_SIZE='6524'
ARCHIVE_BASE_YUKI_1_VERSION='1.2.133.f.r40893v2-gog86438'

ARCHIVE_BASE_YUKI_0_NAME='setup_shadow_gambit_the_cursed_crew__dlctrp_1.2.133.f.r40893_(64bit)_(69829).exe'
ARCHIVE_BASE_YUKI_0_MD5='da9c4f3c92dc2eec996592f3e96acf33'
ARCHIVE_BASE_YUKI_0_TYPE='innosetup'
ARCHIVE_BASE_YUKI_0_SIZE='7198'
ARCHIVE_BASE_YUKI_0_VERSION='1.2.133.f.r40893-gog69829'

# Zagan's Ritual

ARCHIVE_BASE_ZAGAN_2_NAME='setup_shadow_gambit_zagans_ritual_1.2.133.f.r40893v3_(87352).exe'
ARCHIVE_BASE_ZAGAN_2_MD5='cf0611749e8f3a9a49d7fe4eb9bc3bc8'
ARCHIVE_BASE_ZAGAN_2_TYPE='innosetup'
ARCHIVE_BASE_ZAGAN_2_SIZE='6785'
ARCHIVE_BASE_ZAGAN_2_VERSION='1.2.133.f.r40893v3-gog87352'
ARCHIVE_BASE_ZAGAN_2_URL='https://www.gog.com/game/shadow_gambit_zagans_ritual'

ARCHIVE_BASE_ZAGAN_1_NAME='setup_shadow_gambit_zagans_ritual_1.2.133.f.r40893v2_(86438).exe'
ARCHIVE_BASE_ZAGAN_1_MD5='694c9b1f2cfa444ed8b93994312d7b18'
ARCHIVE_BASE_ZAGAN_1_TYPE='innosetup'
ARCHIVE_BASE_ZAGAN_1_SIZE='7608'
ARCHIVE_BASE_ZAGAN_1_VERSION='1.2.133.f.r40893v2-gog86438'

ARCHIVE_BASE_ZAGAN_0_NAME='setup_shadow_gambit_the_cursed_crew__dlcchc_1.2.133.f.r40893_(64bit)_(69829).exe'
ARCHIVE_BASE_ZAGAN_0_MD5='a715770254fe1f451c616503c19ecb2e'
ARCHIVE_BASE_ZAGAN_0_TYPE='innosetup'
ARCHIVE_BASE_ZAGAN_0_SIZE='7058'
ARCHIVE_BASE_ZAGAN_0_VERSION='1.2.133.f.r40893-gog69829'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_MAIN_FILES='
goggame-*.info'

PKG_PARENT_ID="$GAME_ID"

PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_PARENT'

# 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_default

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
