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

###
# Ixion
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260414.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='ixion'
GAME_NAME='Ixion'

# The following build include an annoying, unfixed bug:
# « 1.0.7.0 introduced a bug that stopped transporters from using the streets. »
# — https://www.gog.com/forum/ixion/patch_version
# It is recommended to use the 1.0.6.5 game version instead.
ARCHIVE_BASE_1_NAME='setup_ixion_1.0.7.0_(64bit)_(74527).exe'
ARCHIVE_BASE_1_MD5='2456531ce9701d9e8832d6db58dcad33'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_PART1_NAME='setup_ixion_1.0.7.0_(64bit)_(74527)-1.bin'
ARCHIVE_BASE_1_PART1_MD5='2d2044d041d97b98fad03f8aa69269ea'
ARCHIVE_BASE_1_PART2_NAME='setup_ixion_1.0.7.0_(64bit)_(74527)-2.bin'
ARCHIVE_BASE_1_PART2_MD5='85b1e766eef8cbf991e1fa59da818ab9'
ARCHIVE_BASE_1_SIZE='12481652'
ARCHIVE_BASE_1_VERSION='1.0.7.0-gog74527'
ARCHIVE_BASE_1_URL='https://www.gog.com/game/ixion'

ARCHIVE_BASE_0_NAME='setup_ixion_1.0.6.5_(64bit)_(69670).exe'
ARCHIVE_BASE_0_MD5='753b96e6b35d4adea73ca842f2e8f0e7'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_PART1_NAME='setup_ixion_1.0.6.5_(64bit)_(69670)-1.bin'
ARCHIVE_BASE_0_PART1_MD5='54d9f45d4ed211a14aea70797d1400c1'
ARCHIVE_BASE_0_PART2_NAME='setup_ixion_1.0.6.5_(64bit)_(69670)-2.bin'
ARCHIVE_BASE_0_PART2_MD5='c4b119088ea2190b1d99e5efd38bd7ac'
ARCHIVE_BASE_0_SIZE='12480607'
ARCHIVE_BASE_0_VERSION='1.0.6.5-gog69670'

UNITY3D_NAME='Ixion'
# TODO: Include an explicit list of Unity3D plugins.

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_DATA_SHAREDASSETS1_FILES="
${UNITY3D_NAME}_Data/sharedassets?.*"
CONTENT_GAME_DATA_SHAREDASSETS2_FILES="
${UNITY3D_NAME}_Data/sharedassets??.*"

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/AppData/LocalLow/BulwarkStudios/Ixion'

PACKAGES_LIST='
PKG_BIN
PKG_DATA_SHAREDASSETS1
PKG_DATA_SHAREDASSETS2
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN_DEPENDENCIES_GSTREAMER_PLUGINS='
video/quicktime, variant=(string)iso'

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

PKG_DATA_SHAREDASSETS_ID="${PKG_DATA_ID}-sharedassets"
PKG_DATA_SHAREDASSETS1_ID="${PKG_DATA_SHAREDASSETS_ID}-1"
PKG_DATA_SHAREDASSETS2_ID="${PKG_DATA_SHAREDASSETS_ID}-2"
PKG_DATA_SHAREDASSETS_DESCRIPTION="$PKG_DATA_DESCRIPTION - shared assets"
PKG_DATA_SHAREDASSETS1_DESCRIPTION="$PKG_DATA_SHAREDASSETS_DESCRIPTION - 1"
PKG_DATA_SHAREDASSETS2_DESCRIPTION="$PKG_DATA_SHAREDASSETS_DESCRIPTION - 2"

# 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
