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

###
# GemCraft - Frostborn Wrath
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260402.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='gemcraft-frostborn-wrath'
GAME_NAME='GemCraft - Frostborn Wrath'

ARCHIVE_BASE_1_NAME='setup_gemcraft_-_frostborn_wrath_v.1.2.1a_(45694).exe'
ARCHIVE_BASE_1_MD5='8b04168cdb93ed44440fe0ed4181085d'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_SIZE='220000'
ARCHIVE_BASE_1_VERSION='1.2.1a-gog45694'
ARCHIVE_BASE_1_URL='https://www.gog.com/game/gemcraft_frostborn_wrath'

ARCHIVE_BASE_0_NAME='setup_gemcraft_-_frostborn_wrath_v.1.1.2b_(38400).exe'
ARCHIVE_BASE_0_MD5='3810dc7a58febb3120047a0a041f1b60'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='220000'
ARCHIVE_BASE_0_VERSION='1.1.2b-gog38400'

# AIR_NAME is not supported by the library yet,
# the current game script is a prototype.
# (./play.it 2.35)
AIR_NAME='GemCraft Frostborn Wrath'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_BIN_FILES="
Adobe AIR
META-INF
mimetype
${AIR_NAME}.exe"
CONTENT_GAME_DATA_FILES="
${AIR_NAME}.swf"

WINE_PERSISTENT_DIRCTORIES='
users/${USER}/AppData/Roaming/com.giab.games.gcfw
users/${USER}/Documents/GCFW-backup1'

APP_MAIN_EXE="${AIR_NAME}.exe"
APP_MAIN_ICON='icons/gcfw-icon-128x128tr.png'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
# Easier upgrades from pre-20260402.2 packages
PKG_BIN_PROVIDES='
gemcraft'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'
# Easier upgrades from pre-20260402.2 packages
PKG_DATA_PROVIDES='
gemcraft-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 '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
