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

###
# Haven
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260709.1

PLAYIT_COMPATIBILITY_LEVEL=2.35

GAME_ID=haven
GAME_NAME='Haven'

ARCHIVE_BASE_2_NAME='setup_haven_v1.1.302_official_(64bit)_(54386).exe'
ARCHIVE_BASE_2_MD5=8dca64cf157ae335dab462d52253aeeb
ARCHIVE_BASE_2_TYPE=innosetup
ARCHIVE_BASE_2_PART1_NAME='setup_haven_v1.1.302_official_(64bit)_(54386)-1.bin'
ARCHIVE_BASE_2_PART1_MD5=03a08ea5c6b1a80b7a2f869da91d2df8
ARCHIVE_BASE_2_PART2_NAME='setup_haven_v1.1.302_official_(64bit)_(54386)-2.bin'
ARCHIVE_BASE_2_PART2_MD5=04e4c87ee647fd0511fdda7ff47dc787
ARCHIVE_BASE_2_SIZE=5831558
ARCHIVE_BASE_2_VERSION=1.1.302-1

ARCHIVE_BASE_1_NAME='setup_haven_v1.1.296_official_(64bit)_(53728).exe'
ARCHIVE_BASE_1_MD5=f5b9d5f71a2def217dc9e0f632a04360
ARCHIVE_BASE_1_TYPE=innosetup
ARCHIVE_BASE_1_PART1_NAME='setup_haven_v1.1.296_official_(64bit)_(53728)-1.bin'
ARCHIVE_BASE_1_PART1_MD5=598b4c5592f8f3aa4ab95c49cdf80fe0
ARCHIVE_BASE_1_PART2_NAME='setup_haven_v1.1.296_official_(64bit)_(53728)-2.bin'
ARCHIVE_BASE_1_PART2_MD5=00990daa83f70d6440bb4ccabc07981a
ARCHIVE_BASE_1_SIZE=5900000
ARCHIVE_BASE_1_VERSION=1.1.296-1

ARCHIVE_BASE_0_NAME='setup_haven_v1.1.258-rc_official_(64bit)_(49981).exe'
ARCHIVE_BASE_0_MD5=1770f0efd829dc486cc37242085518d3
ARCHIVE_BASE_0_TYPE=innosetup
ARCHIVE_BASE_0_PART1_NAME='setup_haven_v1.1.258-rc_official_(64bit)_(49981)-1.bin'
ARCHIVE_BASE_0_PART1_MD5=5aec89c6383ab1ee8f1371a9130e01f5
ARCHIVE_BASE_0_SIZE=4700000
ARCHIVE_BASE_0_VERSION=1.1.258-1

UNITY3D_NAME='Haven'
# TODO: Include an explicit list of Unity3D plugins.

CONTENT_PATH_DEFAULT='.'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/AppData/LocalLow/TheGameBakers/Haven'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH=64
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
# TODO: Move videos to a dedicated package.
PKG_BIN_DEPENDENCIES_GSTREAMER_PLUGINS='
video/quicktime, variant=(string)iso'

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
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Create some empty files.
# TODO: Are these files required?

common_directory=$(path_archive_contents)/$(unity3d_name)_Data/StreamingAssets/Audio/GeneratedSoundBanks/Windows
touch \
	"${common_directory}/Combat.txt" \
	"${common_directory}/Dialogs_Epilogue.txt" \
	"${common_directory}/Dialogs_SecretBeach.txt" \
	"${common_directory}/Dialogs_Zone0.txt" \
	"${common_directory}/Dialogs_Zone1.txt" \
	"${common_directory}/Dialogs_Zone2.txt" \
	"${common_directory}/Dialogs_Zone3.txt" \
	"${common_directory}/Dialogs_Zone4.txt" \
	"${common_directory}/Dialogs_Zone5.txt" \
	"${common_directory}/Dialogs_Zone6.txt" \
	"${common_directory}/Dialogs_ZoneK.txt" \
	"${common_directory}/Nest.txt" \
	"${common_directory}/NPC_Gorilla.txt" \
	"${common_directory}/Panel_Desert_Main.txt" \
	"${common_directory}/Panel_Main.txt" \
	"${common_directory}/WorldMap.txt"

# 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
