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

###
# Rusty Lake series:
# - Rusty Lake Hotel
# - Rusty Lake Roots
# - Rusty Lake Paradise
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260420.3

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID_BASE='rusty-lake'
GAME_ID_HOTEL="${GAME_ID_BASE}-hotel"
GAME_ID_ROOTS="${GAME_ID_BASE}-roots"
GAME_ID_PARADISE="${GAME_ID_BASE}-paradise"

GAME_NAME_BASE='Rusty Lake'
GAME_NAME_HOTEL="$GAME_NAME_BASE Hotel"
GAME_NAME_ROOTS="$GAME_NAME_BASE Roots"
GAME_NAME_PARADISE="$GAME_NAME_BASE Paradise"

ARCHIVE_BASE_HOTEL_0_NAME='setup_rusty_lake_hotel_gog-1_(30681).exe'
ARCHIVE_BASE_HOTEL_0_MD5='a6121ae5cd353c8e86342e7b45cef9b4'
ARCHIVE_BASE_HOTEL_0_TYPE='innosetup'
ARCHIVE_BASE_HOTEL_0_SIZE='58000'
ARCHIVE_BASE_HOTEL_0_VERSION='1.0-gog30681'
ARCHIVE_BASE_HOTEL_0_URL='https://www.gog.com/game/rusty_lake_hotel'

ARCHIVE_BASE_ROOTS_0_NAME='setup_rusty_lake_roots_gog-1_(30681).exe'
ARCHIVE_BASE_ROOTS_0_MD5='dae526768d941d55dc80700cc4d3a678'
ARCHIVE_BASE_ROOTS_0_TYPE='innosetup'
ARCHIVE_BASE_ROOTS_0_SIZE='110000'
ARCHIVE_BASE_ROOTS_0_VERSION='1.0-gog30681'
ARCHIVE_BASE_ROOTS_0_URL='https://www.gog.com/game/rusty_lake_roots'

ARCHIVE_BASE_PARADISE_0_NAME='setup_rusty_lake_paradise_gog-1_(30704).exe'
ARCHIVE_BASE_PARADISE_0_MD5='5ff0a14bcc068232cb9948987474b503'
ARCHIVE_BASE_PARADISE_0_TYPE='innosetup'
ARCHIVE_BASE_PARADISE_0_SIZE='130000'
ARCHIVE_BASE_PARADISE_0_VERSION='1.0-gog30704'
ARCHIVE_BASE_PARADISE_0_URL='https://www.gog.com/game/rusty_lake_paradise'

# AIR_NAME is not supported by the library yet,
# the current game script is a prototype.
# (./play.it 2.35)
AIR_NAME_HOTEL='RustyLakeHotel'
AIR_NAME_ROOTS='RustyLakeRoots'
AIR_NAME_PARADISE='RustyLakeParadise'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_BIN_FILES='
Adobe AIR
META-INF
mimetype'
CONTENT_GAME0_BIN_FILES_HOTEL="
${AIR_NAME_HOTEL}.exe"
CONTENT_GAME0_BIN_FILES_ROOTS="
${AIR_NAME_ROOTS}.exe"
CONTENT_GAME0_BIN_FILES_PARADISE="
${AIR_NAME_PARADISE}.exe"
CONTENT_GAME_DATA_FILES_HOTEL="
${AIR_NAME_HOTEL}.swf"
CONTENT_GAME_DATA_FILES_ROOTS="
${AIR_NAME_ROOTS}.swf"
CONTENT_GAME_DATA_FILES_PARADISE='
Paradise.swf
paradise-translations.xml'
CONTENT_DOC_DATA_FILES='
Rusty Lake * Read Me.pdf'

APP_MAIN_EXE_HOTEL="${AIR_NAME_HOTEL}.exe"
APP_MAIN_EXE_ROOTS="${AIR_NAME_ROOTS}.exe"
APP_MAIN_EXE_PARADISE="${AIR_NAME_PARADISE}.exe"
APP_MAIN_ICON_HOTEL='icons/Icon48.png'
APP_MAIN_ICON_ROOTS='icons/icon48.png'
APP_MAIN_ICON_PARADISE='icons/Icon48 (1).png'

WINE_PERSISTENT_DIRECTORIES_HOTEL='
users/${USER}/AppData/Roaming/com.RustyLake.RustyLakeHotel'
WINE_PERSISTENT_DIRECTORIES_ROOTS='
users/${USER}/Documents/Rusty Lake/Roots'
WINE_PERSISTENT_DIRECTORIES_PARADISE='
users/${USER}/Documents/Rusty Lake/Paradise'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

PKG_DATA_ID_HOTEL="${GAME_ID_HOTEL}-data"
PKG_DATA_ID_ROOTS="${GAME_ID_ROOTS}-data"
PKG_DATA_ID_PARADISE="${GAME_ID_PARADISE}-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

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
