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

###
# Pillars of Eternity 2 expansions:
# - Critical Role Pack
# - Rum Runner’s Pack
# - Beard and Hair Pack
# - Scalawags Pack
# - Deck of Many Things
# - Beast of Winter
# - Seeker, Slayer, Survivor
# - The Forgotten Sanctum
###

script_version=20260710.1

PLAYIT_COMPATIBILITY_LEVEL=2.35

GAME_ID=pillars-of-eternity-2
GAME_NAME='Pillars of Eternity II'

EXPANSION_ID_CRITICAL=critical-role
EXPANSION_NAME_CRITCAL='Critical Role Pack'

EXPANSION_ID_RUM=rum-runner
EXPANSION_NAME_RUM='Rum Runner’s Pack'

EXPANSION_ID_BEARD=beard-and-hair
EXPANSION_NAME_BEARD='Beard and Hair Pack'

EXPANSION_ID_SCALAWAGS=scalawags
EXPANSION_NAME_SCALAWAGS='Scalawags Pack'

EXPANSION_ID_DECK=deck-of-many-things
EXPANSION_NAME_DECK='Deck of Many Things'

EXPANSION_ID_BEAST=beast-of-winter
EXPANSION_NAME_BEAST='Beast of Winter'

EXPANSION_ID_SEEKER=seeker-slayer-survivor
EXPANSION_NAME_SEEKER='Seeker, Slayer, Survivor'

EXPANSION_ID_SANCTUM=forgotten-sanctum
EXPANSION_NAME_SANCTUM='The Forgotten Sanctum'

ARCHIVE_BASE_CRITICAL_0_NAME='pillars_of_eternity_ii_deadfire_critical_role_pack_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_CRITICAL_0_MD5=60eccceeb79069065ef4ea9f8661e121
ARCHIVE_BASE_CRITICAL_0_SIZE=3100
ARCHIVE_BASE_CRITICAL_0_VERSION=5.0.0.0040-1

ARCHIVE_BASE_RUM_0_NAME='pillars_of_eternity_ii_deadfire_rum_runner_s_pack_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_RUM_0_MD5=d146cb0f2cdc955f498d1be420b83083
ARCHIVE_BASE_RUM_0_SIZE=3100
ARCHIVE_BASE_RUM_0_VERSION=5.0.0.0040-1

ARCHIVE_BASE_BEARD_0_NAME='pillars_of_eternity_ii_deadfire_beard_and_hair_pack_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_BEARD_0_MD5=bbebde9f100d134e73f8534de38bee28
ARCHIVE_BASE_BEARD_0_SIZE=3100
ARCHIVE_BASE_BEARD_0_VERSION=5.0.0.0040-1

ARCHIVE_BASE_SCALAWAGS_0_NAME='pillars_of_eternity_ii_deadfire_scalawag_pack_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_SCALAWAGS_0_MD5=23b12e22bc0b2bb7073507f0e934fcad
ARCHIVE_BASE_SCALAWAGS_0_SIZE=3100
ARCHIVE_BASE_SCALAWAGS_0_VERSION=5.0.0.0040-1

ARCHIVE_BASE_DECK_0_NAME='pillars_of_eternity_ii_deadfire_deck_of_many_things_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_DECK_0_MD5=0ba169b68f0a7a1ad43a7c33b3bea97b
ARCHIVE_BASE_DECK_0_SIZE=3100
ARCHIVE_BASE_DECK_0_VERSION=5.0.0.0040-1

ARCHIVE_BASE_BEAST_0_NAME='pillars_of_eternity_ii_deadfire_beast_of_winter_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_BEAST_0_MD5=c40ae5e71de2340551883ae15eac82a7
ARCHIVE_BASE_BEAST_0_SIZE=4000000
ARCHIVE_BASE_BEAST_0_VERSION=5.0.0.0040-1

ARCHIVE_BASE_SEEKER_0_NAME='pillars_of_eternity_ii_deadfire_seeker_slayer_survivor_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_SEEKER_0_MD5=48a514d554cdd2435d1db55b3546705b
ARCHIVE_BASE_SEEKER_0_SIZE=2000000
ARCHIVE_BASE_SEEKER_0_VERSION=5.0.0.0040-1

ARCHIVE_BASE_SANCTUM_0_NAME='pillars_of_eternity_ii_deadfire_the_forgotten_sanctum_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_SANCTUM_0_MD5=4c83e476fe74c157c72b9b4f85df917d
ARCHIVE_BASE_SANCTUM_0_SIZE=2623204
ARCHIVE_BASE_SANCTUM_0_VERSION=5.0.0.0040-1

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

PKG_PARENT_ID=$GAME_ID
PKG_MAIN_DEPENDENCIES_SIBLINGS=PKG_PARENT

# 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
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract archive contents.

archive_extraction_default

# Include game data.

content_inclusion_default

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
