#!/bin/sh
# SPDX-License-Identifier: BSD-2-Clause
# SPDX-FileCopyrightText: © 2023 Christian Stalp
set -o errexit

###
# Pathfinder Kingmaker
###


script_version=20240606.1

PLAYIT_COMPATIBILITY_LEVEL='2.30'

APP_MAIN_TYPE='native'

GAME_ID='pathfinder-kingmaker' 
GAME_NAME='Pathfinder Kingmaker' 

ARCHIVE_BASE_0_NAME='pathfinder_kingmaker_2_1_5d_41987.sh'
ARCHIVE_BASE_0_MD5='e17d6ff3c5f06c326ddd047c181eab27'
#ARCHIVE_BASE_0_EXTRACTOR='unzip'
ARCHIVE_BASE_0_SIZE='25000000'
ARCHIVE_BASE_0_VERSION='2.2.5d-gog41987'
ARCHIVE_BASE_0_URL='https://www.gog.com/de/game/pathfinder_kingmaker_explorer_edition'

#UNITY3D_NAME='PathfinderKingsmaker'
UNITY3D_NAME='Kingmaker'
UNITY3D_PLUGINS='
ScreenSelector.so'

CONTENT_PATH_DEFAULT='data/noarch/game'

#CONTENT_GAME_BIN_FILES="
#${UNITY3D_NAME}
##${UNITY3D_NAME}.x86_64
#${UNITY3D_NAME}_Data/Mono/x86_64
#${UNITY3D_NAME}_Data/Plugins/x86_64"

#CONTENT_GAME_STREAMTILE_FILES="
#${UNITY3D_NAME}_Data/assetbundles/streamtile"

#CONTENT_GAME_ASSETBUNDLES_FILES="
#${UNITY3D_NAME}_Data/assetbundles"

CONTENT_GAME0_BIN_FILES='Kingmaker.exe'

CONTENT_GAME_STREAMING_ASSETS_AUDIO_FILES="
${UNITY3D_NAME}_Data/StreamingAssets/Audio"

CONTENT_GAME_STREAMING_ASSETS_BUNDLES_RESOURCE_FILES="
${UNITY3D_NAME}_Data/StreamingAssets/Bundles/r*"

CONTENT_GAME_STREAMING_ASSETS_BUNDLES_COMPANION_FILES="
${UNITY3D_NAME}_Data/StreamingAssets/Bundles/c*"

CONTENT_GAME_STREAMING_ASSETS_BUNDLES_SHADERS_FILES="
${UNITY3D_NAME}_Data/StreamingAssets/Bundles/s*"

CONTENT_GAME_STREAMING_ASSETS_BUNDLES_FILES="
${UNITY3D_NAME}_Data/StreamingAssets/Bundles"

CONTENT_GAME_STREAMING_ASSETS_LOCALIZATION_FILES="
${UNITY3D_NAME}_Data/StreamingAssets/Localization"

CONTENT_GAME_SHARED_ASSETS_FILES="
${UNITY3D_NAME}_Data/sharedassets*"

CONTENT_GAME_DATA_FILES="
${UNITY3D_NAME}_Data"

#APP_MAIN_EXE="Kingmaker.exe"

#PACKAGES_LIST='PKG_BIN PKG_STREAMTILE PKG_ASSETBUNDLES PKG_STREAMING_ASSETS PKG_DATA'
PACKAGES_LIST='PKG_BIN PKG_STREAMING_ASSETS_AUDIO  PKG_STREAMING_ASSETS_BUNDLES_SHADERS PKG_STREAMING_ASSETS_BUNDLES_RESOURCE  PKG_STREAMING_ASSETS_BUNDLES_COMPANION PKG_STREAMING_ASSETS_BUNDLES PKG_STREAMING_ASSETS_LOCALIZATION PKG_SHARED_ASSETS PKG_DATA'

PKG_DATA_DEPENDENCIES_SIBLINGS='
PKG_STREAMING_ASSETS_AUDIO
PKG_STREAMING_ASSETS_BUNDLES_SHADERS 
PKG_STREAMING_ASSETS_BUNDLES_RESOURCE  
PKG_STREAMING_ASSETS_BUNDLES_COMPANION 
PKG_STREAMING_ASSETS_BUNDLES 
PKG_STREAMING_ASSETS_LOCALIZATION 
PKG_SHARED_ASSETS'

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

#PKG_STREAMTILE_ID="${PKG_DATA_ID}-streamtile"
#PKG_STREAMTILE_DESCRIPTION='some data files'
#
#PKG_ASSETBUNDLES_ID="${PKG_DATA_ID}-assetbundles"
#PKG_ASSETBUNDLES_DESCRIPTION='some more data file'

PKG_SHARED_ASSETS_ID="${PKG_DATA_ID}-shared-assets"
PKG_SHARED_ASSETS_DESCRIPTION='very important data'

PKG_STREAMING_ASSETS_AUDIO_ID="${PKG_DATA_ID}-streaming-assets-audio"
PKG_STREAMING_ASSETS_AUDIO_DESCRIPTION='even more data files'

PKG_STREAMING_ASSETS_BUNDLES_RESOURCE_ID="${PKG_DATA_ID}-streaming-assets-bundles-resource"
PKG_STREAMING_ASSETS_BUNDLES_RESOURCE_DESCRIPTION='yet more important files'

PKG_STREAMING_ASSETS_BUNDLES_COMPANION_ID="${PKG_DATA_ID}-streaming-assets-bundles-companion"
PKG_STREAMING_ASSETS_BUNDLES_COMPANION_DESCRIPTION='yet more important files'

PKG_STREAMING_ASSETS_BUNDLES_SHADERS_ID="${PKG_DATA_ID}-streaming-assets-bundles-shaders"
PKG_STREAMING_ASSETS_BUNDLES_SHADERS_DESCRIPTION='yet more important files'

PKG_STREAMING_ASSETS_BUNDLES_ID="${PKG_DATA_ID}-streaming-assets-bundles"
PKG_STREAMING_ASSETS_BUNDLES_DESCRIPTION='yet more important files'

PKG_STREAMING_ASSETS_LOCALIZATION_ID="${PKG_DATA_ID}-streaming-assets-localization"
PKG_STREAMING_ASSETS_LOCALIZATION_DESCRIPTION='localization data files'


PKG_BIN_ARCH='64'
#PKG_BIN_DEPS="$PKG_DATA_ID"
PKG_BIN_DEPENDENCIES_SIBLINGS='PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libgcc_s.so.1
libgdk_pixbuf-2.0.so.0
libglib-2.0.so.0
libGL.so.1
libGLU.so.1
libgobject-2.0.so.0
libgtk-x11-2.0.so.0
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6
libX11.so.6
libXcursor.so.1'


# 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_icons 'PKG_DATA'
content_inclusion_default

# Write launchers

launchers_generation 'PKG_BIN'

# Build packages

packages_generation
print_instructions

# Clean up

working_directory_cleanup

exit 0
