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

###
# Children of Morta
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260713.2

PLAYIT_COMPATIBILITY_LEVEL=2.35

GAME_ID=children-of-morta
GAME_NAME='Children of Morta'

ARCHIVE_BASE_0_NAME='children_of_morta_1_2_63_48061.sh'
ARCHIVE_BASE_0_MD5=3f70026a2f2adf1eff19c25041e94a3e
ARCHIVE_BASE_0_SIZE=1309191
ARCHIVE_BASE_0_VERSION=1.2.63-1

UNITY3D_NAME='ChildrenOfMorta'
UNITY3D_PLUGINS='
libfmodL.so
libfmod.so
libfmodstudioL.so
libfmodstudio.so
libgvraudio.so
libresonanceaudio.so
ScreenSelector.so'

CONTENT_PATH_DEFAULT='data/noarch/game'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH=64
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
librt.so.1
libz.so.1'
# libfmod*.so dependencies
PKG_BIN_DEPENDENCIES_LIBRARIES="$PKG_BIN_DEPENDENCIES_LIBRARIES
libc.so.6
libdl.so.2
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6"
# libgvraudio.so dependencies
PKG_BIN_DEPENDENCIES_LIBRARIES="$PKG_BIN_DEPENDENCIES_LIBRARIES
libc.so.6
libdl.so.2
libm.so.6
libpthread.so.0"
# libresonanceaudio.so dependencies
PKG_BIN_DEPENDENCIES_LIBRARIES="$PKG_BIN_DEPENDENCIES_LIBRARIES
libc.so.6
libgcc_s.so.1
libm.so.6
libstdc++.so.6"
# ScreenSelector.so
PKG_BIN_DEPENDENCIES_LIBRARIES="$PKG_BIN_DEPENDENCIES_LIBRARIES
libatk-1.0.so.0
libcairo.so.2
libc.so.6
libdl.so.2
libfontconfig.so.1
libfreetype.so.6
libgcc_s.so.1
libgdk_pixbuf-2.0.so.0
libgdk-x11-2.0.so.0
libgio-2.0.so.0
libglib-2.0.so.0
libgobject-2.0.so.0
libgtk-x11-2.0.so.0
libm.so.6
libpango-1.0.so.0
libpangocairo-1.0.so.0
libpangoft2-1.0.so.0
libpthread.so.0
libstdc++.so.6"

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

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

# Write launchers.

# Allow loading of shipped FMod libraries.
game_exec_line() {
	cat <<- 'EOF'
	GLIBC_TUNABLES=glibc.rtld.execstack=2 ./ChildrenOfMorta -logFile ./logs/$(date +%F-%R).log "$@"
	EOF
}

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
