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

###
# Tiny & Big in Grandpa's Leftovers
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260525.7

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='tiny-and-big'
GAME_NAME='Tiny & Big in Grandpa’s Leftovers'

ARCHIVE_BASE_GOG_0_NAME='tiny_and_big_grandpa_s_leftovers_en_1_4_2_15616.sh'
ARCHIVE_BASE_GOG_0_MD5='bdcc1ea8366dedcfe00b50c439fd5ec9'
ARCHIVE_BASE_GOG_0_SIZE='2400000'
ARCHIVE_BASE_GOG_0_VERSION='1.4.2-gog15616'
ARCHIVE_BASE_GOG_0_URL='https://www.gog.com/game/tiny_and_big_grandpas_leftovers'

ARCHIVE_BASE_HUMBLE_0_NAME='tinyandbig_grandpasleftovers-retail-linux-1.4.1_1370968537.tar.bz2'
ARCHIVE_BASE_HUMBLE_0_MD5='c6c2bc286f11e4a232211c5176105890'
ARCHIVE_BASE_HUMBLE_0_SIZE='2400000'
ARCHIVE_BASE_HUMBLE_0_VERSION='1.4.1-humble1370968537'
ARCHIVE_BASE_HUMBLE_0_URL='https://www.humblebundle.com/store/tiny-big-grandpas-leftovers'

ARCHIVE_OPTIONAL_ICONS_NAME='tiny-and-big_icons.tar.gz'
ARCHIVE_OPTIONAL_ICONS_MD5='043fa61c838ba6b2ef301c52660352b1'
ARCHIVE_OPTIONAL_ICONS_URL='http://downloads.dotslashplay.it/games/tiny-and-big/'
CONTENT_ICONS_PATH='.'
CONTENT_ICONS_FILES='
16x16
32x32
48x48
64x64'

CONTENT_PATH_DEFAULT_GOG='data/noarch/game'
CONTENT_PATH_DEFAULT_HUMBLE='tinyandbig'
# Shipped libcal3d.so must be used to avoid a missing symbol:
# undefined symbol: _ZNK12CalCoreModel18getCoreAnimationIdERKSs
CONTENT_LIBS_BIN_RELATIVE_PATH='bin64'
CONTENT_LIBS_BIN_FILES='
libcal3d.so'
CONTENT_GAME_BIN_FILES='
bin64/tinyandbig'
CONTENT_GAME_DATA_FILES='
assets'

USER_PERSISTENT_FILES='
options.txt
*.save'

APP_MAIN_EXE='bin64/tinyandbig'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libCgGL.so
libCg.so
libc.so.6
libdl.so.2
libgcc_s.so.1
libGL.so.1
libm.so.6
libopenal.so.1
libpthread.so.0
libstdc++.so.6
libX11.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 game data.

archive_extraction_default

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

# Use system-provided SDL.
APP_MAIN_PRERUN="$(application_prerun 'APP_MAIN')
$(launcher_tweak_sdl_override)"
dependencies_add_native_libraries 'PKG_BIN' 'libSDL2-2.0.so.0'
# Prevent a crash with SDL wayland backend.
APP_MAIN_PRERUN="$(application_prerun 'APP_MAIN')
$(launcher_tweak_sdl_force_x11)"

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
