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

###
# Stellaris expansions (extra content):
# - Arachnoid Portrait Pack
# - Horizon Signal
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260116.5

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='stellaris'
GAME_NAME='Stellaris'

EXPANSION_ID_ARACHNOID='arachnoid'
EXPANSION_NAME_ARACHNOID='Arachnoid Portrait Pack'

EXPANSION_ID_HORIZONSIGNAL='horizon-signal'
EXPANSION_NAME_HORIZONSIGNAL='Horizon Signal'

## Arachnoid Portrait Pack

ARCHIVE_BASE_ARACHNOID_4_NAME='stellaris_arachnoid_portrait_pack_4_2_4_87179.sh'
ARCHIVE_BASE_ARACHNOID_4_MD5='371dfa1f4a5c7609d24b6fdfbeb96cad'
ARCHIVE_BASE_ARACHNOID_4_SIZE='817'
ARCHIVE_BASE_ARACHNOID_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_ARACHNOID_4_URL='https://www.gog.com/game/stellaris_galaxy_edition_upgrade_pack'

ARCHIVE_BASE_ARACHNOID_3_NAME='stellaris_arachnoid_portrait_pack_4_1_7_86266.sh'
ARCHIVE_BASE_ARACHNOID_3_MD5='841c9caa537685374a25afffcda4a83d'
ARCHIVE_BASE_ARACHNOID_3_SIZE='817'
ARCHIVE_BASE_ARACHNOID_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_ARACHNOID_2_NAME='stellaris_arachnoid_portrait_pack_4_0_23_84679.sh'
ARCHIVE_BASE_ARACHNOID_2_MD5='6348fc2d97141925913bbada9ad78f9c'
ARCHIVE_BASE_ARACHNOID_2_SIZE='817'
ARCHIVE_BASE_ARACHNOID_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_ARACHNOID_1_NAME='stellaris_arachnoid_portrait_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_ARACHNOID_1_MD5='4168a3e72b2c19b0e7072e381b235314'
ARCHIVE_BASE_ARACHNOID_1_SIZE='817'
ARCHIVE_BASE_ARACHNOID_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_ARACHNOID_0_NAME='stellaris_arachnoid_portrait_pack_2_8_1_2_42827.sh'
ARCHIVE_BASE_ARACHNOID_0_MD5='6232966782f11eac72d8106dbde538c9'
ARCHIVE_BASE_ARACHNOID_0_SIZE='1400'
ARCHIVE_BASE_ARACHNOID_0_VERSION='2.8.1.2-gog42827'

## Horizon Signal

ARCHIVE_BASE_HORIZONSIGNAL_4_NAME='stellaris_horizon_signal_4_2_4_87179.sh'
ARCHIVE_BASE_HORIZONSIGNAL_4_MD5='81719f136a12a8c17af7c549d054cacc'
ARCHIVE_BASE_HORIZONSIGNAL_4_SIZE='817'
ARCHIVE_BASE_HORIZONSIGNAL_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_HORIZONSIGNAL_4_URL='https://www.gog.com/game/stellaris_horizon_signal'

ARCHIVE_BASE_HORIZONSIGNAL_3_NAME='stellaris_horizon_signal_4_1_7_86266.sh'
ARCHIVE_BASE_HORIZONSIGNAL_3_MD5='d2411d879d8faa982c985b9f5bbc0681'
ARCHIVE_BASE_HORIZONSIGNAL_3_SIZE='817'
ARCHIVE_BASE_HORIZONSIGNAL_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_HORIZONSIGNAL_2_NAME='stellaris_horizon_signal_4_0_23_84679.sh'
ARCHIVE_BASE_HORIZONSIGNAL_2_MD5='d83044063bc16d23c32fee95ecbaa5f0'
ARCHIVE_BASE_HORIZONSIGNAL_2_SIZE='817'
ARCHIVE_BASE_HORIZONSIGNAL_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_HORIZONSIGNAL_1_NAME='stellaris_horizon_signal_3_14_1592653_81105.sh'
ARCHIVE_BASE_HORIZONSIGNAL_1_MD5='b5f000f1f6ab8e30cb90ffffcbb07716'
ARCHIVE_BASE_HORIZONSIGNAL_1_SIZE='817'
ARCHIVE_BASE_HORIZONSIGNAL_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_HORIZONSIGNAL_0_NAME='stellaris_horizon_signal_2_8_1_2_42827.sh'
ARCHIVE_BASE_HORIZONSIGNAL_0_MD5='0e9f53918e8b489add020cf91b4492e8'
ARCHIVE_BASE_HORIZONSIGNAL_0_SIZE='1400'
ARCHIVE_BASE_HORIZONSIGNAL_0_VERSION='2.8.1.2-gog42827'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_MAIN_FILES='
dlc'

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
