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

###
# Pillars of Eternity 2 expansions:
# - forgotten sanctum
# - beast of winter
# - seeker slayer survivor
# - rum runners-pack
# - deck of many things
# - critical role
# - scalawags pack
# - beard and hair pack
###

script_version=20241201.1

PLAYIT_COMPATIBILITY_LEVEL='2.31'

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

EXPANSION_ID_FORGOTTEN_SANCTUM='forgotten-sanctum'
EXPANSION_NAME_FORGOTTEN_SANCTUM='forgotten sanctum'

EXPANSION_ID_BEAST_OF_WINTER='beast-of-winter'
EXPANSION_NAME_BEAST_OF_WINTER='beast of winter'

EXPANSION_ID_SEEKER_SLAYER_SURVIVOR='seeker-slayer-survivor'
EXPANSION_NAME_SEEKER_SLAYER_SURVIVOR='seeker slayer survivor'

EXPANSION_ID_RUM_RUNNERS_PACK='rum-runners-pack'
EXPANSION_NAME_RUM_RUNNERS_PACK='rum runners-pack'

EXPANSION_ID_DECK_OF_MANY_THINGS='deck-of-many-things'
EXPANSION_NAME_DECK_OF_MANY_THINGS='deck of many things'

EXPANSION_ID_CRITICAL_ROLE='critical-role'
EXPANSION_NAME_CRITCAL_ROLE='critical role'

EXPANSION_ID_SCALAWAGS_PACK='scalawags-pack'
EXPANSION_NAME_SCALAWAGS_PACK='scalawags pack'

EXPANSION_ID_BEARD_AND_HAIR_PACK='beard-and-hair-pack'
EXPANSION_NAME_BEARD_AND_HAIR_PACK='beard and hair pack'

# Archives

## Kickstarter item

ARCHIVE_BASE_FORGOTTEN_SANCTUM_0_NAME='pillars_of_eternity_ii_deadfire_the_forgotten_sanctum_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_FORGOTTEN_SANCTUM_0_MD5='4c83e476fe74c157c72b9b4f85df917d'
ARCHIVE_BASE_FORGOTTEN_SANCTUM_0_SIZE='2623204'
ARCHIVE_BASE_FORGOTTEN_SANCTUM_0_VERSION='1.0-gog29222'
ARCHIVE_BASE_FORGOTTEN_SANCTUM_0_URL='https://www.gog.com/de/game/pillars_of_eternity_ii_deadfire_the_forgotten_sanctum'

ARCHIVE_BASE_BEAST_OF_WINTER_0_NAME='pillars_of_eternity_ii_deadfire_beast_of_winter_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_BEAST_OF_WINTER_0_MD5='c40ae5e71de2340551883ae15eac82a7'
ARCHIVE_BASE_BEAST_OF_WINTER_0_SIZE='4000000'
ARCHIVE_BASE_BEAST_OF_WINTER_0_VERSION='1.0-gog29222'
ARCHIVE_BASE_BEAST_OF_WINTER_0_URL='https://www.gog.com/de/game/pillars_of_eternity_ii_deadfire_the_beast_of_winter'

ARCHIVE_BASE_SEEKER_SLAYER_SURVIVOR_0_NAME='pillars_of_eternity_ii_deadfire_seeker_slayer_survivor_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_SEEKER_SLAYER_SURVIVOR_0_MD5='48a514d554cdd2435d1db55b3546705b'
ARCHIVE_BASE_SEEKER_SLAYER_SURVIVOR_0_SIZE='2000000'
ARCHIVE_BASE_SEEKER_SLAYER_SURVIVOR_0_VERSION='1.0-gog29222'
ARCHIVE_BASE_SEEKER_SLAYER_SURVIVOR_0_URL='https://www.gog.com/de/game/pillars_of_eternity_ii_deadfire_seeker_slayer_survivor'

ARCHIVE_BASE_DECK_OF_MANY_THINGS_0_NAME='pillars_of_eternity_ii_deadfire_deck_of_many_things_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_DECK_OF_MANY_THINGS_0_MD5='0ba169b68f0a7a1ad43a7c33b3bea97b'
ARCHIVE_BASE_DECK_OF_MANY_THINGS_0_SIZE='3100'
ARCHIVE_BASE_DECK_OF_MANY_THINGS_0_VERSION='1.0-gog29222'
ARCHIVE_BASE_DECK_OF_MANY_THINGS_0_URL='https://www.gog.com/de/game/pillars_of_eternity_ii_deadfire_deck_of_many_things'

ARCHIVE_BASE_CRITICAL_ROLE_PACK_0_NAME='pillars_of_eternity_ii_deadfire_critical_role_pack_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_CRITICAL_ROLE_PACK_0_MD5='60eccceeb79069065ef4ea9f8661e121'
ARCHIVE_BASE_CRITICAL_ROLE_PACK_0_SIZE='3100'
ARCHIVE_BASE_CRITICAL_ROLE_PACK_0_VERSION='1.0-gog29222'
ARCHIVE_BASE_CRITICAL_ROLE_PACK_0_URL='https://www.gog.com/de/game/pillars_of_eternity_ii_deadfire_critical_role_pack'

ARCHIVE_BASE_SCALAWAGS_PACK_0_NAME='pillars_of_eternity_ii_deadfire_scalawag_pack_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_SCALAWAGS_PACK_0_MD5='23b12e22bc0b2bb7073507f0e934fcad'
ARCHIVE_BASE_SCALAWAGS_PACK_0_SIZE='3100'
ARCHIVE_BASE_SCALAWAGS_PACK_0_VERSION='1.0-gog29222'
ARCHIVE_BASE_SCALAWAGS_PACK_0_URL='https://www.gog.com/de/game/pillars_of_eternity_ii_deadfire_scalawags_pack'

ARCHIVE_BASE_BEARD_AND_HAIR_PACK_0_NAME='pillars_of_eternity_ii_deadfire_beard_and_hair_pack_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_BEARD_AND_HAIR_PACK_0_MD5='bbebde9f100d134e73f8534de38bee28'
ARCHIVE_BASE_BEARD_AND_HAIR_PACK_0_SIZE='3100'
ARCHIVE_BASE_BEARD_AND_HAIR_PACK_0_VERSION='1.0-gog29222'
ARCHIVE_BASE_BEARD_AND_HAIR_PACK_0_URL='https://www.gog.com/de/game/pillars_of_eternity_ii_deadfire_beard_and_hair_pack'

ARCHIVE_BASE_RUM_RUNNERS_PACK_0_NAME='pillars_of_eternity_ii_deadfire_rum_runner_s_pack_v5_0_0_0040_29222.sh'
ARCHIVE_BASE_RUM_RUNNERS_PACK_0_MD5='d146cb0f2cdc955f498d1be420b83083'
ARCHIVE_BASE_RUM_RUNNERS_PACK_0_SIZE='3100'
ARCHIVE_BASE_RUM_RUNNERS_PACK_0_VERSION='1.0-gog29222'
ARCHIVE_BASE_RUM_RUNNERS_PACK_0_URL='https://www.gog.com/de/game/pillars_of_eternity_ii_deadfire_rum_runners_pack'



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

PLAYIT_LIB_PATHS="
$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"

if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_path in $PLAYIT_LIB_PATHS; do
		if [ -e "${playit_lib_path}/libplayit2.sh" ]; then
			PLAYIT_LIB2="${playit_lib_path}/libplayit2.sh"
			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 the default initialization 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
