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

###
# Tyranny
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260310.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='tyranny'
GAME_NAME='Tyranny'

ARCHIVE_BASE_0_NAME='tyranny_v1_2_1_160_v2_25169.sh'
ARCHIVE_BASE_0_MD5='72bdb7c9f6966ac6f1ccfbbad9fb29e6'
ARCHIVE_BASE_0_SIZE='15136872'
ARCHIVE_BASE_0_VERSION='1.2.1.0160-gog25169'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/tyranny_commander_edition'

ARCHIVE_BASE_1_NAME='tyranny_en_1_2_1_0158_15398.sh'
ARCHIVE_BASE_1_MD5='664cba00a861611fb155f65b8d83d9e9'
ARCHIVE_BASE_1_SIZE='15000000'
ARCHIVE_BASE_1_VERSION='1.2.1.0158-gog15398'

UNITY3D_NAME='Tyranny'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_DATA_AREAS_FILES="
${UNITY3D_NAME}_Data/bundles/st_ar_*"

PACKAGES_LIST='
PKG_BIN64
PKG_DATA_AREAS
PKG_DATA'

PKG_BIN64_ARCH='64'
PKG_BIN64_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN64_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libgcc_s.so.1
libGL.so.1
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6
libX11.so.6
libXcursor.so.1
libXrandr.so.2'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'
PKG_DATA_DEPENDENCIES_SIBLINGS='
PKG_DATA_AREAS'

PKG_DATA_AREAS_ID="${PKG_DATA_ID}-areas"
PKG_DATA_AREAS_DESCRIPTION="${PKG_DATA_DESCRIPTION} - areas"
# Easier upgrades from pre-20260107.1 packages
PKG_DATA_AREAS_PROVIDES="${PKG_DATA_AREAS_PROVIDES:-}
tyranny-areas"

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

# Prevent inclusion of 32-bit libraries.

rm --recursive "$(path_archive_contents)/$(unity3d_name)_Data/Mono/x86"

# Prevent inclusion of unused Unity3D plugins.

rm --recursive "$(path_archive_contents)/$(unity3d_name)_Data/Plugins"

# 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
