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

###
# Tyranny expansions:
# - Coat of Arms
# - Portrait Pack
# - Tales from the Tiers
# - Bastard's Wound
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260108.1

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='tyranny'
GAME_NAME='Tyranny'

EXPANSION_ID_COATOFARMS='coat-of-arms'
EXPANSION_NAME_COATOFARMS='Coat of Arms'

EXPANSION_ID_PORTRAIT='portrait-pack'
EXPANSION_NAME_PORTRAIT='Portrait Pack'

EXPANSION_ID_TALES='tales-from-the-tiers'
EXPANSION_NAME_TALES='Tales from the Tiers'

EXPANSION_ID_WOUND='bastards-wound'
EXPANSION_NAME_WOUND='Bastardʼs Wound'

## Coat of Arms

ARCHIVE_BASE_COATOFARMS_0_NAME='tyranny_coat_of_arms_dlc_en_1_0_14773.sh'
ARCHIVE_BASE_COATOFARMS_0_MD5='ba1403ce1f2535a00ae137c19204459f'
ARCHIVE_BASE_COATOFARMS_0_SIZE='1342'
ARCHIVE_BASE_COATOFARMS_0_VERSION='1.0-gog14773'
ARCHIVE_BASE_COATOFARMS_0_URL='https://www.gog.com/game/tyranny_overlord_edition_upgrade'

## Portrait Pack

ARCHIVE_BASE_PORTRAIT_0_NAME='tyranny_portrait_pack_dlc_en_1_0_14773.sh'
ARCHIVE_BASE_PORTRAIT_0_MD5='165e1cf02119a0b2ddb4d8bfa8b6819d'
ARCHIVE_BASE_PORTRAIT_0_SIZE='4150'
ARCHIVE_BASE_PORTRAIT_0_VERSION='1.0-gog14773'
ARCHIVE_BASE_PORTRAIT_0_URL='https://www.gog.com/game/tyranny_portrait_pack'

## Tales from the Tiers

ARCHIVE_BASE_TALES_0_NAME='tyranny_tales_from_the_tiers_dlc_en_1_2_1_0158_15398.sh'
ARCHIVE_BASE_TALES_0_MD5='08676e535375b162e2fa32b1bc4488a3'
ARCHIVE_BASE_TALES_0_SIZE='4386'
ARCHIVE_BASE_TALES_0_VERSION='1.2.1.0158-gog15398'
ARCHIVE_BASE_TALES_0_URL='https://www.gog.com/game/tyranny_tales_from_the_tiers'

## Bastard's Wound

ARCHIVE_BASE_WOUND_0_NAME='tyranny_bastard_s_wound_dlc_en_1_2_1_0158_15398.sh'
ARCHIVE_BASE_WOUND_0_MD5='dbd2b51a410db2357b2e144f44139c19'
ARCHIVE_BASE_WOUND_0_SIZE='1159755'
ARCHIVE_BASE_WOUND_0_VERSION='1.2.1.0158-gog15398'
ARCHIVE_BASE_WOUND_0_URL='https://www.gog.com/game/tyranny_bastards_wound'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_MAIN_FILES='
Tyranny_Data'
## Bastard's Wound - Prevent inclusion of duplicated files already provided by the base game.
CONTENT_GAME_MAIN_FILES_WOUND='
Tyranny_Data/data_vx1
Tyranny_Data/bundles/dlc01.unity3d'

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
