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

###
# Loop Hero
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260103.1

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='loop-hero'
GAME_NAME='Loop Hero'

ARCHIVE_BASE_2_NAME='loop_hero_1_1054_55873.sh'
ARCHIVE_BASE_2_MD5='28197c34cb00548770b6878f95f69b89'
ARCHIVE_BASE_2_SIZE='220000'
ARCHIVE_BASE_2_VERSION='1.1054-gog55873'
ARCHIVE_BASE_2_URL='https://www.gog.com/game/loop_hero'

ARCHIVE_BASE_1_NAME='loop_hero_1_105_50560.sh'
ARCHIVE_BASE_1_MD5='7ce0680d3dc6d945b0db0e3719addb21'
ARCHIVE_BASE_1_SIZE='160000'
ARCHIVE_BASE_1_VERSION='1.105-gog50560'

ARCHIVE_BASE_0_NAME='loop_hero_1_102_48813.sh'
ARCHIVE_BASE_0_MD5='fc860d85d59d02360d2d6aeb57cc8538'
ARCHIVE_BASE_0_SIZE='160000'
ARCHIVE_BASE_0_VERSION='1.102-gog48813'

GAME_ENGINE='gamemaker'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_BIN_FILES='
Loop_Hero'

APP_MAIN_EXE='Loop_Hero'

PKG_BIN_ARCH='64'
## The default list for GameMaker can not be used:
## + libcurl.so.4
## + libssl.so.1.1
## - libssl.so.1.0.0
PKG_BIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libcurl.so.4
libdl.so.2
libgcc_s.so.1
libGL.so.1
libGLU.so.1
libm.so.6
libopenal.so.1
libpthread.so.0
librt.so.1
libssl.so.1.1
libstdc++.so.6
libX11.so.6
libXext.so.6
libXrandr.so.2
libXxf86vm.so.1
libz.so.1'

# 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.

## Prevent inclusion of shipped libraries.
rm --recursive \
	"${PLAYIT_WORKDIR}/gamedata/$(content_path_default)/assets/linuxlibs" \
	"${PLAYIT_WORKDIR}/gamedata/$(content_path_default)/assets/drago.dll"

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
