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

###
# World of Goo 1
# send your bug reports to vv221@dotslashplay.it
###

script_version=20251231.2

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='world-of-goo-1'
GAME_NAME='World of Goo'

ARCHIVE_BASE_GOG_1_NAME='world_of_goo_1_6_538_87464.sh'
ARCHIVE_BASE_GOG_1_MD5='92c4075f2ed640b59caca7fdebe2eafd'
ARCHIVE_BASE_GOG_1_SIZE='251204'
## Yes, 1.6 is supposed to be higher than 1.51.
## Blame game developers inability to manipulate numbers.
ARCHIVE_BASE_GOG_1_VERSION='1.6.538-gog87464'
ARCHIVE_BASE_GOG_1_URL='https://www.gog.com/game/world_of_goo'

ARCHIVE_BASE_GOG_0_NAME='world_of_goo_1_51_29337.sh'
ARCHIVE_BASE_GOG_0_MD5='f3566d859e824862b4dc14f94b15cafa'
ARCHIVE_BASE_GOG_0_SIZE='186520'
ARCHIVE_BASE_GOG_0_VERSION='1.51-gog29337'

## Formerly sold from humblebundle.com, this archive is no longer available for sale.
ARCHIVE_BASE_HUMBLE_0_NAME='WorldOfGoo.Linux.1.53.sh'
ARCHIVE_BASE_HUMBLE_0_MD5='9049f4fccf98ba79ac238a8b414e053a'
ARCHIVE_BASE_HUMBLE_0_SIZE='210000'
ARCHIVE_BASE_HUMBLE_0_VERSION='1.53-humble'

CONTENT_PATH_DEFAULT_GOG='data/noarch/game'
CONTENT_PATH_DEFAULT_HUMBLE='data'
CONTENT_GAME_BIN_RELATIVE_PATH_HUMBLE='x86_64'
CONTENT_GAME_BIN_FILES='
WorldOfGoo.bin.x86_64'
CONTENT_GAME_DATA_RELATIVE_PATH_HUMBLE='noarch'
CONTENT_GAME_DATA_FILES='
game'
## Pre 1.6 game builds only
CONTENT_DOC_DATA_RELATIVE_PATH_HUMBLE='noarch'
CONTENT_DOC_DATA_PATH_GOG='data/noarch/docs'
CONTENT_DOC_DATA_FILES='
readme.html
linux-issues.txt'

APP_MAIN_EXE='WorldOfGoo.bin.x86_64'
APP_MAIN_ICON='WorldOfGoo.png'
APP_MAIN_ICON_GOG_0='game/gooicon.png'
APP_MAIN_ICON_HUMBLE_0='game/gooicon.png'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libgcc_s.so.1
libm.so.6
libSDL2-2.0.so.0
libSDL2_mixer-2.0.so.0
libstdc++.so.6'
## Easier upgrades from pre-20240805.1 packages
PKG_BIN_PROVIDES="${PKG_BIN_PROVIDES:-}
world-of-goo"

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'
## Easier upgrades from pre-20240805.1 packages
PKG_DATA_PROVIDES="${PKG_DATA_PROVIDES:-}
world-of-goo-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
