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

###
# Skullgirls
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260105.1

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='skullgirls'
GAME_NAME='Skullgirls'

## The following DRM-free archives are no longer available for sale from Humble Bundle.
## The game is still listed on their store, but only provided as a Steam key.

ARCHIVE_BASE_1_NAME='Skullgirls-15719.tar'
ARCHIVE_BASE_1_MD5='104a6976aec70d423756e008a5b8554c'
ARCHIVE_BASE_1_SIZE='4172735'
ARCHIVE_BASE_1_VERSION='15719-humble170628'

ARCHIVE_BASE_0_NAME='Skullgirls-1.0.1.sh'
ARCHIVE_BASE_0_MD5='bf110f7d29bfd4b9e075584e41fef402'
ARCHIVE_BASE_0_SIZE='4200000'
ARCHIVE_BASE_0_VERSION='1.0.1-humble152310'

CONTENT_PATH_DEFAULT='SkullGirls'
CONTENT_PATH_DEFAULT_0='data'
CONTENT_LIBS_BIN_RELATIVE_PATH='lib/x86_64-pc-linux-gnu'
CONTENT_LIBS_BIN_RELATIVE_PATH_0='x86_64/lib/x86_64-pc-linux-gnu'
CONTENT_LIBS_BIN_FILES='
libSDL2_locale.so.0'
## libSDL2_mixer-2.0.so.0 must be included, because it provides a non-standard symbol
## (SDL_AudioStreamGet) that libSDL2_locale.so.0 relies on.
CONTENT_LIBS_BIN_FILES="$CONTENT_LIBS_BIN_FILES
libSDL2_mixer-2.0.so.0"
## libSDL2-2.0.so.0 must be included to prevent a silent crash on start-up.
CONTENT_LIBS_BIN_FILES="$CONTENT_LIBS_BIN_FILES
libSDL2-2.0.so.0"
CONTENT_GAME_BIN_RELATIVE_PATH_0='x86_64'
CONTENT_GAME_BIN_FILES='
SkullGirls.x86_64-pc-linux-gnu'
CONTENT_GAME_DATA_RELATIVE_PATH_0='noarch'
CONTENT_GAME_DATA_FILES='
data01
Salmon
Icon.png
gamecontrollerdb.txt
ProgressionInit.txt'

APP_MAIN_EXE='SkullGirls.x86_64-pc-linux-gnu'
APP_MAIN_ICON='Icon.png'
APP_MAIN_ICON_0='noarch/Icon.png'
## Trying to run the game with wayland SDL backend leads to a crash on launch:
## CRITICAL: Unable to create SDL Window
APP_MAIN_PRERUN='
# Prevent a crash on launch when wayland SDL backend is used.
if [ "${SDL_VIDEODRIVER:-}" = "wayland" ]; then
	unset SDL_VIDEODRIVER
fi
'

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
libstdc++.so.6'

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

# Load common functions.

## Scan library paths used by ./play.it ≥ 2.35.
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
## Scan library paths used by ./play.it < 2.35.
## This can go away when PLAYIT_COMPATIBILITY_LEVEL is bumped to 2.35 or higher.
if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$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'
	do
		playit_lib_path="${playit_lib_dir}/libplayit2.sh"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
## Error out if the library can not be found.
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 default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
