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

###
# Ocean's Heart
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260518.3

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='oceans-heart'
GAME_NAME='Ocean’s Heart'

ARCHIVE_BASE_1_NAME='setup_oceans_heart_1.0.3(5)_(71004).exe'
ARCHIVE_BASE_1_MD5='ef6b2c679720c45cc8670df57637b281'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_SIZE='245250'
ARCHIVE_BASE_1_VERSION='1.0.3.5-gog71004'

ARCHIVE_BASE_0_NAME='setup_oceans_heart_1.0.2(6)_(64bit)_(46977).exe'
ARCHIVE_BASE_0_MD5='38550d8340ea0a7ad61b41aeabd13c3d'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='250000'
ARCHIVE_BASE_0_VERSION='1.0.2.6-gog46977'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_BIN_FILES='
oceans-heart.exe'
# TODO: Drop unused libraries.
# TODO: Install libraries in a standard path.
CONTENT_GAME0_BIN_FILES='
libbrotlicommon.dll
libbrotlidec.dll
libbz2-1.dll
libfreetype-6.dll
libgcc_s_seh-1.dll
libglib-2.0-0.dll
libgraphite2.dll
libharfbuzz-0.dll
libiconv-2.dll
libintl-8.dll
libjpeg-8.dll
libmodplug-1.dll
libogg.dll
libpcre2-8-0.dll
libphysfs.dll
libpng16-16.dll
libsolarus.dll
libssp-0.dll
libstdc++-6.dll
libvorbis-0.dll
libvorbisfile-3.dll
libwebp-7.dll
libwinpthread-1.dll
lua51.dll
OpenAL32.dll
SDL2.dll
SDL2_image.dll
SDL2_ttf.dll
zlib1.dll'
# TODO: Check if the Steam libraries are required.
# TODO: Install libraries in a standard path.
CONTENT_GAME1_BIN_FILES='
luasteam.dll
steam_api64.dll'
CONTENT_GAME_DATA_FILES='
data.solarus'
CONTENT_DOC_DATA_FILES='
license.solarus.txt
license.txt'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/AppData/Roaming/OceansHeart'

APP_MAIN_EXE='oceans-heart.exe'
# Prevent errors with SDL backends unsupported on Windows.
APP_MAIN_PRERUN='
# Prevent errors with SDL backends unsupported on Windows.
case "${SDL_VIDEODRIVER:-}" in
	("wayland"|"x11")
		unset SDL_VIDEODRIVER
	;;
esac
'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

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
# shellcheck source=libplayit.sh.2
. "$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
launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
